Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
migrate | |
0.00% |
0 / 29 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
configure | |
0.00% |
0 / 4 |
|
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\InputInterface; |
18 | use Symfony\Component\Console\Output\OutputInterface; |
19 | use Symfony\Component\Console\Style\SymfonyStyle; |
20 | |
21 | class migrate extends \phpbb\console\command\db\migration_command |
22 | { |
23 | /** @var \phpbb\log\log */ |
24 | protected $log; |
25 | |
26 | /** @var string phpBB root path */ |
27 | protected $phpbb_root_path; |
28 | |
29 | /** @var \phpbb\filesystem\filesystem_interface */ |
30 | protected $filesystem; |
31 | |
32 | /** @var \phpbb\language\language */ |
33 | protected $language; |
34 | |
35 | public function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) |
36 | { |
37 | $this->language = $language; |
38 | $this->log = $log; |
39 | $this->filesystem = $filesystem; |
40 | $this->phpbb_root_path = $phpbb_root_path; |
41 | parent::__construct($user, $migrator, $extension_manager, $config, $cache); |
42 | $this->language->add_lang(array('common', 'install', 'migrator')); |
43 | } |
44 | |
45 | /** |
46 | * {@inheritdoc} |
47 | */ |
48 | protected function configure() |
49 | { |
50 | $this |
51 | ->setName('db:migrate') |
52 | ->setDescription($this->language->lang('CLI_DESCRIPTION_DB_MIGRATE')) |
53 | ; |
54 | } |
55 | |
56 | /** |
57 | * Executes the command db:migrate. |
58 | * |
59 | * Updates the database by applying migrations |
60 | * |
61 | * @param InputInterface $input An InputInterface instance |
62 | * @param OutputInterface $output An OutputInterface instance |
63 | * |
64 | * @return int |
65 | */ |
66 | protected function execute(InputInterface $input, OutputInterface $output) |
67 | { |
68 | $io = new SymfonyStyle($input, $output); |
69 | |
70 | $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)); |
71 | |
72 | $this->migrator->create_migrations_table(); |
73 | |
74 | $this->cache->purge(); |
75 | if ($this->config instanceof \phpbb\config\db) |
76 | { |
77 | $this->config->initialise($this->cache->get_driver()); |
78 | } |
79 | |
80 | $this->load_migrations(); |
81 | $orig_version = $this->config['version']; |
82 | while (!$this->migrator->finished()) |
83 | { |
84 | try |
85 | { |
86 | $this->migrator->update(); |
87 | } |
88 | catch (\phpbb\db\migration\exception $e) |
89 | { |
90 | $io->error($e->getLocalisedMessage($this->user)); |
91 | $this->finalise_update(); |
92 | return symfony_command::FAILURE; |
93 | } |
94 | } |
95 | |
96 | if ($orig_version != $this->config['version']) |
97 | { |
98 | $this->log->add('admin', ANONYMOUS, '', 'LOG_UPDATE_DATABASE', time(), array($orig_version, $this->config['version'])); |
99 | } |
100 | |
101 | $this->finalise_update(); |
102 | $io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL')); |
103 | return symfony_command::SUCCESS; |
104 | } |
105 | } |