add_error_message() public method

Note: When an array is passed into the parameters below, it will be resolved as printf($param[0], $param[1], ...).
public add_error_message ( string | array $error_title, string | boolean | array $error_description = false )
$error_title string | array Title of the error message.
$error_description string | boolean | array Description of the error (and possibly guidelines to resolve it), or false if the error description is not available.
Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $languages = $this->language_helper->get_available_languages();
     $installed_languages = array();
     foreach ($languages as $lang_info) {
         $lang_pack = array('lang_iso' => $lang_info['iso'], 'lang_dir' => $lang_info['iso'], 'lang_english_name' => htmlspecialchars($lang_info['name']), 'lang_local_name' => htmlspecialchars($lang_info['local_name'], ENT_COMPAT, 'UTF-8'), 'lang_author' => htmlspecialchars($lang_info['author'], ENT_COMPAT, 'UTF-8'));
         $this->db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $this->db->sql_build_array('INSERT', $lang_pack));
         $installed_languages[] = (int) $this->db->sql_nextid();
         if ($this->db->get_sql_error_triggered()) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message($error['message']);
         }
     }
     $sql = 'SELECT * FROM ' . PROFILE_FIELDS_TABLE;
     $result = $this->db->sql_query($sql);
     $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE);
     while ($row = $this->db->sql_fetchrow($result)) {
         foreach ($installed_languages as $lang_id) {
             $insert_buffer->insert(array('field_id' => $row['field_id'], 'lang_id' => $lang_id, 'lang_name' => strtoupper(substr($row['field_name'], 6)), 'lang_explain' => '', 'lang_default_value' => ''));
         }
     }
     $this->db->sql_freeresult($result);
     $insert_buffer->flush();
 }
 /**
  * Check admin data
  *
  * @param string	$username	Admin username
  * @param string	$pass1		Admin password
  * @param string	$pass2		Admin password confirmation
  * @param string	$email		Admin e-mail address
  *
  * @return bool	True if data is valid, false otherwise
  */
 protected function check_admin_data($username, $pass1, $pass2, $email)
 {
     $data_valid = true;
     // Check if none of admin data is empty
     if (in_array('', array($username, $pass1, $pass2, $email), true)) {
         $this->io_handler->add_error_message('INST_ERR_MISSING_DATA');
         $data_valid = false;
     }
     if (utf8_strlen($username) < 3) {
         $this->io_handler->add_error_message('INST_ERR_USER_TOO_SHORT');
         $data_valid = false;
     }
     if (utf8_strlen($username) > 20) {
         $this->io_handler->add_error_message('INST_ERR_USER_TOO_LONG');
         $data_valid = false;
     }
     if ($pass1 !== $pass2 && $pass1 !== '') {
         $this->io_handler->add_error_message('INST_ERR_PASSWORD_MISMATCH');
         $data_valid = false;
     }
     // Test against the default password rules
     if (utf8_strlen($pass1) < 6) {
         $this->io_handler->add_error_message('INST_ERR_PASSWORD_TOO_SHORT');
         $data_valid = false;
     }
     if (utf8_strlen($pass1) > 30) {
         $this->io_handler->add_error_message('INST_ERR_PASSWORD_TOO_LONG');
         $data_valid = false;
     }
     if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email)) {
         $this->io_handler->add_error_message('INST_ERR_EMAIL_INVALID');
         $data_valid = false;
     }
     return $data_valid;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $table_prefix = $this->config->get('table_prefix');
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     // Get schema data from file
     $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
     // Clean up SQL
     $sql_query = $this->replace_dbms_specific_sql($sql_query);
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query);
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
     $i = $this->config->get('add_default_data_index', 0);
     $total = sizeof($sql_query);
     $sql_query = array_slice($sql_query, $i);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
             break;
         }
     }
     $this->config->set('add_default_data_index', $i);
     if ($i < $total) {
         throw new resource_limit_reached_exception();
     }
 }
 /**
  * Check database data
  *
  * @param string	$dbms			Selected database type
  * @param string	$dbhost			Database host address
  * @param int		$dbport			Database port number
  * @param string	$dbuser			Database username
  * @param string	$dbpass			Database password
  * @param string	$dbname			Database name
  * @param string	$table_prefix	Database table prefix
  *
  * @return bool	True if database data is correct, false otherwise
  */
 protected function check_database_data($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix)
 {
     $available_dbms = $this->database_helper->get_available_dbms();
     $data_valid = true;
     // Check if PHP has the database extensions for the specified DBMS
     if (!isset($available_dbms[$dbms])) {
         $this->io_handler->add_error_message('INST_ERR_NO_DB');
         $data_valid = false;
     }
     // Validate table prefix
     $prefix_valid = $this->database_helper->validate_table_prefix($dbms, $table_prefix);
     if (is_array($prefix_valid)) {
         foreach ($prefix_valid as $error) {
             $this->io_handler->add_error_message($error['title'], isset($error['description']) ? $error['description'] : false);
         }
         $data_valid = false;
     }
     // Try to connect to database if all provided data is valid
     if ($data_valid) {
         $connect_test = $this->database_helper->check_database_connection($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix);
         if (is_array($connect_test)) {
             foreach ($connect_test as $error) {
                 $this->io_handler->add_error_message($error['title'], isset($error['description']) ? $error['description'] : false);
             }
             $data_valid = false;
         }
     }
     return $data_valid;
 }
Beispiel #5
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'";
        $result = $this->db->sql_query($sql);
        $group_id = (int) $this->db->sql_fetchfield('group_id');
        $this->db->sql_freeresult($result);
        if (!$group_id) {
            // If we reach this point then something has gone very wrong
            $this->io_handler->add_error_message('NO_GROUP');
        }
        foreach ($this->bot_list as $bot_name => $bot_ary) {
            $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => '9E8DA7', 'user_email' => '', 'user_lang' => $this->install_config->get('default_lang'), 'user_style' => 1, 'user_timezone' => 'UTC', 'user_dateformat' => $this->language->lang('default_dateformat'), 'user_allow_massemail' => 0, 'user_allow_pm' => 0);
            if (!function_exists('user_add')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $user_id = user_add($user_row);
            if (!$user_id) {
                // If we can't insert this user then continue to the next one to avoid inconsistent data
                $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
                continue;
            }
            $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1]));
            $this->db->sql_query($sql);
        }
    }
Beispiel #6
0
 /**
  * {@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_step_count = $this->installer_config->get('database_update_migration_steps', -1);
     if ($migration_step_count < 0) {
         $migration_step_count = count($this->migrator->get_installable_migrations()) * 2;
         $this->installer_config->set('database_update_migration_steps', $migration_step_count);
     }
     $progress_count = $this->installer_config->get('database_update_count', 0);
     $restart_progress_bar = $progress_count === 0;
     // Only "restart" when the update runs for the first time
     $this->iohandler->set_task_count($migration_step_count, $restart_progress_bar);
     $this->installer_config->set_task_progress_count($migration_step_count);
     while (!$this->migrator->finished()) {
         try {
             $this->migrator->update();
             $progress_count++;
             $last_run_migration = $this->migrator->get_last_run_migration();
             if (isset($last_run_migration['effectively_installed']) && $last_run_migration['effectively_installed']) {
                 // We skipped two step, so increment $progress_count by another one
                 $progress_count++;
             } else {
                 if ($last_run_migration['task'] === 'process_schema_step' && !$last_run_migration['state']['migration_schema_done'] || $last_run_migration['task'] === 'process_data_step' && !$last_run_migration['state']['migration_data_done']) {
                     // We just run a step that wasn't counted yet so make it count
                     $migration_step_count++;
                 }
             }
             $this->iohandler->set_task_count($migration_step_count);
             $this->installer_config->set_task_progress_count($migration_step_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);
             $this->installer_config->set('database_update_migration_steps', $migration_step_count);
             throw new resource_limit_reached_exception();
         }
     }
     if ($original_version !== $this->config['version']) {
         $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version']));
     }
     $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL');
     $this->config->delete('version_update_from');
     $this->cache->purge();
     $this->config->increment('assets_version', 1);
 }
 /**
  * Check if any supported DBMS is available
  */
 protected function check_available_dbms()
 {
     $available_dbms = $this->database_helper->get_available_dbms(false, true);
     if ($available_dbms['ANY_DB_SUPPORT']) {
         $this->set_test_passed(true);
         return;
     }
     $this->response_helper->add_error_message('PHP_SUPPORTED_DB', 'PHP_SUPPORTED_DB_EXPLAIN');
     $this->set_test_passed(false);
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $server_name = $this->install_config->get('server_name');
     $current_time = time();
     $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
     $user_ip = $user_ip === false ? '' : $user_ip;
     $referer = $this->iohandler->get_server_variable('REFERER');
     // Calculate cookie domain
     $cookie_domain = $server_name;
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = substr($cookie_domain, 3);
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('img_imagick')) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'\n\t\t\t\tWHERE config_name = 'smtp_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'\n\t\t\t\tWHERE config_name = 'sitename'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET username = '******'admin_name')) . "',\n\t\t\t\t\tuser_password='******'admin_passwd')) . "',\n\t\t\t\t\tuser_ip = '" . $this->db->sql_escape($user_ip) . "',\n\t\t\t\t\tuser_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',\n\t\t\t\t\tuser_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',\n\t\t\t\t\tuser_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',\n\t\t\t\t\tuser_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",\n\t\t\t\t\tusername_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '******'admin_name')) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\ttopic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $this->posts_table . "\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $this->db->sql_escape($user_ip) . "'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     // Disable avatars if upload directory is not writable
     if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar_upload'";
     }
     $i = $this->install_config->get('add_config_settings_index', 0);
     $total = sizeof($sql_ary);
     $sql_ary = array_slice($sql_ary, $i);
     foreach ($sql_ary as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         $this->install_config->set('add_config_settings_index', $i);
         throw new resource_limit_reached_exception();
     }
 }
