diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2022-01-21 13:09:26 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2022-01-21 13:09:26 +0000 |
| commit | 4df9f170f16d60edc7437c9161c8668dc229b033 (patch) | |
| tree | 1009cffc08fd5ad331328e1bb91b8c40a579debb /lib/plugins | |
| parent | 88a5f717f90e0e2c31599d159144559ae5be795e (diff) | |
fixes #237
Diffstat (limited to 'lib/plugins')
| -rw-r--r-- | lib/plugins/db/RolePersistence.class.php | 47 | ||||
| -rw-r--r-- | lib/plugins/engine/PluginManager.class.php | 17 |
2 files changed, 21 insertions, 43 deletions
diff --git a/lib/plugins/db/RolePersistence.class.php b/lib/plugins/db/RolePersistence.class.php index 358e8f1..a66b9a0 100644 --- a/lib/plugins/db/RolePersistence.class.php +++ b/lib/plugins/db/RolePersistence.class.php @@ -13,32 +13,36 @@ */ class RolePersistence { + const ROLES_CACHE_KEY = 'plugins/rolepersistence/roles'; + /** * Returns all available roles. * * @return array Roles */ - public static function getAllRoles() + public static function getAllRoles(): array { // read cache - $cache = self::getRolesCache(); + $cache = StudipCacheFactory::getCache(); // cache miss, retrieve from database - if (count($cache) === 0) { + $roles = $cache->read(self::ROLES_CACHE_KEY); + if (!$roles) { $query = "SELECT `roleid`, `rolename`, `system` = 'y' AS `is_system` FROM `roles` ORDER BY `rolename`"; $statement = DBManager::get()->query($query); $statement->setFetchMode(PDO::FETCH_ASSOC); + $roles = []; foreach ($statement as $row) { - extract($row); - - $cache[$roleid] = new Role($roleid, $rolename, $is_system); + $roles[$row['roleid']] = new Role($row['roleid'], $row['rolename'], $row['is_system']); } + + $cache->write(self::ROLES_CACHE_KEY, $roles); } - return $cache->getArrayCopy(); + return $roles; } public static function getRoleIdByName($name) @@ -55,7 +59,7 @@ class RolePersistence * Inserts the role into the database or does an update, if it's already there * * @param Role $role - * @return the role id + * @return int the role id */ public static function saveRole($role) { @@ -469,28 +473,13 @@ class RolePersistence } // Cache operations - private static $roles_cache = null; private static $user_roles_cache = null; private static $plugin_roles_cache = null; - private static function getRolesCache() - { - if (self::$roles_cache === null) { - self::$roles_cache = new StudipCachedArray( - '/Roles', - function () { - return 'All'; - }, - StudipCachedArray::ENCODE_SERIALIZE - ); - } - return self::$roles_cache; - } - private static function getUserRolesCache() { if (self::$user_roles_cache === null) { - self::$user_roles_cache = new StudipCachedArray('/UserRoles'); + self::$user_roles_cache = new StudipCachedArray('UserRoles'); } return self::$user_roles_cache; } @@ -498,20 +487,18 @@ class RolePersistence private static function getPluginRolesCache() { if (self::$plugin_roles_cache === null) { - self::$plugin_roles_cache = new StudipCachedArray('/PluginRoles'); + self::$plugin_roles_cache = new StudipCachedArray('PluginRoles'); } return self::$plugin_roles_cache; } - public static function expireCaches() + public static function expireRolesCache() { - self::getRolesCache()->clear(); - self::getUserRolesCache()->clear(); - self::getPluginRolesCache()->clear(); + StudipCacheFactory::getCache()->expire(self::ROLES_CACHE_KEY); } public static function expireUserCache($user_id) { unset(self::getUserRolesCache()[$user_id]); } -}
\ No newline at end of file +} diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.class.php index 5f67c40..b7ecb0d 100644 --- a/lib/plugins/engine/PluginManager.class.php +++ b/lib/plugins/engine/PluginManager.class.php @@ -29,11 +29,6 @@ class PluginManager private $plugins_activated_cache; /** - * cache of plugin default activations - */ - private $plugins_default_activations_cache; - - /** * Returns the PluginManager singleton instance. */ public static function getInstance () @@ -56,7 +51,6 @@ class PluginManager $this->plugin_cache = []; $this->plugins_activated_cache = new StudipCachedArray('/PluginActivations'); - $this->plugins_default_activations_cache = new StudipCachedArray('/PluginDefaultActivations'); } /** @@ -324,8 +318,8 @@ class PluginManager * Set the list of institutes for which a specific plugin should * be enabled by default. * - * @param $id id of the plugin - * @param $institutes array of institute ids + * @param int $id id of the plugin + * @param array $institutes array of institute ids */ public function setDefaultActivations ($id, $institutes) { @@ -339,8 +333,6 @@ class PluginManager foreach ($institutes as $instid) { $stmt->execute([$id, $instid]); } - - $this->plugins_default_activations_cache->clear(); } /** @@ -493,7 +485,7 @@ class PluginManager /** * Remove registration for the given plugin from the data base. * - * @param $id id of the plugin + * @param int $id id of the plugin */ public function unregisterPlugin ($id) { @@ -509,8 +501,7 @@ class PluginManager unset($this->plugins[$id]); - $this->plugins_default_activations_cache->clear(); - $this->plugins_activated_cache->clear(); + unset($this->plugins_activated_cache[$id]); } } |
