Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
revert | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
configure | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 |
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 | */ |
13 | namespace phpbb\console\command\db; |
14 | |
15 | use Symfony\Component\Console\Command\Command as symfony_command; |
16 | use phpbb\db\output_handler\log_wrapper_migrator_output_handler; |
17 | use Symfony\Component\Console\Input\InputArgument; |
18 | use Symfony\Component\Console\Input\InputInterface; |
19 | use Symfony\Component\Console\Output\OutputInterface; |
20 | use Symfony\Component\Console\Style\SymfonyStyle; |
21 | |
22 | class revert extends \phpbb\console\command\db\migrate |
23 | { |
24 | /** |
25 | * {@inheritdoc} |
26 | */ |
27 | protected function configure() |
28 | { |
29 | $this |
30 | ->setName('db:revert') |
31 | ->setDescription($this->language->lang('CLI_DESCRIPTION_DB_REVERT')) |
32 | ->addArgument( |
33 | 'name', |
34 | InputArgument::REQUIRED, |
35 | $this->language->lang('CLI_MIGRATION_NAME') |
36 | ) |
37 | ; |
38 | } |
39 | |
40 | /** |
41 | * Executes the command db:revert. |
42 | * |
43 | * Reverts a migration |
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 | $name = str_replace('/', '\\', $input->getArgument('name')); |
55 | |
56 | $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); |
57 | |
58 | $this->cache->purge(); |
59 | |
60 | if (!in_array($name, $this->load_migrations())) |
61 | { |
62 | $io->error($this->language->lang('MIGRATION_NOT_VALID', $name)); |
63 | return symfony_command::FAILURE; |
64 | } |
65 | else if ($this->migrator->migration_state($name) === false) |
66 | { |
67 | $io->error($this->language->lang('MIGRATION_NOT_INSTALLED', $name)); |
68 | return symfony_command::FAILURE; |
69 | } |
70 | |
71 | try |
72 | { |
73 | while ($this->migrator->migration_state($name) !== false) |
74 | { |
75 | $this->migrator->revert($name); |
76 | } |
77 | } |
78 | catch (\phpbb\db\migration\exception $e) |
79 | { |
80 | $io->error($e->getLocalisedMessage($this->user)); |
81 | $this->finalise_update(); |
82 | return symfony_command::FAILURE; |
83 | } |
84 | |
85 | $this->finalise_update(); |
86 | $io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL')); |
87 | return symfony_command::SUCCESS; |
88 | } |
89 | } |