delete_module() public method

Remove module from tree
public delete_module ( $module_id )
Example #1
0
    /**
     * Module Remove
     *
     * Remove a module
     *
     * @param string $class The module class(acp|mcp|ucp)
     * @param int|string|bool $parent The parent module_id|module_langname(0 for no parent).
     * 	Use false to ignore the parent check and check class wide.
     * @param int|string $module The module id|module_langname
     * 	specify that here
     * @return null
     * @throws \src\db\migration\exception
     */
    public function remove($class, $parent = 0, $module = '')
    {
        // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto
        if (is_array($module)) {
            if (isset($module['module_langname'])) {
                // Manual Method
                return $this->remove($class, $parent, $module['module_langname']);
            }
            // Failed.
            if (!isset($module['module_basename'])) {
                throw new \src\db\migration\exception('MODULE_NOT_EXIST');
            }
            // Automatic method
            $basename = $module['module_basename'];
            $module_info = $this->get_module_info($class, $basename);
            foreach ($module_info['modes'] as $mode => $info) {
                if (!isset($module['modes']) || in_array($mode, $module['modes'])) {
                    $this->remove($class, $parent, $info['title']);
                }
            }
        } else {
            if (!$this->exists($class, $parent, $module)) {
                return;
            }
            $parent_sql = '';
            if ($parent !== false) {
                // Allows '' to be sent as 0
                $parent = $parent ?: 0;
                if (!is_numeric($parent)) {
                    $sql = 'SELECT module_id
						FROM ' . $this->modules_table . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'";
                    $result = $this->db->sql_query($sql);
                    $module_id = $this->db->sql_fetchfield('module_id');
                    $this->db->sql_freeresult($result);
                    // we know it exists from the module_exists check
                    $parent_sql = 'AND parent_id = ' . (int) $module_id;
                } else {
                    $parent_sql = 'AND parent_id = ' . (int) $parent;
                }
            }
            $module_ids = array();
            if (!is_numeric($module)) {
                $sql = 'SELECT module_id
					FROM ' . $this->modules_table . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($module) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'\n\t\t\t\t\t\t{$parent_sql}";
                $result = $this->db->sql_query($sql);
                while ($module_id = $this->db->sql_fetchfield('module_id')) {
                    $module_ids[] = (int) $module_id;
                }
                $this->db->sql_freeresult($result);
            } else {
                $module_ids[] = (int) $module;
            }
            if (!class_exists('acp_modules')) {
                include $this->src_root_path . 'includes/acp/acp_modules.' . $this->php_ext;
                $this->user->add_lang('acp/modules');
            }
            $acp_modules = new \acp_modules();
            $acp_modules->module_class = $class;
            foreach ($module_ids as $module_id) {
                $result = $acp_modules->delete_module($module_id);
                if (!empty($result)) {
                    return;
                }
            }
            $this->cache->destroy("_modules_{$class}");
        }
    }
