Add ConfigurationTesterServiceProvider, update ConfigurationTester

This commit is contained in:
Romain Neutron
2012-10-02 14:00:51 +02:00
parent 77460383f0
commit 0b1736a120
2 changed files with 98 additions and 2 deletions

View File

@@ -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)
{
}
}

View File

@@ -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;
}
}