[ticket/14162] Add CLI command db:list

This command lists all installed and uninstalled migrations.

Note: The class is named `list_command`, because `list` is a reserved word
and can't be used as class name in PHP.

PHPBB3-14162
This commit is contained in:
Zoddo 2015-09-13 17:15:35 +02:00
parent 2596fba487
commit 60099cf97c
3 changed files with 89 additions and 0 deletions

View file

@ -75,6 +75,17 @@ services:
tags: tags:
- { name: console.command } - { name: console.command }
console.command.db.list:
class: phpbb\console\command\db\list_command
arguments:
- @user
- @migrator
- @ext.manager
- @config
- @cache
tags:
- { name: console.command }
console.command.db.migrate: console.command.db.migrate:
class: phpbb\console\command\db\migrate class: phpbb\console\command\db\migrate
arguments: arguments:

View file

@ -50,6 +50,7 @@ $lang = array_merge($lang, array(
'CLI_DESCRIPTION_CRON_LIST' => 'Prints a list of ready and unready cron jobs.', 'CLI_DESCRIPTION_CRON_LIST' => 'Prints a list of ready and unready cron jobs.',
'CLI_DESCRIPTION_CRON_RUN' => 'Runs all ready cron tasks.', 'CLI_DESCRIPTION_CRON_RUN' => 'Runs all ready cron tasks.',
'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run', 'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run',
'CLI_DESCRIPTION_DB_LIST' => 'List all installed and available migrations.',
'CLI_DESCRIPTION_DB_MIGRATE' => 'Updates the database by applying migrations.', 'CLI_DESCRIPTION_DB_MIGRATE' => 'Updates the database by applying migrations.',
'CLI_DESCRIPTION_DB_REVERT' => 'Revert a migration.', 'CLI_DESCRIPTION_DB_REVERT' => 'Revert a migration.',
'CLI_DESCRIPTION_DELETE_CONFIG' => 'Deletes a configuration option', 'CLI_DESCRIPTION_DELETE_CONFIG' => 'Deletes a configuration option',
@ -96,6 +97,10 @@ $lang = array_merge($lang, array(
'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.', 'CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS' => 'Successfully recalculated all email hashes.',
'CLI_MIGRATION_NAME' => 'Migration name, including the namespace (use forward slashes instead of backslashes to avoid problems).', 'CLI_MIGRATION_NAME' => 'Migration name, including the namespace (use forward slashes instead of backslashes to avoid problems).',
'CLI_MIGRATIONS_AVAILABLE' => 'Available migrations',
'CLI_MIGRATIONS_INSTALLED' => 'Installed migrations',
'CLI_MIGRATIONS_ONLY_AVAILABLE' => 'Show only available migrations',
'CLI_MIGRATIONS_EMPTY' => 'No migrations.',
'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)', 'CLI_REPARSER_REPARSE_REPARSING' => 'Reparsing %1$s (range %2$d..%3$d)',
'CLI_REPARSER_REPARSE_REPARSING_START' => 'Reparsing %s...', 'CLI_REPARSER_REPARSE_REPARSING_START' => 'Reparsing %s...',

View file

@ -0,0 +1,73 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\console\command\db;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class list_command extends \phpbb\console\command\db\migration_command
{
protected function configure()
{
$this
->setName('db:list')
->setDescription($this->user->lang('CLI_DESCRIPTION_DB_LIST'))
->addOption(
'available',
'u',
InputOption::VALUE_NONE,
$this->user->lang('CLI_MIGRATIONS_ONLY_AVAILABLE')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$show_installed = !$input->getOption('available');
$installed = $available = array();
foreach ($this->load_migrations() as $name)
{
if ($this->migrator->migration_state($name) !== false)
{
$installed[] = $name;
}
else
{
$available[] = $name;
}
}
if ($show_installed)
{
$output->writeln('<info>' . $this->user->lang('CLI_MIGRATIONS_INSTALLED') . $this->user->lang('COLON') . '</info>');
$output->writeln($installed);
if (empty($installed))
{
$output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY'));
}
$output->writeln('');
}
$output->writeln('<info>' . $this->user->lang('CLI_MIGRATIONS_AVAILABLE') . $this->user->lang('COLON') . '</info>');
$output->writeln($available);
if (empty($available))
{
$output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY'));
}
}
}