Beispiel #9
0
 /**
  * {@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}
  */
 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';
         if ($this->installer_config->get('disable_filesystem_update', false) && $update_files) {
             $this->iohandler->add_error_message('UPDATE_FILES_NOT_FOUND');
             throw new user_interaction_required_exception();
         }
         $this->installer_config->set('do_update_files', $update_files);
     } else {
         if ($this->installer_config->get('disable_filesystem_update', false)) {
             $options[] = array('value' => 'db_only', 'label' => 'UPDATE_TYPE_DB_ONLY', 'selected' => true);
         } else {
             $options = array(array('value' => 'all', 'label' => 'UPDATE_TYPE_ALL', 'selected' => true), array('value' => 'db_only', 'label' => 'UPDATE_TYPE_DB_ONLY', 'selected' => false));
         }
         $this->iohandler->add_user_form_group('UPDATE_TYPE', array('update_type' => array('label' => 'UPDATE_TYPE', 'type' => 'radio', 'options' => $options), 'submit_update' => array('label' => 'SUBMIT', 'type' => 'submit')));
         throw new user_interaction_required_exception();
     }
 }
Beispiel #11
0
 /**
  * Renders an error form
  *
  * @param string		$msg
  * @param string|bool	$desc
  */
 public function render_error($msg, $desc = false)
 {
     if ($this->request->is_ajax()) {
         $this->iohandler->add_error_message($msg, $desc);
         $this->iohandler->send_response(true);
     } else {
         $this->template->assign_vars(array('S_ERROR_BOX' => true, 'ERROR_TITLE' => $this->language->lang($msg)));
         if ($desc) {
             $this->template->assign_var('ERROR_MSG', $this->language->lang($desc));
         }
     }
 }
Beispiel #12
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $table_prefix = $this->config->get('table_prefix');
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     // Get schema data from file
     $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
     // Clean up SQL
     $sql_query = $this->replace_dbms_specific_sql($sql_query);
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query);
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
     }
 }
