mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?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\Command\Developer;
|
|
|
|
use Alchemy\Phrasea\Command\Command;
|
|
use Alchemy\Phrasea\Core\Provider\ORMServiceProvider;
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
class RegenerateSqliteDb extends Command
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct('phraseanet:regenerate-sqlite');
|
|
|
|
$this->setDescription("Updates the sqlite 'tests/db-ref.sqlite' database with current database definition.");
|
|
}
|
|
|
|
public function doExecute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$fs = new Filesystem();
|
|
|
|
$source = __DIR__ . '/../../../../../tests/db-ref.sqlite';
|
|
$target = __DIR__ . '/../../../../../tests/db-ref.sqlite.bkp';
|
|
$renamed = false;
|
|
|
|
if (is_file($source)) {
|
|
$renamed = true;
|
|
$fs->rename($source, $target);
|
|
}
|
|
|
|
try {
|
|
$dbParams = $this->container['configuration.store']->getTestConnectionParameters();
|
|
$dbParams['path'] = $source;
|
|
|
|
$this->container->register(new ORMServiceProvider());
|
|
$this->container['EM.dbal-conf'] = $dbParams;
|
|
|
|
$metadatas = $this->container['EM']->getMetadataFactory()->getAllMetadata();
|
|
$schemaTool = new SchemaTool($this->container['EM']);
|
|
$schemaTool->createSchema($metadatas);
|
|
} catch (\Exception $e) {
|
|
if ($renamed) {
|
|
$fs->rename($target, $source);
|
|
}
|
|
throw $e;
|
|
}
|
|
|
|
$fs->remove($target);
|
|
|
|
return 0;
|
|
}
|
|
}
|