propel-bundle/Command/MigrationMigrateCommand.php

70 lines
2.5 KiB
PHP
Raw Normal View History

2011-02-02 02:06:58 +01:00
<?php
2011-08-30 23:29:49 +02:00
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Propel\PropelBundle\Command;
2011-02-02 02:06:58 +01:00
2012-04-20 13:54:05 +02:00
use Propel\PropelBundle\Command\AbstractCommand;
2011-02-02 02:06:58 +01:00
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
2011-02-02 02:06:58 +01:00
use Symfony\Component\Console\Output\OutputInterface;
/**
* MigrationMigrateCommand.
2011-02-02 02:06:58 +01:00
*
* @author William DURAND <william.durand1@gmail.com>
2011-02-02 02:06:58 +01:00
*/
2012-04-20 13:54:05 +02:00
class MigrationMigrateCommand extends AbstractCommand
2011-02-02 02:06:58 +01:00
{
/**
* @see Command
*/
protected function configure()
{
$this
->setDescription('Executes the next migrations up')
->setDefinition(array(
new InputOption('--up', '', InputOption::VALUE_NONE, 'Executes the next migration up'),
new InputOption('--down', '', InputOption::VALUE_NONE, 'Executes the next migration down'),
))
->setHelp(<<<EOT
The <info>propel:migration:migrate</info> command checks the version of the database structure, looks for migrations files not yet executed (i.e. with a greater version timestamp), and executes them.
2011-02-02 02:06:58 +01:00
<info>php app/console propel:migration:migrate [--up] [--down]</info>
2011-02-02 02:06:58 +01:00
<info>php app/console propel:migration:migrate</info> : is the default command, it <comment>executes all</comment> migrations files.
2011-02-02 02:06:58 +01:00
<info>php app/console propel:migration:migrate --up</info> : checks the version of the database structure, looks for migrations files not yet executed (i.e. with a greater version timestamp), and <comment>executes the first one</comment> of them.
<info>php app/console propel:migration:migrate --down</info> : checks the version of the database structure, and looks for migration files already executed (i.e. with a lower version timestamp). <comment>The last executed migration found is reversed.</comment>
2011-02-02 02:06:58 +01:00
EOT
)
->setName('propel:migration:migrate')
2011-02-02 02:06:58 +01:00
;
}
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('down')) {
2011-02-02 02:06:58 +01:00
$this->callPhing('migration-down');
2012-05-24 12:44:48 +02:00
} elseif ($input->getOption('up')) {
2011-02-02 02:06:58 +01:00
$this->callPhing('migration-up');
} else {
$this->callPhing('migrate');
}
2011-04-13 22:27:07 +02:00
2011-08-30 11:52:30 +02:00
$this->writeSummary($output, 'propel-migration');
2011-02-02 02:06:58 +01:00
}
}