Beispiel #13
0
 /**
  * {@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;
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $delimiter = $dbms_info[$dbms]['DELIM'];
     $table_prefix = $this->config->get('table_prefix');
     $sql_query = @file_get_contents($this->schema_file_path);
     $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
     $sql_query = $this->database_helper->remove_comments($sql_query);
     $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
     foreach ($sql_query as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
     }
     unset($sql_query);
 }
Beispiel #15
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $config_written = true;
     // Create config.php
     $path_to_config = $this->phpbb_root_path . 'config.' . $this->php_ext;
     $fp = @fopen($path_to_config, 'w');
     if (!$fp) {
         $config_written = false;
     }
     $config_content = $this->get_config_data();
     if (!@fwrite($fp, $config_content)) {
         $config_written = false;
     }
     @fclose($fp);
     // chmod config.php to be only readable
     if ($config_written) {
         try {
             $this->filesystem->phpbb_chmod($path_to_config, \phpbb\filesystem\filesystem_interface::CHMOD_READ);
         } catch (\phpbb\filesystem\exception\filesystem_exception $e) {
             // Do nothing, the user will get a notice later
         }
     } else {
         $this->iohandler->add_error_message('UNABLE_TO_WRITE_CONFIG_FILE');
         $this->iohandler->send_response();
         throw new user_interaction_required_exception();
     }
     // Create a lock file to indicate that there is an install in progress
     $fp = @fopen($this->phpbb_root_path . 'cache/install_lock', 'wb');
     if ($fp === false) {
         // We were unable to create the lock file - abort
         $this->iohandler->add_error_message('UNABLE_TO_WRITE_LOCK');
         $this->iohandler->send_response();
         throw new user_interaction_required_exception();
     }
     @fclose($fp);
     try {
         $this->filesystem->phpbb_chmod($this->phpbb_root_path . 'cache/install_lock', 0777);
     } catch (\phpbb\filesystem\exception\filesystem_exception $e) {
         // Do nothing, the user will get a notice later
     }
 }
Beispiel #16
0
 /**
  * {@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($this->migrator->get_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);
             $this->iohandler->send_response();
             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', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $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);
 }
Beispiel #17
0
 /**
  * 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);
         }
     }
 }
Beispiel #18
0
    /**
     * Add extra modules
     *
     * @param string	$module_class
     */
    protected function add_module_extras($module_class)
    {
        foreach ($this->module_extras[$module_class] as $cat_name => $mods) {
            $sql = 'SELECT module_id, left_id, right_id
				FROM ' . MODULES_TABLE . "\n\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'\n\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'";
            $result = $this->db->sql_query_limit($sql, 1);
            $row2 = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            foreach ($mods as $mod_name) {
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'\n\t\t\t\t\t\tAND module_basename <> ''";
                $result = $this->db->sql_query_limit($sql, 1);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $module_data = array('module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth']);
                $this->module_manager->update_module_data($module_data);
                // Check for last sql error happened
                if ($this->db->get_sql_error_triggered()) {
                    $error = $this->db->sql_error($this->db->get_sql_error_sql());
                    $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
                }
            }
        }
    }
Beispiel #19
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);
 }
