Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
list_command
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 configure
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13namespace phpbb\console\command\db;
14
15use Symfony\Component\Console\Command\Command as symfony_command;
16use Symfony\Component\Console\Input\InputInterface;
17use Symfony\Component\Console\Input\InputOption;
18use Symfony\Component\Console\Output\OutputInterface;
19use Symfony\Component\Console\Style\SymfonyStyle;
20
21class list_command extends \phpbb\console\command\db\migration_command
22{
23    /**
24     * {@inheritdoc}
25     */
26    protected function configure()
27    {
28        $this
29            ->setName('db:list')
30            ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_LIST'))
31            ->addOption(
32                'available',
33                'u',
34                InputOption::VALUE_NONE,
35                $this->user->lang('CLI_MIGRATIONS_ONLY_AVAILABLE')
36            )
37        ;
38    }
39
40    /**
41     * Executes the command db:list.
42     *
43     * Lists all installed and available migrations
44     *
45     * @param InputInterface  $input  An InputInterface instance
46     * @param OutputInterface $output An OutputInterface instance
47     *
48     * @return int
49     */
50    protected function execute(InputInterface $input, OutputInterface $output)
51    {
52        $io = new SymfonyStyle($input, $output);
53
54        $show_installed = !$input->getOption('available');
55        $installed = $available = array();
56
57        foreach ($this->load_migrations() as $name)
58        {
59            if ($this->migrator->migration_state($name) !== false)
60            {
61                $installed[] = $name;
62            }
63            else
64            {
65                $available[] = $name;
66            }
67        }
68
69        if ($show_installed)
70        {
71            $io->section($this->user->lang('CLI_MIGRATIONS_INSTALLED'));
72
73            if (!empty($installed))
74            {
75                $io->listing($installed);
76            }
77            else
78            {
79                $io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
80                $io->newLine();
81            }
82        }
83
84        $io->section($this->user->lang('CLI_MIGRATIONS_AVAILABLE'));
85        if (!empty($available))
86        {
87            $io->listing($available);
88        }
89        else
90        {
91            $io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
92            $io->newLine();
93        }
94
95        return symfony_command::SUCCESS;
96    }
97}