Skip to content

Commit 7ae5ef5

Browse files
korllanREJack
authored andcommitted
Fix for ID caching (#230)
* Fix for ID caching Rebuilds the cache every time a group or permission is added / deleted (create_perm, delete_perm, create_group, delete_group). * Fix precache_perms()
1 parent 1ceb28d commit 7ae5ef5

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

application/libraries/Aauth.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,42 +121,41 @@ public function __construct() {
121121
$this->errors = $this->CI->session->flashdata('errors') ?: array();
122122
$this->infos = $this->CI->session->flashdata('infos') ?: array();
123123

124-
// Pre-Cache IDs
125-
$this->precache_ids();
126-
127-
}
128-
129-
/**
130-
* pre_cache_ids() caches all permission and group IDs for later use.
131-
*/
132-
public function precache_ids() {
133-
134124
// Initialize Variables
135125

136126
$this->cache_perm_id = array();
137127
$this->cache_group_id = array();
128+
129+
// Pre-Cache IDs
130+
$this->precache_perms();
131+
$this->precache_groups();
138132

139-
// Permissions
140-
133+
}
134+
135+
/**
136+
* precache_perms() caches all permission IDs for later use.
137+
*/
138+
private function precache_perms {
141139
$query = $this->aauth_db->get($this->config_vars['perms']);
142140

143141
foreach ($query->result() as $row) {
144142
$key = str_replace(' ', '', trim(strtolower($row->name)));
145143
$this->cache_perm_id[$key] = $row->id;
146144
}
147-
148-
// Groups
149-
145+
}
146+
147+
/**
148+
* precache_groups() caches all group IDs for later use.
149+
*/
150+
private function precache_groups {
150151
$query = $this->aauth_db->get($this->config_vars['groups']);
151152

152153
foreach ($query->result() as $row) {
153154
$key = str_replace(' ', '', trim(strtolower($row->name)));
154155
$this->cache_group_id[$key] = $row->id;
155156
}
156-
157157
}
158-
159-
158+
160159
########################
161160
# Login Functions
162161
########################
@@ -1289,6 +1288,7 @@ public function create_group($group_name, $definition = '') {
12891288
'definition'=> $definition
12901289
);
12911290
$this->aauth_db->insert($this->config_vars['groups'], $data);
1291+
$this->precache_groups();
12921292
return $this->aauth_db->insert_id();
12931293
}
12941294

@@ -1362,6 +1362,7 @@ public function delete_group($group_par) {
13621362
return false;
13631363
} else {
13641364
$this->aauth_db->trans_commit();
1365+
$this->precache_groups();
13651366
return true;
13661367
}
13671368

@@ -1657,6 +1658,7 @@ public function create_perm($perm_name, $definition='') {
16571658
'definition'=> $definition
16581659
);
16591660
$this->aauth_db->insert($this->config_vars['perms'], $data);
1661+
$this->precache_perms();
16601662
return $this->aauth_db->insert_id();
16611663
}
16621664
$this->info($this->CI->lang->line('aauth_info_perm_exists'));
@@ -1716,6 +1718,7 @@ public function delete_perm($perm_par) {
17161718
return false;
17171719
} else {
17181720
$this->aauth_db->trans_commit();
1721+
$this->precache_perms();
17191722
return true;
17201723
}
17211724

0 commit comments

Comments
 (0)