Esempio 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 \phpbb\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 \phpbb\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;
            }
            foreach ($module_ids as $module_id) {
                $this->module_manager->delete_module($module_id, $class);
            }
            $this->cache->destroy("_modules_{$class}");
        }
    }