acp_modules::delete_module PHP Method

delete_module() public method

Remove module from tree
public delete_module ( $module_id )
    function delete_module($module_id)
    {
        global $db, $user, $phpbb_log;
        $row = $this->get_module_row($module_id);
        $branch = $this->get_module_branch($module_id, 'children', 'descending', false);
        if (sizeof($branch)) {
            return array($user->lang['CANNOT_REMOVE_MODULE']);
        }
        // If not move
        $diff = 2;
        $sql = 'DELETE FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND module_id = {$module_id}";
        $db->sql_query($sql);
        $row['right_id'] = (int) $row['right_id'];
        $row['left_id'] = (int) $row['left_id'];
        // Resync tree
        $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\tSET right_id = right_id - {$diff}\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND left_id < {$row['right_id']} AND right_id > {$row['right_id']}";
        $db->sql_query($sql);
        $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND left_id > {$row['right_id']}";
        $db->sql_query($sql);
        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_REMOVED', false, array($this->lang_name($row['module_langname'])));
        return array();
    }

Usage Example

Exemplo n.º 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}");
        }
    }
All Usage Examples Of acp_modules::delete_module