Example #2
0
 /**
  * Module Remove
  *
  * Remove a module
  *
  * @param string $class The module class(acp|mcp|ucp)
  * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent).  Use false to ignore the parent check and check class wide.
  * @param int|string $module The module id|module_langname
  * @param string|bool $include_path If you would like to use a custom include path, specify that here
  */
 function module_remove($class, $parent = 0, $module = '', $include_path = false)
 {
     global $cache, $user, $phpbb_root_path, $phpEx;
     // Multicall
     if (is_array($class)) {
         foreach ($class as $params) {
             call_user_func_array(array($this, 'module_remove'), $params);
         }
         return;
     }
     // Allows '' to be sent
     $parent = !$parent ? 0 : $parent;
     // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto
     if (is_array($module)) {
         if (isset($module['module_langname'])) {
             // Manual Method
             return $this->module_remove($class, $parent, $module['module_langname'], $include_path);
         }
         // Failed.
         if (!isset($module['module_basename'])) {
             $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN');
             return $this->umil_end('FAIL');
         }
         // Automatic method
         $basename = str_replace(array('/', '\\'), '', $module['module_basename']);
         $class = str_replace(array('/', '\\'), '', $class);
         $info_file = "{$class}/info/{$class}_{$basename}.{$phpEx}";
         if (!file_exists(($include_path === false ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) {
             $this->umil_start('MODULE_REMOVE', $class, $info_file);
             return $this->umil_end('FAIL');
         }
         $classname = "{$class}_{$basename}_info";
         if (!class_exists($classname)) {
             include ($include_path === false ? $phpbb_root_path . 'includes/' : $include_path) . $info_file;
         }
         $info = new $classname();
         $module_info = $info->module();
         unset($info);
         $result = '';
         foreach ($module_info['modes'] as $mode => $info) {
             if (!isset($module['modes']) || in_array($mode, $module['modes'])) {
                 $result .= $this->module_remove($class, $parent, $info['title']) . '<br />';
             }
         }
         return $result;
     } else {
         $class = $this->db->sql_escape($class);
         if (!$this->module_exists($class, $parent, $module)) {
             $this->umil_start('MODULE_REMOVE', $class, isset($user->lang[$module]) ? $user->lang[$module] : $module);
             return $this->umil_end('MODULE_NOT_EXIST');
         }
         $parent_sql = '';
         if ($parent !== false) {
             if (!is_numeric($parent)) {
                 $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\tAND module_class = '{$class}'";
                 $result = $this->db->sql_query($sql);
                 $row = $this->db->sql_fetchrow($result);
                 $this->db->sql_freeresult($result);
                 // we know it exists from the module_exists check
                 $parent_sql = 'AND parent_id = ' . (int) $row['module_id'];
             } else {
                 $parent_sql = 'AND parent_id = ' . (int) $parent;
             }
         }
         $module_ids = array();
         if (!is_numeric($module)) {
             $module = $this->db->sql_escape($module);
             $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = '{$module}'\n\t\t\t\t\tAND module_class = '{$class}'\n\t\t\t\t\t{$parent_sql}";
             $result = $this->db->sql_query($sql);
             while ($row = $this->db->sql_fetchrow($result)) {
                 $module_ids[] = (int) $row['module_id'];
             }
             $this->db->sql_freeresult($result);
             $module_name = $module;
         } else {
             $module = (int) $module;
             $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_id = {$module}\n\t\t\t\t\tAND module_class = '{$class}'\n\t\t\t\t\t{$parent_sql}";
             $result = $this->db->sql_query($sql);
             $row = $this->db->sql_fetchrow($result);
             $this->db->sql_freeresult($result);
             $module_name = $row['module_langname'];
             $module_ids[] = $module;
         }
         $this->umil_start('MODULE_REMOVE', $class, isset($user->lang[$module_name]) ? $user->lang[$module_name] : $module_name);
         add_log('admin', 'LOG_MODULE_REMOVED', isset($user->lang[$module_name]) ? $user->lang[$module_name] : $module_name);
         if (!class_exists('acp_modules')) {
             include $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx;
             $user->add_lang('acp/modules');
         }
         $acp_modules = new acp_modules();
         $acp_modules->module_class = $class;
         foreach ($module_ids as $module_id) {
             $result = $acp_modules->delete_module($module_id);
             if (!empty($result)) {
                 if ($this->result == (isset($user->lang['SUCCESS']) ? $user->lang['SUCCESS'] : 'SUCCESS')) {
                     $this->result = implode('<br />', $result);
                 } else {
                     $this->result .= '<br />' . implode('<br />', $result);
                 }
             }
         }
         $cache->destroy("_modules_{$class}");
         return $this->umil_end();
     }
 }
 /**
  * remove_modules
  */
 function remove_modules($mode, $sub)
 {
     global $db, $user, $phpbb_root_path, $phpEx;
     if (!class_exists('acp_modules')) {
         require $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx;
     }
     $_module = new acp_modules();
     // Set the module class
     $module_classes = array_keys($this->module_categories);
     $_module->u_action = "phpbb_seo_install.{$phpEx}";
     $cat_module_data = array();
     $module_data = array();
     $delete_module_data = array();
     foreach ($module_classes as $module_class) {
         $_module->module_class = $module_class;
         foreach ($this->module_categories[$module_class] as $cat_name => $subs) {
             // If the cat is already uninstalled break for now
             if ($this->get_module_id($cat_name) < 1) {
                 $url_mod = !empty($this->sub) ? '?mode=' . $this->mode : '';
                 $this->p_master->error(sprintf($user->lang['SEO_ERROR_UNINSTALLED'], $user->lang[$cat_name]) . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->p_master->module_url . $url_mod . '">', '</a>'), '', '', false, $user->lang['SEO_ERROR_INFO']);
             }
             $cat_module_data[$cat_name] = array('module_id' => $this->check_module_id($cat_name), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => '');
             if (is_array($subs)) {
                 foreach ($subs as $sub_cat) {
                     $sub_cat_module_data[$sub_cat] = array('module_id' => $this->check_module_id($sub_cat), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $cat_module_data[$cat_name]['module_id'], 'module_class' => $module_class, 'module_langname' => $sub_cat, 'module_mode' => '', 'module_auth' => '');
                     $branch = $_module->get_module_branch($sub_cat_module_data[$sub_cat]['module_id'], 'children', 'descending', false);
                     if (sizeof($branch)) {
                         foreach ($branch as $module) {
                             $error = $_module->delete_module($module['module_id']);
                             if (!sizeof($error)) {
                                 $_module->remove_cache_file();
                                 $delete_module_data[$module['module_id']] = $module['module_langname'] . ' - id : ' . $module['module_id'];
                             } else {
                                 $this->errors[] = implode(' ', $error);
                             }
                         }
                         // End modules
                     }
                     if (!sizeof($this->errors)) {
                         $error = $_module->delete_module($sub_cat_module_data[$sub_cat]['module_id']);
                         if (!sizeof($error)) {
                             $_module->remove_cache_file();
                             $delete_module_data[$sub_cat_module_data[$sub_cat]['module_id']] = $sub_cat_module_data[$sub_cat]['module_langname'] . ' - id : ' . $sub_cat_module_data[$sub_cat]['module_id'];
                         } else {
                             $this->errors[] = implode(' ', $error);
                         }
                     }
                 }
             }
             // End sub categories
             if (!sizeof($this->errors)) {
                 $branch = $_module->get_module_branch($cat_module_data[$cat_name]['module_id'], 'children', 'descending', false);
                 if (empty($branch)) {
                     $error = $_module->delete_module($cat_module_data[$cat_name]['module_id']);
                 }
                 if (!sizeof($error)) {
                     $_module->remove_cache_file();
                     $delete_module_data[$cat_module_data[$cat_name]['module_id']] = $cat_module_data[$cat_name]['module_langname'] . ' - id : ' . $cat_module_data[$cat_name]['module_id'];
                 } else {
                     $this->errors[] = implode(' ', $error);
                 }
             }
         }
         // End categories
     }
     // End classes
     return;
 }
function remove_module($module_id, $module_class)
{
    global $user;
    $modules = new acp_modules();
    $modules->module_class = $module_class;
    $failed = $modules->delete_module($module_id);
}
Example #5
0
 function remove_modules()
 {
     $modules_to_delete = array('ACP_WPU_CATOTHER' => array('ACP_WPU_UNINSTALL', 'ACP_WPU_RESET', 'ACP_WPU_DEBUG'), 'ACP_WPU_CATSUPPORT' => array('ACP_WPU_DONATE'), 'ACP_WPU_CATMANAGE' => array('ACP_WPU_USERMAP', 'ACP_WPU_PERMISSIONS'), 'ACP_WPU_CATSETUP' => array('ACP_WPU_DETAILED', 'ACP_WPU_WIZARD'), 'ACP_WPU_CATMAIN' => array('ACP_WPU_MAINTITLE'));
     $cats = array('ACP_WPU_CATOTHER', 'ACP_WPU_CATSUPPORT', 'ACP_WPU_CATMANAGE', 'ACP_WPU_CATSETUP', 'ACP_WPU_CATMAIN');
     $acp_modules = new acp_modules();
     $acp_modules->module_class = 'acp';
     $mainTab = $this->module_exists('ACP_WP_UNITED', 0);
     if ($mainTab) {
         //remove modules
         foreach ($modules_to_delete as $cat => $modules) {
             if ($parent = $this->module_exists($cat, $mainTab)) {
                 foreach ($modules as $module) {
                     if ($id = $this->module_exists($module, $parent)) {
                         $errors .= $acp_modules->delete_module($id);
                     }
                 }
                 //remove cat
                 $errors .= $acp_modules->delete_module($parent);
             }
         }
         //remove main tab
         $acp_modules->delete_module($mainTab);
     }
     $acp_modules->remove_cache_file();
     return $errors;
 }