Beispiel #20
0
 /**
  * Run phpBB installer
  */
 public function run()
 {
     if ($this->iohandler instanceof ajax_iohandler) {
         $this->iohandler->acquire_lock();
     }
     // Load install progress
     $this->install_config->load_config();
     if (!$this->install_config->get('cache_purged_before', false) && $this->purge_cache_before) {
         /** @var \phpbb\cache\driver\driver_interface $cache */
         $cache = $this->container_factory->get('cache.driver');
         $cache->purge();
         $this->install_config->set('cache_purged_before', true);
     }
     // Recover install progress
     $module_index = $this->recover_progress();
     // Variable used to check if the install process have been finished
     $install_finished = false;
     $fail_cleanup = false;
     $send_refresh = false;
     // We are installing something, so the introduction stage can go now...
     $this->install_config->set_finished_navigation_stage(array('install', 0, 'introduction'));
     $this->iohandler->set_finished_stage_menu(array('install', 0, 'introduction'));
     if ($this->install_config->get_task_progress_count() === 0) {
         // Count all tasks in the current installer modules
         $step_count = 0;
         /** @var \phpbb\install\module_interface $module */
         foreach ($this->installer_modules as $name => $module) {
             $module_step_count = $module->get_step_count();
             $step_count += $module_step_count;
             $this->module_step_count[$name] = $module_step_count;
         }
         // Set task count
         $this->install_config->set_task_progress_count($step_count);
     }
     // Set up progress information
     $this->iohandler->set_task_count($this->install_config->get_task_progress_count());
     try {
         $iterator = $this->installer_modules->getIterator();
         if ($module_index < $iterator->count()) {
             $iterator->seek($module_index);
         } else {
             $iterator->seek($module_index - 1);
             $iterator->next();
         }
         while ($iterator->valid()) {
             $module = $iterator->current();
             $name = $iterator->key();
             // Check if module should be executed
             if (!$module->is_essential() && !$module->check_requirements()) {
                 $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
                 $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
                 $this->iohandler->add_log_message(array('SKIP_MODULE', $name));
                 $this->install_config->increment_current_task_progress($this->module_step_count[$name]);
             } else {
                 // Set the correct stage in the navigation bar
                 $this->install_config->set_active_navigation_stage($module->get_navigation_stage_path());
                 $this->iohandler->set_active_stage_menu($module->get_navigation_stage_path());
                 $this->iohandler->send_response();
                 $module->run();
                 $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
                 $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
             }
             $module_index++;
             $iterator->next();
             // Save progress
             $this->install_config->set_active_module($name, $module_index);
             if ($iterator->valid() && ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)) {
                 throw new resource_limit_reached_exception();
             }
         }
         // Installation finished
         $install_finished = true;
         if ($this->iohandler instanceof cli_iohandler) {
             $this->iohandler->add_success_message('INSTALLER_FINISHED');
         } else {
             global $SID;
             $acp_url = $this->web_root . 'adm/index.php' . $SID;
             $this->iohandler->add_success_message('INSTALLER_FINISHED', array('ACP_LINK', $acp_url));
         }
     } catch (user_interaction_required_exception $e) {
         $this->iohandler->send_response(true);
     } catch (resource_limit_reached_exception $e) {
         $send_refresh = true;
     } catch (jump_to_restart_point_exception $e) {
         $this->install_config->jump_to_restart_point($e->get_restart_point_name());
         $send_refresh = true;
     } catch (\Exception $e) {
         $this->iohandler->add_error_message($e->getMessage());
         $this->iohandler->send_response(true);
         $fail_cleanup = true;
     }
     if ($this->iohandler instanceof ajax_iohandler) {
         $this->iohandler->release_lock();
     }
     if ($install_finished) {
         // Send install finished message
         $this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
         $this->iohandler->send_response(true);
     } else {
         if ($send_refresh) {
             $this->iohandler->request_refresh();
             $this->iohandler->send_response(true);
         }
     }
     // Save install progress
     try {
         if ($install_finished || $fail_cleanup) {
             $this->install_config->clean_up_config_file();
             $this->cache->purge();
             try {
                 /** @var \phpbb\cache\driver\driver_interface $cache */
                 $cache = $this->container_factory->get('cache.driver');
                 $cache->purge();
             } catch (cannot_build_container_exception $e) {
                 // Do not do anything, this just means there is no config.php yet
             }
         } else {
             $this->install_config->save_config();
         }
     } catch (installer_config_not_writable_exception $e) {
         // It is allowed to fail this test during requirements testing
         $progress_data = $this->install_config->get_progress_data();
         if ($progress_data['last_task_module_name'] !== 'installer.module.requirements_install') {
             $this->iohandler->add_error_message('INSTALLER_CONFIG_NOT_WRITABLE');
         }
     }
 }
