mirror of
https://github.com/jbcr/ezmigrationbundle.git
synced 2026-03-25 09:22:18 +01:00
135 lines
5.3 KiB
PHP
135 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Kaliop\eZMigrationBundle\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Kaliop\eZMigrationBundle\API\Value\Migration;
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
|
|
|
|
/**
|
|
* Command to display the status of migrations.
|
|
*
|
|
* @todo add option to skip displaying already executed migrations
|
|
*/
|
|
class StatusCommand extends AbstractCommand
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('kaliop:migration:status')
|
|
->setDescription('List available migrations and their status.')
|
|
->addOption(
|
|
'path',
|
|
null,
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
|
"The directory or file to load the migration definitions from"
|
|
)
|
|
->setHelp(
|
|
<<<EOT
|
|
The <info>kaliop:migration:status</info> command displays the status of all available migrations:
|
|
|
|
<info>./ezpublish/console kaliop:migration:status</info>
|
|
|
|
You can optionally specify the path to migration versions with <info>--path</info>:
|
|
|
|
<info>./ezpublish/console kaliop:migrations:status --path=/path/to/bundle/version_directory --path=/path/to/bundle/version_directory/single_migration_file</info>
|
|
EOT
|
|
);
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$migrationsService = $this->getMigrationService();
|
|
|
|
$migrationDefinitions = $migrationsService->getMigrationsDefinitions($input->getOption('path')) ;
|
|
$migrations = $migrationsService->getMigrations();
|
|
|
|
if (!count($migrationDefinitions) && !count($migrations)) {
|
|
$output->writeln('<info>No migrations found</info>');
|
|
return;
|
|
}
|
|
|
|
// create a unique ist of all migrations and definitions
|
|
$index = array();
|
|
foreach($migrationDefinitions as $migrationDefinition) {
|
|
$index[$migrationDefinition->name] = array('definition' => $migrationDefinition);
|
|
}
|
|
foreach($migrations as $migration) {
|
|
if (isset($index[$migration->name])) {
|
|
$index[$migration->name]['migration'] = $migration;
|
|
} else {
|
|
$index[$migration->name] = array('migration' => $migration);
|
|
}
|
|
}
|
|
ksort($index);
|
|
|
|
$output->writeln("\n <info>==</info> Available Migrations\n");
|
|
|
|
$data = array();
|
|
$i = 1;
|
|
foreach($index as $name => $value) {
|
|
if (!isset($value['migration'])) {
|
|
$migrationDefinition = $migrationsService->parseMigrationDefinition($value['definition']);
|
|
$notes = '';
|
|
if ($migrationDefinition->status != MigrationDefinition::STATUS_PARSED) {
|
|
$notes = '<error>' . $migrationDefinition->parsingError . '</error>';
|
|
}
|
|
$data[] = array(
|
|
$i++,
|
|
$name,
|
|
'<error>not executed</error>',
|
|
'',
|
|
$notes
|
|
);
|
|
} else {
|
|
$migration = $value['migration'];
|
|
switch ($migration->status) {
|
|
case Migration::STATUS_DONE:
|
|
$status = '<info>executed</info>';
|
|
break;
|
|
case Migration::STATUS_STARTED:
|
|
$status = '<warning>execution started</warning>';
|
|
break;
|
|
case Migration::STATUS_TODO:
|
|
$status = '<error>not executed</error>';
|
|
break;
|
|
case Migration::STATUS_SKIPPED:
|
|
$status = '<warning>skipped</warning>';
|
|
break;
|
|
case Migration::STATUS_PARTIALLY_DONE:
|
|
$status = '<warning>partially executed</warning>';
|
|
break;
|
|
}
|
|
$notes = array();
|
|
if (!isset($value['definition'])) {
|
|
$notes[] = '<warning>The migration definition file can not be found any more</warning>';
|
|
} else {
|
|
$migrationDefinition = $value['definition'];
|
|
if (md5($migrationDefinition->rawDefinition) != $migration->md5) {
|
|
$notes[] = '<warning>The migration definition file has now a different checksum</warning>';
|
|
}
|
|
if ($migrationDefinition->path != $migrationDefinition->path) {
|
|
$notes[] = '<warning>The migration definition file has now moved</warning>';
|
|
}
|
|
}
|
|
$notes = implode(' ', $notes);
|
|
$data[] = array(
|
|
$i++,
|
|
$migration->name,
|
|
$status,
|
|
($migration->executionDate != null ? date("Y-m-d H:i:s", $migration->executionDate) : ''),
|
|
$notes
|
|
);
|
|
}
|
|
}
|
|
|
|
$table = new Table($output);
|
|
$table
|
|
->setHeaders(array('#', 'Migration', 'Status', 'Executed on', 'Notes'))
|
|
->setRows($data);
|
|
$table->render();
|
|
}
|
|
}
|