Ejemplo n.º 1
0
    /**
     * Permission Remove
     *
     * Remove a permission (auth) option
     *
     * @param string $auth_option The name of the permission (auth) option
     * @param bool $global True for checking a global permission setting,
     * 	False for a local permission setting
     * @return null
     */
    public function remove($auth_option, $global = true)
    {
        if (!$this->exists($auth_option, $global)) {
            return;
        }
        if ($global) {
            $type_sql = ' AND is_global = 1';
        } else {
            $type_sql = ' AND is_local = 1';
        }
        $sql = 'SELECT auth_option_id, is_global, is_local
			FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\tWHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . $type_sql;
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        $id = (int) $row['auth_option_id'];
        // If it is a local and global permission, do not remove the row! :P
        if ($row['is_global'] && $row['is_local']) {
            $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
				SET ' . ($global ? 'is_global = 0' : 'is_local = 0') . '
				WHERE auth_option_id = ' . $id;
            $this->db->sql_query($sql);
        } else {
            // Delete time
            $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE);
            foreach ($tables as $table) {
                $this->db->sql_query('DELETE FROM ' . $table . '
					WHERE auth_option_id = ' . $id);
            }
        }
        // Purge the auth cache
        $this->cache->destroy('_acl_options');
        $this->auth->acl_clear_prefetch();
    }
Ejemplo n.º 2
0
    /**
     * Purge all notifications of a certain type
     *
     * This should be called when an extension which has notification types
     * is purged so that all those notifications are removed
     *
     * @param string $notification_type_name Type identifier of the subscription
     */
    public function purge_notifications($notification_type_name)
    {
        // If a notification is never used, its type will not be added to the database
        // nor its id cached. If this method is called by an extension during the
        // purge step, and that extension never used its notifications,
        // get_notification_type_id() will throw an exception. However,
        // because no notification type was added to the database,
        // there is nothing to delete, so we can silently drop the exception.
        try {
            $notification_type_id = $this->get_notification_type_id($notification_type_name);
            $sql = 'DELETE FROM ' . $this->notifications_table . '
				WHERE notification_type_id = ' . (int) $notification_type_id;
            $this->db->sql_query($sql);
            $sql = 'DELETE FROM ' . $this->notification_types_table . '
				WHERE notification_type_id = ' . (int) $notification_type_id;
            $this->db->sql_query($sql);
            $this->cache->destroy('notification_type_ids');
        } catch (\src\notification\exception $e) {
            // Continue
        }
    }
Ejemplo n.º 3
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}");
        }
    }