Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| check_update | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
380 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| set_test_passed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| run | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
210 | |||
| get_step_count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_task_lang_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | |
| 14 | namespace phpbb\install\module\requirements\task; |
| 15 | |
| 16 | use phpbb\filesystem\filesystem; |
| 17 | use phpbb\install\helper\config; |
| 18 | use phpbb\install\helper\container_factory; |
| 19 | use phpbb\install\helper\iohandler\iohandler_interface; |
| 20 | use phpbb\install\helper\update_helper; |
| 21 | use phpbb\install\task_base; |
| 22 | |
| 23 | /** |
| 24 | * Check the availability of updater files and update version |
| 25 | */ |
| 26 | class check_update extends task_base |
| 27 | { |
| 28 | /** |
| 29 | * @var \phpbb\config\db |
| 30 | */ |
| 31 | protected $config; |
| 32 | |
| 33 | /** |
| 34 | * @var filesystem |
| 35 | */ |
| 36 | protected $filesystem; |
| 37 | |
| 38 | /** |
| 39 | * @var config |
| 40 | */ |
| 41 | protected $installer_config; |
| 42 | |
| 43 | /** |
| 44 | * @var iohandler_interface |
| 45 | */ |
| 46 | protected $iohandler; |
| 47 | |
| 48 | /** |
| 49 | * @var update_helper |
| 50 | */ |
| 51 | protected $update_helper; |
| 52 | |
| 53 | /** |
| 54 | * @var \phpbb\version_helper |
| 55 | */ |
| 56 | protected $version_helper; |
| 57 | |
| 58 | /** |
| 59 | * @var string |
| 60 | */ |
| 61 | protected $phpbb_root_path; |
| 62 | |
| 63 | /** |
| 64 | * @var string |
| 65 | */ |
| 66 | protected $php_ext; |
| 67 | |
| 68 | /** |
| 69 | * @var bool |
| 70 | */ |
| 71 | protected $tests_passed; |
| 72 | |
| 73 | /** |
| 74 | * Constructor |
| 75 | * |
| 76 | * @param container_factory $container |
| 77 | * @param filesystem $filesystem |
| 78 | * @param config $config |
| 79 | * @param iohandler_interface $iohandler |
| 80 | * @param update_helper $update_helper |
| 81 | * @param string $phpbb_root_path |
| 82 | * @param string $php_ext |
| 83 | */ |
| 84 | public function __construct(container_factory $container, filesystem $filesystem, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext) |
| 85 | { |
| 86 | $this->filesystem = $filesystem; |
| 87 | $this->installer_config = $config; |
| 88 | $this->iohandler = $iohandler; |
| 89 | $this->update_helper = $update_helper; |
| 90 | $this->phpbb_root_path = $phpbb_root_path; |
| 91 | $this->php_ext = $php_ext; |
| 92 | $this->tests_passed = true; |
| 93 | |
| 94 | $this->config = $container->get('config'); |
| 95 | $this->version_helper = $container->get('version_helper'); |
| 96 | |
| 97 | parent::__construct(true); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Sets $this->tests_passed |
| 102 | * |
| 103 | * @param bool $is_passed |
| 104 | */ |
| 105 | protected function set_test_passed($is_passed) |
| 106 | { |
| 107 | // If one test failed, tests_passed should be false |
| 108 | $this->tests_passed = $this->tests_passed && $is_passed; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * {@inheritdoc} |
| 113 | */ |
| 114 | public function run() |
| 115 | { |
| 116 | // Array of update files |
| 117 | $update_files = array( |
| 118 | $this->phpbb_root_path . 'install/update', |
| 119 | $this->phpbb_root_path . 'install/update/index.' . $this->php_ext, |
| 120 | ); |
| 121 | |
| 122 | // Check for a valid update directory |
| 123 | if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files)) |
| 124 | { |
| 125 | if ($this->iohandler->get_input('update_type', 'all') === 'all') |
| 126 | { |
| 127 | $this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND'); |
| 128 | $this->set_test_passed(false); |
| 129 | } |
| 130 | |
| 131 | // If there are no update files, we can't check the version etc |
| 132 | // However, we can let the users run migrations if they really want to... |
| 133 | $this->installer_config->set('disable_filesystem_update', true); |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | // Recover version numbers |
| 138 | $update_info = array(); |
| 139 | @include($this->phpbb_root_path . 'install/update/index.' . $this->php_ext); |
| 140 | /** @var array|false $info */ |
| 141 | $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; |
| 142 | $update_version = false; |
| 143 | |
| 144 | if ($info !== false) |
| 145 | { |
| 146 | $update_version = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false; |
| 147 | } |
| 148 | |
| 149 | // Get current and latest version |
| 150 | try |
| 151 | { |
| 152 | $latest_version = $this->version_helper->get_latest_on_current_branch(true); |
| 153 | } |
| 154 | catch (\RuntimeException $e) |
| 155 | { |
| 156 | $latest_version = $update_version; |
| 157 | } |
| 158 | |
| 159 | $current_version = (!empty($this->config['version_update_from'])) ? $this->config['version_update_from'] : $this->config['version']; |
| 160 | |
| 161 | // Check if the update package |
| 162 | if (!$this->update_helper->phpbb_version_compare($current_version, $update_version, '<')) |
| 163 | { |
| 164 | $this->iohandler->add_error_message('NO_UPDATE_FILES_UP_TO_DATE'); |
| 165 | $this->tests_passed = false; |
| 166 | } |
| 167 | |
| 168 | // Check if the update package works with the installed version |
| 169 | if (empty($info['version']['from']) || $info['version']['from'] !== $current_version) |
| 170 | { |
| 171 | $this->iohandler->add_error_message(array('INCOMPATIBLE_UPDATE_FILES', $current_version, $info['version']['from'], $update_version)); |
| 172 | $this->tests_passed = false; |
| 173 | } |
| 174 | |
| 175 | // check if this is the latest update package |
| 176 | if ($this->update_helper->phpbb_version_compare($update_version, $latest_version, '<')) |
| 177 | { |
| 178 | $this->iohandler->add_warning_message(array('OLD_UPDATE_FILES', $info['version']['from'], $update_version, $latest_version)); |
| 179 | } |
| 180 | |
| 181 | return $this->tests_passed; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * {@inheritdoc} |
| 186 | */ |
| 187 | public static function get_step_count() |
| 188 | { |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * {@inheritdoc} |
| 194 | */ |
| 195 | public function get_task_lang_name() |
| 196 | { |
| 197 | return ''; |
| 198 | } |
| 199 | } |