Beispiel #21
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $schema_name = $dbms_info[$dbms]['SCHEMA'];
     $delimiter = $dbms_info[$dbms]['DELIM'];
     $table_prefix = $this->config->get('table_prefix');
     if ($dbms === 'mysql') {
         if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $schema_name .= '_41';
         } else {
             $schema_name .= '_40';
         }
     }
     $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
     // Load database vendor specific code if there is any
     if ($this->filesystem->exists($db_schema_path)) {
         $sql_query = @file_get_contents($db_schema_path);
         $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
         $sql_query = $this->database_helper->remove_comments($sql_query);
         $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
         foreach ($sql_query as $sql) {
             if (!$this->db->sql_query($sql)) {
                 $error = $this->db->sql_error($this->db->get_sql_error_sql());
                 $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
             }
         }
         unset($sql_query);
     }
     $change_prefix = false;
     // Generate database schema
     if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json')) {
         $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
         $change_prefix = true;
     } else {
         global $table_prefix;
         $table_prefix = $this->config->get('table_prefix');
         if (!defined('CONFIG_TABLE')) {
             // We need to include the constants file for the table constants
             // when we generate the schema from the migration files.
             include $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
         }
         $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
         $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($this->db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($migrator_classes, new \phpbb\config\config(array()), $this->db, $db_tools, $this->phpbb_root_path, $this->php_ext, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     if (!defined('CONFIG_TABLE')) {
         // CONFIG_TABLE is required by sql_create_index() to check the
         // length of index names. However table_prefix is not defined
         // here yet, so we need to create the constant ourselves.
         define('CONFIG_TABLE', $table_prefix . 'config');
     }
     foreach ($db_table_schema as $table_name => $table_data) {
         $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data);
     }
 }
Beispiel #22
0
 /**
  * Run phpBB installer
  */
 public function run()
 {
     // Load install progress
     $this->install_config->load_config();
     // Recover install progress
     $module_name = $this->recover_progress();
     $module_found = false;
     // Variable used to check if the install process have been finished
     $install_finished = false;
     $fail_cleanup = false;
     $send_refresh = false;
     // We are installing something, so the introduction stage can go now...
     $this->install_config->set_finished_navigation_stage(array('install', 0, 'introduction'));
     $this->iohandler->set_finished_stage_menu(array('install', 0, 'introduction'));
     if ($this->install_config->get_task_progress_count() === 0) {
         // Count all tasks in the current installer modules
         $step_count = 0;
         /** @var \phpbb\install\module_interface $module */
         foreach ($this->installer_modules as $name => $module) {
             $module_step_count = $module->get_step_count();
             $step_count += $module_step_count;
             $this->module_step_count[$name] = $module_step_count;
         }
         // Set task count
         $this->install_config->set_task_progress_count($step_count);
     }
     // Set up progress information
     $this->iohandler->set_task_count($this->install_config->get_task_progress_count());
     try {
         foreach ($this->installer_modules as $name => $module) {
             // Skip forward until the current task is reached
             if (!$module_found) {
                 if ($module_name === $name || empty($module_name)) {
                     $module_found = true;
                 } else {
                     continue;
                 }
             }
             // Log progress
             $this->install_config->set_active_module($name);
             // Run until there are available resources
             if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
                 throw new resource_limit_reached_exception();
             }
             // Check if module should be executed
             if (!$module->is_essential() && !$module->check_requirements()) {
                 $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
                 $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
                 $this->iohandler->add_log_message(array('SKIP_MODULE', $name));
                 $this->install_config->increment_current_task_progress($this->module_step_count[$name]);
                 continue;
             }
             // Set the correct stage in the navigation bar
             $this->install_config->set_active_navigation_stage($module->get_navigation_stage_path());
             $this->iohandler->set_active_stage_menu($module->get_navigation_stage_path());
             $module->run();
             $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
             $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
         }
         // Installation finished
         $install_finished = true;
         if ($this->iohandler instanceof cli_iohandler) {
             $this->iohandler->add_success_message('INSTALLER_FINISHED');
         } else {
             global $SID;
             $acp_url = $this->web_root . 'adm/index.php' . $SID;
             $this->iohandler->add_success_message('INSTALLER_FINISHED', array('ACP_LINK', $acp_url));
         }
     } catch (user_interaction_required_exception $e) {
         // Do nothing
     } catch (resource_limit_reached_exception $e) {
         $send_refresh = true;
     } catch (jump_to_restart_point_exception $e) {
         $this->install_config->jump_to_restart_point($e->get_restart_point_name());
         $send_refresh = true;
     } catch (\Exception $e) {
         $this->iohandler->add_error_message($e->getMessage());
         $this->iohandler->send_response();
         $fail_cleanup = true;
     }
     if ($install_finished) {
         // Send install finished message
         $this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
     } else {
         if ($send_refresh) {
             $this->iohandler->request_refresh();
             $this->iohandler->send_response();
         }
     }
     // Save install progress
     try {
         if ($install_finished || $fail_cleanup) {
             $this->install_config->clean_up_config_file();
         } else {
             $this->install_config->save_config();
         }
     } catch (installer_config_not_writable_exception $e) {
         // It is allowed to fail this test during requirements testing
         $progress_data = $this->install_config->get_progress_data();
         if ($progress_data['last_task_module_name'] !== 'installer.module.requirements_install') {
             $this->iohandler->add_error_message('INSTALLER_CONFIG_NOT_WRITABLE');
         }
     }
 }
