Example #1
0
 /**
  * Wrapper for \acp_modules::get_module_infos()
  *
  * @param string $class Module Class
  * @param string $basename Module Basename
  * @return array Module Information
  * @throws \phpbb\db\migration\exception
  */
 protected function get_module_info($class, $basename)
 {
     $module = $this->module_manager->get_module_infos($class, $basename, true);
     if (empty($module)) {
         throw new \phpbb\db\migration\exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename);
     }
     return array_pop($module);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $module_classes = array('acp', 'mcp', 'ucp');
     $total = sizeof($module_classes);
     $i = $this->config->get('module_class_index', 0);
     $module_classes = array_slice($module_classes, $i);
     foreach ($module_classes as $module_class) {
         $categories = $this->config->get('module_categories_array', array());
         $k = $this->config->get('module_categories_index', 0);
         $module_categories = array_slice($this->module_categories[$module_class], $k);
         $timed_out = false;
         foreach ($module_categories 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'];
                 }
             }
             $k++;
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 $timed_out = true;
                 break;
             }
         }
         $this->config->set('module_categories_array', $categories);
         $this->config->set('module_categories_index', $k);
         if ($timed_out) {
             throw new resource_limit_reached_exception();
         }
         // Get the modules we want to add... returned sorted by name
         $module_info = $this->module_manager->get_module_infos($module_class);
         $k = $this->config->get('module_info_index', 0);
         $module_info = array_slice($module_info, $k);
         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']);
                     }
                 }
             }
             $k++;
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 $timed_out = true;
                 break;
             }
         }
         $this->config->set('module_info_index', $k);
         // Stop execution if resource limit is reached
         if ($timed_out) {
             throw new resource_limit_reached_exception();
         }
         // Move some of the modules around since the code above will put them in the wrong place
         if (!$this->config->get('modules_ordered', false)) {
             $this->order_modules($module_class);
             $this->config->set('modules_ordered', true);
             // Stop execution if resource limit is reached
             if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
                 throw new resource_limit_reached_exception();
             }
         }
         // 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])) {
             $this->add_module_extras($module_class);
         }
         $this->module_manager->remove_cache_file($module_class);
         $i++;
         $this->config->set('module_class_index', $i);
         $this->config->set('module_categories_index', 0);
         $this->config->set('module_info_index', 0);
         $this->config->set('added_extra_modules', false);
         $this->config->set('modules_ordered', false);
         $this->config->set('module_categories_array', array());
         // Stop execution if resource limit is reached
         if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         throw new resource_limit_reached_exception();
     }
 }
Example #3
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);
        }
    }