Add Doctrine schema pre-upgrades

Conflicts:
	lib/classes/appbox.php
This commit is contained in:
Andrey
2013-09-03 18:05:07 +02:00
committed by Nicolas Le Goff
parent c10c78f740
commit ada3ec96c3
5 changed files with 132 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Setup\ConfigurationTester;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Setup\Version\PreSchemaUpgrade\PreSchemaUpgradeCollection;
use Silex\Application as SilexApplication;
use Silex\ServiceProviderInterface;
@@ -24,6 +25,10 @@ class ConfigurationTesterServiceProvider implements ServiceProviderInterface
$app['phraseanet.configuration-tester'] = $app->share(function (Application $app) {
return new ConfigurationTester($app);
});
$app['phraseanet.pre-schema-upgrader'] = $app->share(function () {
return new PreSchemaUpgradeCollection();
});
}
public function boot(SilexApplication $app)

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Setup\Version\PreSchemaUpgrade;
use Alchemy\Phrasea\Application;
/**
* Collection of Doctrine schema pre-upgrades
*/
class PreSchemaUpgradeCollection
{
/** @var PreSchemaUpgradeInterface[] */
private $upgrades = array();
public function __construct()
{
$this->upgrades[] = new Upgrade39();
}
/**
* Applies all applyable upgrades
*
* @param Application $app
*/
public function apply(Application $app)
{
foreach ($this->upgrades as $upgrade) {
if ($upgrade->isApplyable($app)) {
$upgrade->apply($app['EM']);
}
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Setup\Version\PreSchemaUpgrade;
use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Application;
/**
* Interface for DB schema upgrade that have to be done before Doctrine schema
* upgrade
*/
interface PreSchemaUpgradeInterface
{
/**
* Applies the pre-upgrade/
*
* @param EntityManager $em
*/
public function apply(EntityManager $em);
/**
* Returns true if the Upgrade is applyable
*
* @param Application $app
*
* @return Boolean
*/
public function isApplyable(Application $app);
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Setup\Version\PreSchemaUpgrade;
use Alchemy\Phrasea\Application;
use Doctrine\ORM\EntityManager;
class Upgrade39 implements PreSchemaUpgradeInterface
{
/**
* {@inheritdoc}
*/
public function apply(EntityManager $em)
{
$em->getConnection()->executeQuery('RENAME TABLE `feeds` TO `feeds_backup`');
}
/**
* {@inheritdoc}
*/
public function isApplyable(Application $app)
{
$rs = $app['EM']->getConnection()->fetchAll('SHOW TABLE STATUS');
$found = false;
foreach ($rs as $row) {
if ('feeds' === $row['Name']) {
$found = true;
break;
}
}
return $found;
}
}

View File

@@ -295,6 +295,8 @@ class appbox extends base
$upgrader->set_current_message($this->app->trans('Creating new tables'));
$app['phraseanet.pre-schema-upgrader']->apply($app);
$upgrader->add_steps_complete(1);
/**