From c66e72f4685061f7490f14afd0c821d2bbb51cf3 Mon Sep 17 00:00:00 2001 From: joaocustodio Date: Mon, 7 May 2018 12:59:58 -0300 Subject: [PATCH 1/2] Fix for ID caching Rebuilds the cache every time a group or permission is added / deleted (create_perm, delete_perm, create_group, delete_group). --- application/libraries/Aauth.php | 40 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index 8417f821..239205dc 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -121,42 +121,40 @@ public function __construct() { $this->errors = $this->CI->session->flashdata('errors') ?: array(); $this->infos = $this->CI->session->flashdata('infos') ?: array(); - // Pre-Cache IDs - $this->precache_ids(); - - } - - /** - * pre_cache_ids() caches all permission and group IDs for later use. - */ - public function precache_ids() { - // Initialize Variables $this->cache_perm_id = array(); $this->cache_group_id = array(); + + // Pre-Cache IDs + $this->precache_perms(); + $this->precache_groups(); - // Permissions - + } + + /** + * precache_perms() caches all permission IDs for later use. + */ + private function precache_perms { $query = $this->aauth_db->get($this->config_vars['perms']); foreach ($query->result() as $row) { $key = str_replace(' ', '', trim(strtolower($row->name))); $this->cache_perm_id[$key] = $row->id; - } - - // Groups - + } + + /** + * precache_groups() caches all group IDs for later use. + */ + private function precache_groups { $query = $this->aauth_db->get($this->config_vars['groups']); foreach ($query->result() as $row) { $key = str_replace(' ', '', trim(strtolower($row->name))); $this->cache_group_id[$key] = $row->id; } - } - - + ######################## # Login Functions ######################## @@ -1289,6 +1287,7 @@ public function create_group($group_name, $definition = '') { 'definition'=> $definition ); $this->aauth_db->insert($this->config_vars['groups'], $data); + $this->precache_groups(); return $this->aauth_db->insert_id(); } @@ -1362,6 +1361,7 @@ public function delete_group($group_par) { return false; } else { $this->aauth_db->trans_commit(); + $this->precache_groups(); return true; } @@ -1657,6 +1657,7 @@ public function create_perm($perm_name, $definition='') { 'definition'=> $definition ); $this->aauth_db->insert($this->config_vars['perms'], $data); + $this->precache_perms(); return $this->aauth_db->insert_id(); } $this->info($this->CI->lang->line('aauth_info_perm_exists')); @@ -1716,6 +1717,7 @@ public function delete_perm($perm_par) { return false; } else { $this->aauth_db->trans_commit(); + $this->precache_perms(); return true; } From 259066cceb9d8d0118406e086a2afd0a192dd19d Mon Sep 17 00:00:00 2001 From: joaocustodio Date: Mon, 14 May 2018 12:07:05 -0300 Subject: [PATCH 2/2] Fix precache_perms() --- application/libraries/Aauth.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index 239205dc..1b73668f 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -141,6 +141,7 @@ private function precache_perms { foreach ($query->result() as $row) { $key = str_replace(' ', '', trim(strtolower($row->name))); $this->cache_perm_id[$key] = $row->id; + } } /**