diff --git a/lib/Alchemy/Phrasea/Core/Provider/ConfigurationTesterServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ConfigurationTesterServiceProvider.php new file mode 100644 index 0000000000..90ecba576e --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Provider/ConfigurationTesterServiceProvider.php @@ -0,0 +1,32 @@ +share(function(Application $app) { + return new ConfigurationTester($app); + }); + } + + public function boot(SilexApplication $app) + { + } +} diff --git a/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php b/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php index 5f3f176964..b3eb31ef3d 100644 --- a/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php +++ b/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php @@ -3,10 +3,11 @@ namespace Alchemy\Phrasea\Setup; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Setup\Version\Probe\Probe31; +use Alchemy\Phrasea\Setup\Version\Probe\Probe35; class ConfigurationTester { - private $app; private $probes; private $versionProbes; @@ -15,6 +16,11 @@ class ConfigurationTester { $this->app = $app; + $this->versionProbes = array( + new Probe31($this->app), + new Probe35($this->app), + ); + } public function registerProbe(ProbeInterface $probe) @@ -22,6 +28,11 @@ class ConfigurationTester $this->probes[] = $probe; } + /** + * Return true if got the latest configuration file. + * + * @return type + */ public function isInstalled() { return file_exists(__DIR__ . '/../../../../config/config.yml') @@ -29,8 +40,61 @@ class ConfigurationTester && 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; } }