mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 06:23:18 +00:00
Add ConfigurationTesterServiceProvider, update ConfigurationTester
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Setup\ConfigurationTester;
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Silex\Application as SilexApplication;
|
||||||
|
use Silex\ServiceProviderInterface;
|
||||||
|
|
||||||
|
class ConfigurationTesterServiceProvider implements ServiceProviderInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function register(SilexApplication $app)
|
||||||
|
{
|
||||||
|
$app['phraseanet.configuration-tester'] = $app->share(function(Application $app) {
|
||||||
|
return new ConfigurationTester($app);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(SilexApplication $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -3,10 +3,11 @@
|
|||||||
namespace Alchemy\Phrasea\Setup;
|
namespace Alchemy\Phrasea\Setup;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Setup\Version\Probe\Probe31;
|
||||||
|
use Alchemy\Phrasea\Setup\Version\Probe\Probe35;
|
||||||
|
|
||||||
class ConfigurationTester
|
class ConfigurationTester
|
||||||
{
|
{
|
||||||
|
|
||||||
private $app;
|
private $app;
|
||||||
private $probes;
|
private $probes;
|
||||||
private $versionProbes;
|
private $versionProbes;
|
||||||
@@ -15,6 +16,11 @@ class ConfigurationTester
|
|||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
|
||||||
|
$this->versionProbes = array(
|
||||||
|
new Probe31($this->app),
|
||||||
|
new Probe35($this->app),
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerProbe(ProbeInterface $probe)
|
public function registerProbe(ProbeInterface $probe)
|
||||||
@@ -22,6 +28,11 @@ class ConfigurationTester
|
|||||||
$this->probes[] = $probe;
|
$this->probes[] = $probe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if got the latest configuration file.
|
||||||
|
*
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
public function isInstalled()
|
public function isInstalled()
|
||||||
{
|
{
|
||||||
return file_exists(__DIR__ . '/../../../../config/config.yml')
|
return file_exists(__DIR__ . '/../../../../config/config.yml')
|
||||||
@@ -29,8 +40,61 @@ class ConfigurationTester
|
|||||||
&& file_exists(__DIR__ . '/../../../../config/services.yml');
|
&& file_exists(__DIR__ . '/../../../../config/services.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function probeIsMigrable()
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function isUpToDate()
|
||||||
{
|
{
|
||||||
|
return $this->isInstalled() && !$this->isUpgradable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function isBlank()
|
||||||
|
{
|
||||||
|
return !$this->isMigrable() && !$this->isUpgradable() && !$this->isInstalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isUpgradable()
|
||||||
|
{
|
||||||
|
$upgradable = version_compare($this->app['phraseanet.appbox']->get_version(), $this->app['phraseanet.version'], "<");
|
||||||
|
|
||||||
|
if (!$upgradable) {
|
||||||
|
foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||||
|
if (version_compare($databox->get_version(), $this->app['phraseanet.version'], "<")) {
|
||||||
|
$upgradable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $upgradable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function isMigrable()
|
||||||
|
{
|
||||||
|
return (Boolean) $this->getMigrations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMigrations()
|
||||||
|
{
|
||||||
|
$migrations = array();
|
||||||
|
|
||||||
|
foreach($this->versionProbes as $probe) {
|
||||||
|
if($probe->isMigrable()) {
|
||||||
|
$migrations[] = $probe->getMigration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $migrations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user