Note: When an array is passed into the parameters below, it will be
resolved as printf($param[0], $param[1], ...).
public add_warning_message ( string | array $warning_title, string | boolean | array $warning_description = false ) | ||
$warning_title | string | array | Title of the warning message |
$warning_description | string | boolean | array | Description of the warning (and possibly guidelines to resolve it), or false if the warning description is not available |
/** * {@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_warning_message('UPDATE_FILES_NOT_FOUND'); $this->set_test_passed(false); // If there are no update files, we can't check the version etc // However, we can let the users run migrations if they really want to... $this->installer_config->set('disable_filesystem_update', true); return true; } // 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; }
/** * Check if a directory is readable and writable * * @param string $dir Filename * @param bool $failable Whether failing test should abort the installation process */ protected function check_dir($dir, $failable = false) { $path = $this->phpbb_root_path . $dir; $exists = $writable = false; // Try to create the directory if it does not exist if (!file_exists($path)) { try { $this->filesystem->mkdir($path, 0777); $this->filesystem->phpbb_chmod($path, \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE); $exists = true; } catch (\phpbb\filesystem\exception\filesystem_exception $e) { // Do nothing } } // Now really check if (file_exists($path) && is_dir($path)) { try { $exists = true; $this->filesystem->phpbb_chmod($path, \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE); } catch (\phpbb\filesystem\exception\filesystem_exception $e) { // Do nothing } } if ($this->filesystem->is_writable($path)) { $writable = true; } $this->set_test_passed($exists && $writable || $failable); if (!($exists && $writable)) { $title = $exists ? 'DIRECTORY_NOT_WRITABLE' : 'DIRECTORY_NOT_EXISTS'; $lang_suffix = '_EXPLAIN'; $lang_suffix .= $failable ? '_OPTIONAL' : ''; $description = array($title . $lang_suffix, $dir); if ($failable) { $this->response->add_warning_message($title, $description); } else { $this->response->add_error_message($title, $description); } } }
/** * {@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(); } }