mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring ACL and tree code for query optimization changes
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4521 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
6989f80376
commit
64bbd74c85
5 changed files with 21 additions and 10 deletions
|
@ -270,11 +270,11 @@ class DB_ACL extends AclBase {
|
|||
}
|
||||
|
||||
return array(
|
||||
'aro' => $obj['Aro']['id'],
|
||||
'aco' => $obj['Aco']['id'],
|
||||
'aro' => Set::extract($obj, 'Aro.0.Aro.id'),
|
||||
'aco' => Set::extract($obj, 'Aco.0.Aco.id'),
|
||||
'link' => $Link->findAll(array(
|
||||
'Permission.aro_id' => $obj['Aro']['id'],
|
||||
'Permission.aco_id' => $obj['Aco']['id']
|
||||
'Permission.aro_id' => Set::extract($obj, 'Aro.0.Aro.id'),
|
||||
'Permission.aco_id' => Set::extract($obj, 'Aco.0.Aco.id')
|
||||
))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ class AclNode extends AppModel {
|
|||
$result = $this->query("{$query} " . $db->conditions($ref) ." ORDER BY {$type}.lft DESC");
|
||||
|
||||
if (!$result) {
|
||||
pr($this->trace());
|
||||
trigger_error("AclNode::node() - Couldn't find {$type} node identified by \"" . print_r($ref, true) . "\"", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,12 @@ class AclBehavior extends ModelBehavior {
|
|||
function afterSave(&$model, $created) {
|
||||
if ($created) {
|
||||
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
||||
$parent = $this->node($model, $model->parentNode());
|
||||
$parent = $model->parentNode();
|
||||
if (!empty($parent)) {
|
||||
$parent = $this->node($model, $parent);
|
||||
} else {
|
||||
$parent = null;
|
||||
}
|
||||
|
||||
$model->{$type}->create();
|
||||
$model->{$type}->save(array(
|
||||
|
|
|
@ -61,6 +61,9 @@ class TreeBehavior extends ModelBehavior {
|
|||
*/
|
||||
function setparent(&$model, $parent_id = null) {
|
||||
extract($this->settings[$model->name]);
|
||||
if ($parent_id == $model->field($parent)) {
|
||||
return true;
|
||||
}
|
||||
list($node) = array_values($model->find(array($model->escapeField() => $model->id), array($model->primaryKey, $parent, $left, $right), null, -1));
|
||||
list($edge) = array_values($model->find(null, "MAX({$right}) AS {$right}", null, -1));
|
||||
$edge = ife(empty($edge[$right]), 0, $edge[$right]); // Is the tree empty?
|
||||
|
|
|
@ -154,12 +154,14 @@ class DboMysql extends DboSource {
|
|||
if (empty($tables)) {
|
||||
$result = $this->query('SHOW TABLES');
|
||||
$key1 = $key2 = null;
|
||||
foreach ($result as $item) {
|
||||
if (empty($key1)) {
|
||||
$key1 = key($item);
|
||||
$key2 = key($item[$key1]);
|
||||
if ($result) {
|
||||
foreach ($result as $item) {
|
||||
if (empty($key1)) {
|
||||
$key1 = key($item);
|
||||
$key2 = key($item[$key1]);
|
||||
}
|
||||
$tables[] = $item[$key1][$key2];
|
||||
}
|
||||
$tables[] = $item[$key1][$key2];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue