diff options
Diffstat (limited to 'phpBB/phpbb/install/module')
21 files changed, 2089 insertions, 20 deletions
diff --git a/phpBB/phpbb/install/module/obtain_data/module.php b/phpBB/phpbb/install/module/obtain_data/install_module.php index 0e008796c5..deb4be90d8 100644 --- a/phpBB/phpbb/install/module/obtain_data/module.php +++ b/phpBB/phpbb/install/module/obtain_data/install_module.php @@ -13,7 +13,7 @@ namespace phpbb\install\module\obtain_data; -class module extends \phpbb\install\module_base +class install_module extends \phpbb\install\module_base { /** * {@inheritdoc} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php index b2250e524b..41616e995a 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php @@ -155,7 +155,7 @@ class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\insta $data_valid = true; // Check if none of admin data is empty - if (in_array('', array($username, $pass1, $pass2, $email))) + if (in_array('', array($username, $pass1, $pass2, $email), true)) { $this->io_handler->add_error_message('INST_ERR_MISSING_DATA'); $data_valid = false; diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php index 821c221123..0726cc449c 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php @@ -165,7 +165,7 @@ class obtain_board_data extends \phpbb\install\task_base implements \phpbb\insta $this->io_handler->add_user_form_group('BOARD_CONFIG', $board_form); $this->io_handler->send_response(); - throw new user_interaction_required_exception; + throw new user_interaction_required_exception(); } /** diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php new file mode 100644 index 0000000000..9bcb73a6a9 --- /dev/null +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php @@ -0,0 +1,168 @@ +<?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\install\module\obtain_data\task; + +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\task_base; + +class obtain_file_updater_method extends task_base +{ + /** + * @var array Supported compression methods + * + * Note: .tar is assumed to be supported, but not in the list + */ + protected $available_methods; + + /** + * @var \phpbb\install\helper\config + */ + protected $installer_config; + + /** + * @var \phpbb\install\helper\iohandler\iohandler_interface + */ + protected $iohandler; + + /** + * Constructor + * + * @param config $installer_config + * @param iohandler_interface $iohandler + */ + public function __construct(config $installer_config, iohandler_interface $iohandler) + { + $this->installer_config = $installer_config; + $this->iohandler = $iohandler; + + $this->available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false); + } + + /** + * {@inheritdoc} + */ + public function run() + { + // Check if data is sent + if ($this->iohandler->get_input('submit_update_file', false)) + { + $supported_methods = array('compression', 'ftp', 'direct_file'); + $method = $this->iohandler->get_input('method', 'compression'); + $update_method = (in_array($method, $supported_methods, true)) ? $method : 'compression'; + $this->installer_config->set('file_update_method', $update_method); + + $compression = $this->iohandler->get_input('compression_method', '.zip'); + $supported_methods = array_keys($this->available_methods); + $supported_methods[] = '.tar'; + $compression = (in_array($compression, $supported_methods, true)) ? $compression : '.zip'; + $this->installer_config->set('file_update_compression', $compression); + } + else + { + $this->iohandler->add_user_form_group('UPDATE_FILE_METHOD_TITLE', array( + 'method' => array( + 'label' => 'UPDATE_FILE_METHOD', + 'type' => 'select', + 'options' => array( + array( + 'value' => 'compression', + 'label' => 'UPDATE_FILE_METHOD_DOWNLOAD', + 'selected' => true, + ), + array( + 'value' => 'ftp', + 'label' => 'UPDATE_FILE_METHOD_FTP', + 'selected' => false, + ), + array( + 'value' => 'direct_file', + 'label' => 'UPDATE_FILE_METHOD_FILESYSTEM', + 'selected' => false, + ), + ), + ), + 'compression_method' => array( + 'label' => 'SELECT_DOWNLOAD_FORMAT', + 'type' => 'select', + 'options' => $this->get_available_compression_methods(), + ), + 'submit_update_file' => array( + 'label' => 'SUBMIT', + 'type' => 'submit', + ), + )); + + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + } + + /** + * Returns form elements in an array of available compression methods + * + * @return array + */ + protected function get_available_compression_methods() + { + $methods[] = array( + 'value' => '.tar', + 'label' => '.tar', + 'selected' => true, + ); + + foreach ($this->available_methods as $type => $module) + { + if (!@extension_loaded($module)) + { + continue; + } + + $methods[] = array( + 'value' => $type, + 'label' => $type, + 'selected' => false, + ); + } + + return $methods; + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php new file mode 100644 index 0000000000..0cb809154e --- /dev/null +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php @@ -0,0 +1,113 @@ +<?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\install\module\obtain_data\task; + +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\task_base; + +class obtain_update_files extends task_base +{ + /** + * @var config + */ + protected $installer_config; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param config $config + * @param iohandler_interface $iohandler + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(config $config, iohandler_interface $iohandler, $phpbb_root_path, $php_ext) + { + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false); + } + + /** + * {@inheritdoc} + */ + public function run() + { + // Load update info file + // The file should be checked in the requirements, so we assume that it exists + $update_info_file = $this->phpbb_root_path . 'install/update/index.' . $this->php_ext; + include($update_info_file); + $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; + + // If the file is invalid, abort mission + if (!$info) + { + $this->iohandler->add_error_message('WRONG_INFO_FILE_FORMAT'); + throw new user_interaction_required_exception(); + } + + // Replace .php with $this->php_ext if needed + if ($this->php_ext !== 'php') + { + $custom_extension = '.' . $this->php_ext; + $info['files'] = preg_replace('#\.php$#i', $custom_extension, $info['files']); + } + + // Save update info + $this->installer_config->set('update_info_unprocessed', $info); + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php new file mode 100644 index 0000000000..a4d362a0f1 --- /dev/null +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php @@ -0,0 +1,164 @@ +<?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\install\module\obtain_data\task; + +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\helper\update_helper; +use phpbb\install\task_base; + +class obtain_update_ftp_data extends task_base +{ + /** + * @var \phpbb\install\helper\config + */ + protected $installer_config; + + /** + * @var \phpbb\install\helper\iohandler\iohandler_interface + */ + protected $iohandler; + + /** + * @var update_helper + */ + protected $update_helper; + + /** + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param config $installer_config + * @param iohandler_interface $iohandler + * @param update_helper $update_helper + * @param string $php_ext + */ + public function __construct(config $installer_config, iohandler_interface $iohandler, update_helper $update_helper, $php_ext) + { + $this->installer_config = $installer_config; + $this->iohandler = $iohandler; + $this->update_helper = $update_helper; + $this->php_ext = $php_ext; + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return ($this->installer_config->get('do_update_files', false) && + ($this->installer_config->get('file_update_method', '') === 'ftp') + ); + } + + /** + * {@inheritdoc} + */ + public function run() + { + if ($this->iohandler->get_input('submit_ftp', false)) + { + $this->update_helper->include_file('includes/functions_transfer.' . $this->php_ext); + + $method = 'ftp'; + $methods = \transfer::methods(); + if (!in_array($method, $methods, true)) + { + $method = $methods[0]; + } + + $ftp_host = $this->iohandler->get_input('ftp_host', ''); + $ftp_user = $this->iohandler->get_input('ftp_user', ''); + $ftp_pass = htmlspecialchars_decode($this->iohandler->get_input('ftp_pass', '')); + $ftp_path = $this->iohandler->get_input('ftp_path', ''); + $ftp_port = $this->iohandler->get_input('ftp_port', 21); + $ftp_time = $this->iohandler->get_input('ftp_timeout', 10); + + $this->installer_config->set('ftp_host', $ftp_host); + $this->installer_config->set('ftp_user', $ftp_user); + $this->installer_config->set('ftp_pass', $ftp_pass); + $this->installer_config->set('ftp_path', $ftp_path); + $this->installer_config->set('ftp_port', (int) $ftp_port); + $this->installer_config->set('ftp_timeout', (int) $ftp_time); + $this->installer_config->set('ftp_method', $method); + } + else + { + $this->iohandler->add_user_form_group('FTP_SETTINGS', array( + 'ftp_host' => array( + 'label' => 'FTP_HOST', + 'description' => 'FTP_HOST_EXPLAIN', + 'type' => 'text', + ), + 'ftp_user' => array( + 'label' => 'FTP_USERNAME', + 'description' => 'FTP_USERNAME_EXPLAIN', + 'type' => 'text', + ), + 'ftp_pass' => array( + 'label' => 'FTP_PASSWORD', + 'description' => 'FTP_PASSWORD_EXPLAIN', + 'type' => 'password', + ), + 'ftp_path' => array( + 'label' => 'FTP_ROOT_PATH', + 'description' => 'FTP_ROOT_PATH_EXPLAIN', + 'type' => 'text', + ), + 'ftp_port' => array( + 'label' => 'FTP_PORT', + 'description' => 'FTP_PORT_EXPLAIN', + 'type' => 'text', + 'default' => 21, + ), + 'ftp_timeout' => array( + 'label' => 'FTP_TIMEOUT', + 'description' => 'FTP_TIMEOUT_EXPLAIN', + 'type' => 'text', + 'default' => 10, + ), + 'submit_ftp' => array( + 'label' => 'SUBMIT', + 'type' => 'submit', + ), + )); + + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php new file mode 100644 index 0000000000..6a98721e77 --- /dev/null +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php @@ -0,0 +1,103 @@ +<?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\install\module\obtain_data\task; + +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\task_base; + +class obtain_update_settings extends task_base +{ + /** + * @var \phpbb\install\helper\config + */ + protected $installer_config; + + /** + * @var \phpbb\install\helper\iohandler\iohandler_interface + */ + protected $iohandler; + + /** + * Constructor + * + * @param config $installer_config + * @param iohandler_interface $iohandler + */ + public function __construct(config $installer_config, iohandler_interface $iohandler) + { + $this->installer_config = $installer_config; + $this->iohandler = $iohandler; + + parent::__construct(true); + } + + /** + * {@inheritdoc} + */ + public function run() + { + // Check if data is sent + if ($this->iohandler->get_input('submit_update', false)) + { + $update_files = $this->iohandler->get_input('update_type', 'all') === 'all'; + $this->installer_config->set('do_update_files', $update_files); + } + else + { + $this->iohandler->add_user_form_group('UPDATE_TYPE', array( + 'update_type' => array( + 'label' => 'UPDATE_TYPE', + 'type' => 'radio', + 'options' => array( + array( + 'value' => 'all', + 'label' => 'UPDATE_TYPE_ALL', + 'selected' => true, + ), + array( + 'value' => 'db_only', + 'label' => 'UPDATE_TYPE_DB_ONLY', + 'selected' => false, + ), + ), + ), + 'submit_update' => array( + 'label' => 'SUBMIT', + 'type' => 'submit', + ), + )); + + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/obtain_data/update_module.php b/phpBB/phpbb/install/module/obtain_data/update_module.php new file mode 100644 index 0000000000..c2f9019d34 --- /dev/null +++ b/phpBB/phpbb/install/module/obtain_data/update_module.php @@ -0,0 +1,33 @@ +<?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\install\module\obtain_data; + +class update_module extends \phpbb\install\module_base +{ + /** + * {@inheritdoc} + */ + public function get_navigation_stage_path() + { + return array('update', 0, 'obtain_data'); + } + + /** + * {@inheritdoc} + */ + public function get_step_count() + { + return 0; + } +} diff --git a/phpBB/phpbb/install/module/requirements/module.php b/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php index 79a031bad9..26593e6777 100644 --- a/phpBB/phpbb/install/module/requirements/module.php +++ b/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php @@ -15,8 +15,12 @@ namespace phpbb\install\module\requirements; use phpbb\install\exception\resource_limit_reached_exception; use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\module_base; -class module extends \phpbb\install\module_base +/** + * Base class for requirements installer module + */ +abstract class abstract_requirements_module extends module_base { public function run() { @@ -33,7 +37,7 @@ class module extends \phpbb\install\module_base foreach ($this->task_collection as $name => $task) { // Run until there are available resources - if ($this->install_config->get_time_remaining() <= 0 && $this->install_config->get_memory_remaining() <= 0) + if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) { throw new resource_limit_reached_exception(); } @@ -99,12 +103,4 @@ class module extends \phpbb\install\module_base { return 0; } - - /** - * {@inheritdoc} - */ - public function get_navigation_stage_path() - { - return array('install', 0, 'requirements'); - } } diff --git a/phpBB/phpbb/install/module/requirements/install_module.php b/phpBB/phpbb/install/module/requirements/install_module.php new file mode 100644 index 0000000000..ed0c5fbd94 --- /dev/null +++ b/phpBB/phpbb/install/module/requirements/install_module.php @@ -0,0 +1,25 @@ +<?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\install\module\requirements; + +class install_module extends abstract_requirements_module +{ + /** + * {@inheritdoc} + */ + public function get_navigation_stage_path() + { + return array('install', 0, 'requirements'); + } +} diff --git a/phpBB/phpbb/install/module/requirements/task/check_filesystem.php b/phpBB/phpbb/install/module/requirements/task/check_filesystem.php index ab6b1091e2..2aec3915e0 100644 --- a/phpBB/phpbb/install/module/requirements/task/check_filesystem.php +++ b/phpBB/phpbb/install/module/requirements/task/check_filesystem.php @@ -50,11 +50,9 @@ class check_filesystem extends \phpbb\install\task_base * @param \phpbb\install\helper\iohandler\iohandler_interface $response response helper * @param string $phpbb_root_path relative path to phpBB's root * @param string $php_ext extension of php files + * @param bool $check_config_php Whether or not to check if config.php is writable */ - public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, - \phpbb\install\helper\iohandler\iohandler_interface $response, - $phpbb_root_path, - $php_ext) + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, \phpbb\install\helper\iohandler\iohandler_interface $response, $phpbb_root_path, $php_ext, $check_config_php = true) { parent::__construct(true); @@ -87,12 +85,16 @@ class check_filesystem extends \phpbb\install\task_base 'failable' => true, 'is_file' => false, ), - array( + ); + + if ($check_config_php) + { + $this->files_to_check[] = array( 'path' => "config.$php_ext", 'failable' => false, 'is_file' => true, - ), - ); + ); + } } /** diff --git a/phpBB/phpbb/install/module/requirements/task/check_update.php b/phpBB/phpbb/install/module/requirements/task/check_update.php new file mode 100644 index 0000000000..c986c76810 --- /dev/null +++ b/phpBB/phpbb/install/module/requirements/task/check_update.php @@ -0,0 +1,185 @@ +<?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\install\module\requirements\task; + +use phpbb\filesystem\filesystem; +use phpbb\install\helper\container_factory; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\helper\update_helper; +use phpbb\install\task_base; + +/** + * Check the availability of updater files and update version + */ +class check_update extends task_base +{ + /** + * @var \phpbb\config\db + */ + protected $config; + + /** + * @var filesystem + */ + protected $filesystem; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var update_helper + */ + protected $update_helper; + + /** + * @var \phpbb\version_helper + */ + protected $version_helper; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * @var string + */ + protected $php_ext; + + /** + * @var bool + */ + protected $tests_passed; + + /** + * Constructor + * + * @param container_factory $container + * @param filesystem $filesystem + * @param iohandler_interface $iohandler + * @param update_helper $update_helper + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(container_factory $container, filesystem $filesystem, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext) + { + $this->filesystem = $filesystem; + $this->iohandler = $iohandler; + $this->update_helper = $update_helper; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->tests_passed = true; + + $this->config = $container->get('config'); + $this->version_helper = $container->get('version_helper'); + + parent::__construct(true); + } + + /** + * Sets $this->tests_passed + * + * @param bool $is_passed + */ + protected function set_test_passed($is_passed) + { + // If one test failed, tests_passed should be false + $this->tests_passed = $this->tests_passed && $is_passed; + } + + /** + * {@inheritdoc} + */ + public function run() + { + // Array of update files + $update_files = array( + $this->phpbb_root_path . 'install/update', + $this->phpbb_root_path . 'install/update/index.' . $this->php_ext, + ); + + // Check for a valid update directory + if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files)) + { + $this->iohandler->add_error_message('UPDATE_FILES_NOT_FOUND'); + $this->set_test_passed(false); + + // If there are no update files, we can't check the version + return false; + } + + // Recover version numbers + $update_info = array(); + @include($this->phpbb_root_path . 'install/update/index.' . $this->php_ext); + $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; + $update_version = false; + + if ($info !== false) + { + $update_version = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false; + } + + // Get current and latest version + try + { + $latest_version = $this->version_helper->get_latest_on_current_branch(true); + } + catch (\RuntimeException $e) + { + $latest_version = $update_version; + } + + $current_version = (!empty($this->config['version_update_from'])) ? $this->config['version_update_from'] : $this->config['version']; + + // Check if the update package + if (!$this->update_helper->phpbb_version_compare($current_version, $update_version, '<')) + { + $this->iohandler->add_error_message('NO_UPDATE_FILES_UP_TO_DATE'); + $this->tests_passed = false; + } + + // Check if the update package works with the installed version + if (empty($info['version']['from']) || $info['version']['from'] !== $current_version) + { + $this->iohandler->add_error_message(array('INCOMPATIBLE_UPDATE_FILES', $current_version, $info['version']['from'], $update_version)); + $this->tests_passed = false; + } + + // check if this is the latest update package + if ($this->update_helper->phpbb_version_compare($update_version, $latest_version, '<')) + { + $this->iohandler->add_warning_message(array('OLD_UPDATE_FILES', $info['version']['from'], $update_version, $latest_version)); + } + + return $this->tests_passed; + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/requirements/update_module.php b/phpBB/phpbb/install/module/requirements/update_module.php new file mode 100644 index 0000000000..223d12faf3 --- /dev/null +++ b/phpBB/phpbb/install/module/requirements/update_module.php @@ -0,0 +1,25 @@ +<?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\install\module\requirements; + +class update_module extends abstract_requirements_module +{ + /** + * {@inheritdoc} + */ + public function get_navigation_stage_path() + { + return array('update', 0, 'requirements'); + } +} diff --git a/phpBB/phpbb/install/module/update_database/module.php b/phpBB/phpbb/install/module/update_database/module.php new file mode 100644 index 0000000000..ee38afe17d --- /dev/null +++ b/phpBB/phpbb/install/module/update_database/module.php @@ -0,0 +1,33 @@ +<?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\install\module\update_database; + +class module extends \phpbb\install\module_base +{ + /** + * {@inheritdoc} + */ + public function get_navigation_stage_path() + { + return array('update', 0, 'update_database'); + } + + /** + * {@inheritdoc} + */ + public function get_step_count() + { + return 0; + } +} diff --git a/phpBB/phpbb/install/module/update_database/task/update.php b/phpBB/phpbb/install/module/update_database/task/update.php new file mode 100644 index 0000000000..2d640134a3 --- /dev/null +++ b/phpBB/phpbb/install/module/update_database/task/update.php @@ -0,0 +1,212 @@ +<?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\install\module\update_database\task; + +use phpbb\db\migration\exception; +use phpbb\db\output_handler\installer_migrator_output_handler; +use phpbb\db\output_handler\log_wrapper_migrator_output_handler; +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\task_base; + +/** + * Database updater task + */ +class update extends task_base +{ + /** + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + + /** + * @var \phpbb\config\config + */ + protected $config; + + /** + * @var \phpbb\extension\manager + */ + protected $extension_manager; + + /** + * @var \phpbb\filesystem\filesystem + */ + protected $filesystem; + + /** + * @var \phpbb\install\helper\config + */ + protected $installer_config; + + /** + * @var \phpbb\install\helper\iohandler\iohandler_interface + */ + protected $iohandler; + + /** + * @var \phpbb\language\language + */ + protected $language; + + /** + * @var \phpbb\log\log + */ + protected $log; + + /** + * @var \phpbb\db\migrator + */ + protected $migrator; + + /** + * @var \phpbb\user + */ + protected $user; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * Constructor + * + * @param \phpbb\install\helper\container_factory $container + * @param \phpbb\filesystem\filesystem $filesystem + * @param \phpbb\install\helper\config $installer_config + * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler + * @param \phpbb\language\language $language + * @param string $phpbb_root_path + */ + public function __construct(\phpbb\install\helper\container_factory $container, \phpbb\filesystem\filesystem $filesystem, \phpbb\install\helper\config $installer_config, \phpbb\install\helper\iohandler\iohandler_interface $iohandler, \phpbb\language\language $language, $phpbb_root_path) + { + $this->filesystem = $filesystem; + $this->installer_config = $installer_config; + $this->iohandler = $iohandler; + $this->language = $language; + $this->phpbb_root_path = $phpbb_root_path; + + $this->cache = $container->get('cache.driver'); + $this->config = $container->get('config'); + $this->extension_manager = $container->get('ext.manager'); + $this->log = $container->get('log'); + $this->migrator = $container->get('migrator'); + $this->user = $container->get('user'); + + parent::__construct(true); + } + + /** + * {@inheritdoc} + */ + public function run() + { + $this->language->add_lang('migrator'); + + if (!isset($this->config['version_update_from'])) + { + $this->config->set('version_update_from', $this->config['version']); + } + + $original_version = $this->config['version_update_from']; + + $this->migrator->set_output_handler( + new log_wrapper_migrator_output_handler( + $this->language, + new installer_migrator_output_handler($this->iohandler), + $this->phpbb_root_path . 'store/migrations_' . time() . '.log', + $this->filesystem + ) + ); + + $this->migrator->create_migrations_table(); + + $migrations = $this->extension_manager + ->get_finder() + ->core_path('phpbb/db/migration/data/') + ->extension_directory('/migrations') + ->get_classes(); + + $this->migrator->set_migrations($migrations); + $migration_count = count($migrations); + $this->iohandler->set_task_count($migration_count, true); + $progress_count = $this->installer_config->get('database_update_count', 0); + + while (!$this->migrator->finished()) + { + try + { + $this->migrator->update(); + $progress_count++; + $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count); + } + catch (exception $e) + { + $msg = $e->getParameters(); + array_unshift($msg, $e->getMessage()); + + $this->iohandler->add_error_message($msg); + throw new user_interaction_required_exception(); + } + + if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) + { + $this->installer_config->set('database_update_count', $progress_count); + throw new resource_limit_reached_exception(); + } + } + + if ($original_version !== $this->config['version']) + { + $this->log->add( + 'admin', + $this->user->data['user_id'], + $this->user->ip, + 'LOG_UPDATE_DATABASE', + false, + array( + $original_version, + $this->config['version'] + ) + ); + } + + $this->iohandler->finish_progress('INLINE_UPDATE_SUCCESSFUL'); + + $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL'); + + $this->config->delete('version_update_from'); + + $this->cache->purge(); + + $this->config->increment('assets_version', 1); + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/module.php b/phpBB/phpbb/install/module/update_filesystem/module.php new file mode 100644 index 0000000000..157c78a1ac --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/module.php @@ -0,0 +1,33 @@ +<?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\install\module\update_filesystem; + +class module extends \phpbb\install\module_base +{ + /** + * {@inheritdoc} + */ + public function get_navigation_stage_path() + { + return array('update', 0, 'update_files'); + } + + /** + * {@inheritdoc} + */ + public function get_step_count() + { + return 0; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php b/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php new file mode 100644 index 0000000000..e3e6db6263 --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/task/diff_files.php @@ -0,0 +1,205 @@ +<?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\install\module\update_filesystem\task; + +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\container_factory; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\helper\update_helper; +use phpbb\install\task_base; + +/** + * Merges user made changes into the files + */ +class diff_files extends task_base +{ + /** + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + + /** + * @var config + */ + protected $installer_config; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * @var string + */ + protected $php_ext; + + /** + * @var update_helper + */ + protected $update_helper; + + /** + * Constructor + * + * @param container_factory $container + * @param config $config + * @param iohandler_interface $iohandler + * @param update_helper $update_helper + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path, $php_ext) + { + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->update_helper = $update_helper; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->cache = $container->get('cache.driver'); + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + $files_to_diff = $this->installer_config->get('update_files', array()); + $files_to_diff = (isset($files_to_diff['update_with_diff'])) ? $files_to_diff['update_with_diff'] : array(); + + return $this->installer_config->get('do_update_files', false) && count($files_to_diff) > 0; + } + + /** + * {@inheritdoc} + */ + public function run() + { + // Include diff engine + $this->update_helper->include_file('includes/diff/diff.' . $this->php_ext); + $this->update_helper->include_file('includes/diff/engine.' . $this->php_ext); + + // Set up basic vars + $old_path = $this->update_helper->get_path_to_old_update_files(); + $new_path = $this->update_helper->get_path_to_new_update_files(); + + $files_to_diff = $this->installer_config->get('update_files', array()); + $files_to_diff = $files_to_diff['update_with_diff']; + + // Set progress bar + $this->iohandler->set_task_count(count($files_to_diff), true); + $this->iohandler->set_progress('UPDATE_FILE_DIFF', 0); + $progress_count = $this->installer_config->get('file_diff_update_count', 0); + + // Recover progress + $progress_key = $this->installer_config->get('differ_progress_key', -1); + $progress_recovered = ($progress_key === -1); + $merge_conflicts = $this->installer_config->get('merge_conflict_list', array()); + + foreach ($files_to_diff as $key => $filename) + { + if ($progress_recovered === false) + { + if ($progress_key === $key) + { + $progress_recovered = true; + } + + continue; + } + + // Read in files' content + $file_contents = array(); + + // Handle the special case when user created a file with the filename that is now new in the core + $file_contents[0] = (file_exists($old_path . $filename)) ? file_get_contents($old_path . $filename) : ''; + + $filenames = array( + $this->phpbb_root_path . $filename, + $new_path . $filename + ); + + foreach ($filenames as $file_to_diff) + { + $file_contents[] = file_get_contents($file_to_diff); + + if ($file_contents[sizeof($file_contents) - 1] === false) + { + $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff)); + unset($file_contents); + throw new user_interaction_required_exception(); + } + } + + $diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]); + unset($file_contents); + + // Handle conflicts + if ($diff->get_num_conflicts() !== 0) + { + $merge_conflicts[] = $filename; + } + + // Save merged output + $this->cache->put( + '_file_' . md5($filename), + base64_encode(implode("\n", $diff->merged_output())) + ); + + unset($diff); + + $progress_count++; + $this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count); + + if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) + { + // Save differ progress + $this->installer_config->set('differ_progress_key', $key); + $this->installer_config->set('merge_conflict_list', $merge_conflicts); + $this->installer_config->set('file_diff_update_count', $progress_count); + + // Request refresh + throw new resource_limit_reached_exception(); + } + } + + $this->iohandler->finish_progress('ALL_FILES_DIFFED'); + $this->installer_config->set('merge_conflict_list', $merge_conflicts); + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php b/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php new file mode 100644 index 0000000000..9271e8fd50 --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php @@ -0,0 +1,124 @@ +<?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\install\module\update_filesystem\task; + +use phpbb\filesystem\filesystem; +use phpbb\install\exception\jump_to_restart_point_exception; +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\task_base; + +class download_updated_files extends task_base +{ + /** + * @var config + */ + protected $installer_config; + + /** + * @var filesystem + */ + protected $filesystem; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * Constructor + * + * @param config $config + * @param iohandler_interface $iohandler + * @param filesystem $filesystem + */ + public function __construct(config $config, iohandler_interface $iohandler, filesystem $filesystem) + { + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->filesystem = $filesystem; + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false) + && $this->installer_config->get('file_update_method', '') === 'compression'; + } + + /** + * {@inheritdoc} + */ + public function run() + { + if ($this->iohandler->get_input('database_update_submit', false)) + { + // Remove archive + $this->filesystem->remove( + $this->installer_config->get('update_file_archive', null) + ); + + $this->installer_config->set('update_file_archive', null); + } + else if ($this->iohandler->get_input('update_recheck_files_submit', false)) + { + throw new jump_to_restart_point_exception('check_update_files'); + } + else + { + // Render download box + $this->iohandler->add_download_link( + 'phpbb_installer_update_file_download', + 'DOWNLOAD_UPDATE_METHOD', + 'DOWNLOAD_UPDATE_METHOD_EXPLAIN' + ); + + // Add form to continue update + $this->iohandler->add_user_form_group('UPDATE_CONTINUE_UPDATE_PROCESS', array( + 'update_recheck_files_submit' => array( + 'label' => 'UPDATE_RECHECK_UPDATE_FILES', + 'type' => 'submit', + ), + 'database_update_submit' => array( + 'label' => 'UPDATE_CONTINUE_UPDATE_PROCESS', + 'type' => 'submit', + ), + )); + + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/file_check.php b/phpBB/phpbb/install/module/update_filesystem/task/file_check.php new file mode 100644 index 0000000000..9945e61714 --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/task/file_check.php @@ -0,0 +1,186 @@ +<?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\install\module\update_filesystem\task; + +use phpbb\filesystem\filesystem; +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\helper\update_helper; +use phpbb\install\task_base; + +/** + * Updater task performing file checking + */ +class file_check extends task_base +{ + /** + * @var filesystem + */ + protected $filesystem; + + /** + * @var config + */ + protected $installer_config; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var update_helper + */ + protected $update_helper; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * Construct + * + * @param filesystem $filesystem + * @param config $config + * @param iohandler_interface $iohandler + * @param update_helper $update_helper + * @param string $phpbb_root_path + */ + public function __construct(filesystem $filesystem, config $config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path) + { + $this->filesystem = $filesystem; + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->update_helper = $update_helper; + $this->phpbb_root_path = $phpbb_root_path; + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false); + } + + /** + * {@inheritdoc} + */ + public function run() + { + if (!$this->installer_config->has_restart_point('check_update_files')) + { + $this->installer_config->create_progress_restart_point('check_update_files'); + } + + $old_path = $this->update_helper->get_path_to_old_update_files(); + $new_path = $this->update_helper->get_path_to_new_update_files(); + + $update_info = $this->installer_config->get('update_info', array()); + $file_update_info = $this->installer_config->get('update_files', array()); + + if (empty($update_info)) + { + $root_path = $this->phpbb_root_path; + + $update_info = $this->installer_config->get('update_info_unprocessed', array()); + + $file_update_info = array(); + $file_update_info['update_without_diff'] = $update_info['binary']; + + // Filter out files that are already deleted + $file_update_info['delete'] = array_filter( + $update_info['deleted'], + function ($filename) use ($root_path) + { + return !file_exists($root_path . $filename); + } + ); + } + + $progress_count = $this->installer_config->get('file_check_progress_count', 0); + $task_count = count($update_info['files']); + $this->iohandler->set_task_count($task_count); + $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0); + + foreach ($update_info['files'] as $key => $filename) + { + $old_file = $old_path . $filename; + $new_file = $new_path . $filename; + $file = $this->phpbb_root_path . $filename; + + if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) + { + // Save progress + $this->installer_config->set('update_info', $update_info); + $this->installer_config->set('file_check_progress_count', $progress_count); + $this->installer_config->set('update_files', $file_update_info); + + // Request refresh + throw new resource_limit_reached_exception(); + } + + $progress_count++; + $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count); + + if (!$this->filesystem->exists($file)) + { + $file_update_info['new'][] = $filename; + } + else + { + $file_checksum = md5_file($file); + + if ($file_checksum === md5_file($new_file)) + { + // File already up to date + continue; + } + else if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file)) + { + // No need to diff the file + $file_update_info['update_without_diff'][] = $filename; + } + else + { + $file_update_info['update_with_diff'][] = $filename; + } + } + + unset($update_info['files'][$key]); + } + + $this->installer_config->set('update_files', $file_update_info); + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php b/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php new file mode 100644 index 0000000000..1c6b9aa058 --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php @@ -0,0 +1,168 @@ +<?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\install\module\update_filesystem\task; + +use phpbb\filesystem\filesystem; +use phpbb\install\exception\user_interaction_required_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\container_factory; +use phpbb\install\helper\file_updater\factory; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\task_base; + +class show_file_status extends task_base +{ + /** + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + + /** + * @var filesystem + */ + protected $filesystem; + + /** + * @var config + */ + protected $installer_config; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var \phpbb\install\helper\file_updater\compression_file_updater + */ + protected $file_updater; + + /** + * Constructor + * + * @param container_factory $container + * @param config $config + * @param iohandler_interface $iohandler + * @param filesystem $filesystem + * @param factory $file_updater_factory + */ + public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, filesystem $filesystem, factory $file_updater_factory) + { + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->filesystem = $filesystem; + + $this->cache = $container->get('cache.driver'); + + // Initialize compression file updater + $compression_method = $this->installer_config->get('compression_method', ''); + $this->file_updater = $file_updater_factory->get('compression'); + $conflict_archive = $this->file_updater->init($compression_method); + + $this->installer_config->set('update_file_conflict_archive', $conflict_archive); + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false); + } + + /** + * {@inheritdoc} + */ + public function run() + { + if (!$this->iohandler->get_input('submit_continue_file_update', false)) + { + // Handle merge conflicts + $merge_conflicts = $this->installer_config->get('merge_conflict_list', array()); + + // Create archive for merge conflicts + if (!empty($merge_conflicts)) + { + foreach ($merge_conflicts as $filename) + { + $this->file_updater->create_new_file( + $filename, + $this->cache->get('_file_' . md5($filename)), + true + ); + } + + // Render download box + $this->iohandler->add_download_link( + 'phpbb_installer_update_conflict_download', + 'DOWNLOAD_CONFLICTS', + 'DOWNLOAD_CONFLICTS_EXPLAIN' + ); + } + + $this->file_updater->close(); + + // Render update file statuses + $file_update_info = $this->installer_config->get('update_files', array()); + $file_status = array( + 'deleted' => (!isset($file_update_info['delete'])) ? array() : $file_update_info['delete'], + 'new' => (!isset($file_update_info['new'])) ? array() : $file_update_info['new'], + 'conflict' => $this->installer_config->get('merge_conflict_list', array()), + 'modified' => (!isset($file_update_info['update_with_diff'])) ? array() : $file_update_info['update_with_diff'], + 'not_modified' => (!isset($file_update_info['update_without_diff'])) ? array() : $file_update_info['update_without_diff'], + ); + + $this->iohandler->render_update_file_status($file_status); + + // Add form to continue update + $this->iohandler->add_user_form_group('UPDATE_CONTINUE_FILE_UPDATE', array( + 'submit_continue_file_update' => array( + 'label' => 'UPDATE_CONTINUE_FILE_UPDATE', + 'type' => 'submit', + ), + )); + + // Show results to the user + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + else + { + // Remove archive + $this->filesystem->remove( + $this->installer_config->get('update_file_conflict_archive', null) + ); + + $this->installer_config->set('update_file_conflict_archive', null); + } + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/update_files.php b/phpBB/phpbb/install/module/update_filesystem/task/update_files.php new file mode 100644 index 0000000000..747a86281b --- /dev/null +++ b/phpBB/phpbb/install/module/update_filesystem/task/update_files.php @@ -0,0 +1,294 @@ +<?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\install\module\update_filesystem\task; + +use phpbb\exception\runtime_exception; +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\container_factory; +use phpbb\install\helper\file_updater\factory; +use phpbb\install\helper\file_updater\file_updater_interface; +use phpbb\install\helper\iohandler\iohandler_interface; +use phpbb\install\helper\update_helper; +use phpbb\install\task_base; + +/** + * File updater task + */ +class update_files extends task_base +{ + /** + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + + /** + * @var config + */ + protected $installer_config; + + /** + * @var iohandler_interface + */ + protected $iohandler; + + /** + * @var factory + */ + protected $factory; + + /** + * @var file_updater_interface + */ + protected $file_updater; + + /** + * @var update_helper + */ + protected $update_helper; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * Constructor + * + * @param container_factory $container + * @param config $config + * @param iohandler_interface $iohandler + * @param factory $file_updater_factory + * @param update_helper $update_helper + * @param string $phpbb_root_path + */ + public function __construct(container_factory $container, config $config, iohandler_interface $iohandler, factory $file_updater_factory, update_helper $update_helper, $phpbb_root_path) + { + $this->factory = $file_updater_factory; + $this->installer_config = $config; + $this->iohandler = $iohandler; + $this->update_helper = $update_helper; + $this->phpbb_root_path = $phpbb_root_path; + + $this->cache = $container->get('cache.driver'); + $this->file_updater = null; + + parent::__construct(false); + } + + /** + * {@inheritdoc} + */ + public function check_requirements() + { + return $this->installer_config->get('do_update_files', false); + } + + /** + * {@inheritdoc} + */ + public function run() + { + $new_path = $this->update_helper->get_path_to_new_update_files(); + + $file_update_info = $this->installer_config->get('update_files', array()); + + $update_type_progress = $this->installer_config->get('file_updater_type_progress', ''); + $update_elem_progress = $this->installer_config->get('file_updater_elem_progress', ''); + $type_progress_found = false; + $elem_progress_found = false; + + // Progress bar + $task_count = 0; + foreach ($file_update_info as $sub_array) + { + $task_count += count($sub_array); + } + + // Everything is up to date, so just continue + if ($task_count === 0) + { + return; + } + + $progress_count = $this->installer_config->get('file_update_progress_count', 0); + $this->iohandler->set_task_count($task_count, true); + $this->iohandler->set_progress('UPDATE_UPDATING_FILES', 0); + + $this->file_updater = $this->get_file_updater(); + + // File updater fallback logic + try + { + // Update files + foreach ($file_update_info as $type => $file_update_vector) + { + if (!$type_progress_found) + { + if ($type === $update_type_progress || empty($update_elem_progress)) + { + $type_progress_found = true; + } + else + { + continue; + } + } + + foreach ($file_update_vector as $path) + { + if (!$elem_progress_found) + { + if ($path === $update_elem_progress || empty($update_elem_progress)) + { + $elem_progress_found = true; + } + else + { + continue; + } + } + + switch ($type) + { + case 'delete': + $this->file_updater->delete_file($path); + break; + case 'new': + $this->file_updater->create_new_file($path, $new_path . $path); + break; + case 'update_without_diff': + $this->file_updater->update_file($path, $new_path . $path); + break; + case 'update_with_diff': + $this->file_updater->update_file( + $path, + $this->cache->get('_file_' . md5($path)), + true + ); + break; + } + + // Save progress + $this->installer_config->set('file_updater_type_progress', $type); + $this->installer_config->set('file_updater_elem_progress', $path); + $progress_count++; + $this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count); + + if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) + { + // Request refresh + throw new resource_limit_reached_exception(); + } + } + } + + $this->iohandler->finish_progress('UPDATE_UPDATING_FILES'); + } + catch (runtime_exception $e) + { + if ($e instanceof resource_limit_reached_exception) + { + throw new resource_limit_reached_exception(); + } + + $current_method = $this->installer_config->get('file_update_method', ''); + + // File updater failed, try to fallback to download file update mode + if ($current_method !== 'compression') + { + $this->iohandler->add_warning_message(array( + 'UPDATE_FILE_UPDATER_HAS_FAILED', + $current_method, + 'compression' + )); + $this->installer_config->set('file_update_method', 'compression'); + + // We only want a simple refresh here + throw new resource_limit_reached_exception(); + } + else + { + // Nowhere to fallback to :( + // Due to the way the installer handles fatal errors, we need to throw a low level exception + throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED'); + } + } + + $file_updater_method = $this->installer_config->get('file_update_method', ''); + if ($file_updater_method === 'compression' || $file_updater_method === 'ftp') + { + $this->file_updater->close(); + } + } + + /** + * Get file updater + * + * @param null|string $file_updater_method Name of the file updater to use + * + * @return file_updater_interface File updater + */ + protected function get_file_updater($file_updater_method = null) + { + $file_updater_method = ($file_updater_method === null) ? $this->installer_config->get('file_update_method', '') : $file_updater_method; + + if ($file_updater_method === 'compression') + { + $compression_method = $this->installer_config->get('file_update_compression', ''); + + /** @var \phpbb\install\helper\file_updater\compression_file_updater $file_updater */ + $file_updater = $this->factory->get('compression'); + $archive_path = $file_updater->init($compression_method); + $this->installer_config->set('update_file_archive', $archive_path); + } + else if ($file_updater_method === 'ftp') + { + /** @var \phpbb\install\helper\file_updater\ftp_file_updater $file_updater */ + $file_updater = $this->factory->get('ftp'); + $file_updater->init( + $this->installer_config->get('ftp_method', ''), + $this->installer_config->get('ftp_host', ''), + $this->installer_config->get('ftp_user', ''), + $this->installer_config->get('ftp_pass', ''), + $this->installer_config->get('ftp_path', ''), + $this->installer_config->get('ftp_port', 0), + $this->installer_config->get('ftp_timeout', 10) + ); + } + else + { + /** @var file_updater_interface $file_updater */ + $file_updater = $this->factory->get('direct_file'); + } + + return $file_updater; + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return ''; + } +} |