Beispiel #23
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $module_classes = array('acp', 'mcp', 'ucp');
        foreach ($module_classes as $module_class) {
            $categories = array();
            foreach ($this->module_categories[$module_class] as $cat_name => $subs) {
                // Check if this sub-category has a basename. If it has, use it.
                $basename = isset($this->module_categories_basenames[$cat_name]) ? $this->module_categories_basenames[$cat_name] : '';
                $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => '');
                $this->module_manager->update_module_data($module_data);
                // Check for last sql error happened
                if ($this->db->get_sql_error_triggered()) {
                    $error = $this->db->sql_error($this->db->get_sql_error_sql());
                    $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
                }
                $categories[$cat_name]['id'] = (int) $module_data['module_id'];
                $categories[$cat_name]['parent_id'] = 0;
                if (is_array($subs)) {
                    foreach ($subs as $level2_name) {
                        // Check if this sub-category has a basename. If it has, use it.
                        $basename = isset($this->module_categories_basenames[$level2_name]) ? $this->module_categories_basenames[$level2_name] : '';
                        $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $level2_name, 'module_mode' => '', 'module_auth' => '');
                        $this->module_manager->update_module_data($module_data);
                        // Check for last sql error happened
                        if ($this->db->get_sql_error_triggered()) {
                            $error = $this->db->sql_error($this->db->get_sql_error_sql());
                            $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
                        }
                        $categories[$level2_name]['id'] = (int) $module_data['module_id'];
                        $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
                    }
                }
            }
            // Get the modules we want to add... returned sorted by name
            $module_info = $this->module_manager->get_module_infos($module_class);
            foreach ($module_info as $module_basename => $fileinfo) {
                foreach ($fileinfo['modes'] as $module_mode => $row) {
                    foreach ($row['cat'] as $cat_name) {
                        if (!isset($categories[$cat_name])) {
                            continue;
                        }
                        $module_data = array('module_basename' => $module_basename, 'module_enabled' => 1, 'module_display' => isset($row['display']) ? (int) $row['display'] : 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $row['title'], 'module_mode' => $module_mode, 'module_auth' => $row['auth']);
                        $this->module_manager->update_module_data($module_data);
                        // Check for last sql error happened
                        if ($this->db->get_sql_error_triggered()) {
                            $error = $this->db->sql_error($this->db->get_sql_error_sql());
                            $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
                        }
                    }
                }
            }
            // Move some of the modules around since the code above will put them in the wrong place
            if ($module_class === 'acp') {
                // Move main module 4 up...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_main'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'main'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
                // Move permissions intro screen module 4 up...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_permissions'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'intro'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
                // Move manage users screen module 5 up...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'overview'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'acp', 'move_up', 5);
                // Move extension management module 1 up...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = ''\n\t\t\t\t\t\tAND module_basename = ''";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'acp', 'move_up', 1);
            }
            if ($module_class == 'mcp') {
                // Move pm report details module 3 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_report_details'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
                // Move closed pm reports module 3 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports_closed'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
                // Move open pm reports module 3 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
            }
            if ($module_class == 'ucp') {
                // Move attachment module 4 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_attachments'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'attachments'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
                // Move notification options module 4 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_notifications'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'notification_options'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
                // Move OAuth module 5 down...
                $sql = 'SELECT *
					FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_auth_link'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'auth_link'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->module_manager->move_module_by($row, 'ucp', 'move_down', 5);
            }
            // And now for the special ones
            // (these are modules which appear in multiple categories and thus get added manually
            // to some for more control)
            if (isset($this->module_extras[$module_class])) {
                foreach ($this->module_extras[$module_class] as $cat_name => $mods) {
                    $sql = 'SELECT module_id, left_id, right_id
						FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'";
                    $result = $this->db->sql_query_limit($sql, 1);
                    $row2 = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    foreach ($mods as $mod_name) {
                        $sql = 'SELECT *
							FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'\n\t\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($module_class) . "'\n\t\t\t\t\t\t\t\tAND module_basename <> ''";
                        $result = $this->db->sql_query_limit($sql, 1);
                        $row = $this->db->sql_fetchrow($result);
                        $this->db->sql_freeresult($result);
                        $module_data = array('module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth']);
                        $this->module_manager->update_module_data($module_data);
                        // Check for last sql error happened
                        if ($this->db->get_sql_error_triggered()) {
                            $error = $this->db->sql_error($this->db->get_sql_error_sql());
                            $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
                        }
                    }
                }
            }
            $this->module_manager->remove_cache_file($module_class);
        }
    }