Esempio n. 1
0
 /**
  * Validates settings form
  *
  * @param string	$convertor
  */
 public function proccess_settings_form($convertor)
 {
     global $phpbb_root_path, $phpEx, $get_info;
     $phpbb_root_path = $this->phpbb_root_path;
     $phpEx = $this->php_ext;
     $get_info = true;
     require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
     require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
     // Include convertor if available
     $convertor_file_path = $this->phpbb_root_path . 'install/convertors/convert_' . $convertor . '.' . $this->php_ext;
     include $convertor_file_path;
     // We expect to have an AJAX request here
     $src_dbms = $this->request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $this->request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $this->request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $this->request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $this->request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $this->request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $this->request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $this->request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $this->request->variable('refresh', 1);
     // Default URL of the old board
     // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
     //		-> We should convert old urls to the new relative urls format
     // $src_url = $request->variable('src_url', 'Not in use at the moment');
     // strip trailing slash from old forum path
     $forum_path = strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/' ? substr($forum_path, 0, -1) : $forum_path;
     $error = array();
     if (!file_exists($this->phpbb_root_path . $forum_path . '/' . $test_file)) {
         $error[] = $this->language->lang('COULD_NOT_FIND_PATH', $forum_path);
     }
     $connect_test = false;
     $available_dbms = $this->db_helper->get_available_dbms(false, true, true);
     if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
         $error[] = $this->language->lang('INST_ERR_NO_DB');
     } else {
         $connect_test = $this->db_helper->check_database_connection($src_dbms, $src_dbhost, $src_dbport, $src_dbuser, $src_dbpasswd, $src_dbname, $src_table_prefix);
     }
     extract($this->config_php_file->get_all());
     // The forum prefix of the old and the new forum can only be the same if two different databases are used.
     if ($src_table_prefix === $table_prefix && $src_dbms === $dbms && $src_dbhost === $dbhost && $src_dbport === $dbport && $src_dbname === $dbname) {
         $error[] = $this->language->lang('TABLE_PREFIX_SAME', $src_table_prefix);
     }
     if (!$connect_test) {
         $error[] = $this->language->lang('INST_ERR_DB_CONNECT');
     }
     $src_dbms = $this->config_php_file->convert_30_dbms_to_31($src_dbms);
     // Check table prefix
     if (empty($error)) {
         // initiate database connection to old db if old and new db differ
         global $src_db, $same_db;
         $src_db = $same_db = false;
         if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) {
             /** @var \phpbb\db\driver\driver_interface $src_db */
             $src_db = new $src_dbms();
             $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
             $same_db = false;
         } else {
             $src_db = $this->db;
             $same_db = true;
         }
         $src_db->sql_return_on_error(true);
         $this->db->sql_return_on_error(true);
         // Try to select one row from the first table to see if the prefix is OK
         $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
         if (!$result) {
             $prefixes = array();
             $db_tools_factory = new \phpbb\db\tools\factory();
             $db_tools = $db_tools_factory->get($src_db);
             $tables_existing = $db_tools->sql_list_tables();
             $tables_existing = array_map('strtolower', $tables_existing);
             foreach ($tables_existing as $table_name) {
                 compare_table($tables, $table_name, $prefixes);
             }
             unset($tables_existing);
             foreach ($prefixes as $prefix => $count) {
                 if ($count >= sizeof($tables)) {
                     $possible_prefix = $prefix;
                     break;
                 }
             }
             $msg = '';
             if (!empty($convertor_data['table_prefix'])) {
                 $msg .= $this->language->lang_array('DEFAULT_PREFIX_IS', array($convertor_data['forum_name'], $convertor_data['table_prefix']));
             }
             if (!empty($possible_prefix)) {
                 $msg .= '<br />';
                 $msg .= $possible_prefix == '*' ? $this->language->lang('BLANK_PREFIX_FOUND') : $this->language->lang_array('PREFIX_FOUND', array($possible_prefix));
                 $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
             }
             $error[] = $msg;
         }
         $src_db->sql_freeresult($result);
         $src_db->sql_return_on_error(false);
     }
     if (empty($error)) {
         // Save convertor Status
         $this->config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor)), false);
         $this->config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
         $this->config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
         // Save options
         $this->config->set('convert_options', serialize(array('forum_path' => $this->phpbb_root_path . $forum_path, 'refresh' => $refresh)), false);
         $url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));
         $this->iohandler->redirect($url);
         $this->iohandler->send_response(true);
     } else {
         $this->render_settings_form($error);
     }
 }
    /**
     * Get enabled extensions.
     *
     * @return array enabled extensions
     */
    protected function get_installed_extensions()
    {
        $db = $this->get_dbal_connection();
        $extension_table = $this->config_php_file->get('table_prefix') . 'ext';
        $sql = 'SELECT *
			FROM ' . $extension_table . '
			WHERE ext_active = 1';
        $result = $db->sql_query($sql);
        $rows = $db->sql_fetchrowset($result);
        $db->sql_freeresult($result);
        $exts = array();
        foreach ($rows as $row) {
            $exts[$row['ext_name']] = $this->phpbb_root_path . 'ext/' . $row['ext_name'] . '/';
        }
        return $exts;
    }