mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Optimizing ACL node querying
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4517 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b45f8984f8
commit
c78b777db7
5 changed files with 30 additions and 27 deletions
|
@ -71,19 +71,21 @@ class DB_ACL extends AclBase {
|
|||
}
|
||||
|
||||
$permKeys = $this->_getAcoKeys($Perms->loadInfo());
|
||||
$aroNode = $Aro->node($aro);
|
||||
$acoNode = $Aco->node($aco);
|
||||
$aroPath = $Aro->node($aro);
|
||||
$acoPath = new Set($Aco->node($aco));
|
||||
|
||||
if (empty($aroNode) || empty($acoNode)) {
|
||||
if (empty($aroPath) || empty($acoPath)) {
|
||||
trigger_error("DB_ACL::check() - Attempted to check permissions on/with a node that does not exist. Node references:\nAro: " . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
$aroPath = $Aro->getPath($aroNode['id']);
|
||||
$acoPath = new Set($Aco->getPath($acoNode['id']));
|
||||
|
||||
if ($acoPath->get() == null || $acoPath->get() == array()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$aroNode = $aroPath[0];
|
||||
$acoNode = $acoPath->get();
|
||||
$acoNode = $acoNode[0];
|
||||
|
||||
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
|
||||
trigger_error(sprintf(__("ACO permissions key %s does not exist in DB_ACL::check()", true), $action), E_USER_NOTICE);
|
||||
return false;
|
||||
|
|
|
@ -71,7 +71,9 @@ class AclNode extends AppModel {
|
|||
$start = $path[count($path) - 1];
|
||||
unset($path[count($path) - 1]);
|
||||
|
||||
$query = "SELECT {$type}0.* From {$prefix}{$table} AS {$type}0 ";
|
||||
$query = "SELECT {$type}.* From {$prefix}{$table} AS {$type} ";
|
||||
$query .= "LEFT JOIN {$prefix}{$table} AS {$type}0 ";
|
||||
$query .= "ON {$type}0.alias = " . $db->value($start) . " ";
|
||||
foreach ($path as $i => $alias) {
|
||||
$j = $i - 1;
|
||||
$k = $i + 1;
|
||||
|
@ -79,11 +81,7 @@ class AclNode extends AppModel {
|
|||
$query .= "ON {$type}{$k}.lft > {$type}{$i}.lft && {$type}{$k}.rght < {$type}{$i}.rght ";
|
||||
$query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " ";
|
||||
}
|
||||
$result = $this->query("{$query} WHERE {$type}0.alias = " . $db->value($start));
|
||||
|
||||
if (!empty($result)) {
|
||||
$result = $result[0]["{$type}0"];
|
||||
}
|
||||
$result = $this->query("{$query} WHERE {$type}.lft <= {$type}0.lft AND {$type}.rght >= {$type}0.rght ORDER BY {$type}.lft DESC");
|
||||
} elseif (is_object($ref) && is_a($ref, 'Model')) {
|
||||
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
|
||||
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
|
||||
|
@ -111,9 +109,19 @@ class AclNode extends AppModel {
|
|||
}
|
||||
}
|
||||
if (is_array($ref)) {
|
||||
$result = $this->find($ref, null, null, -1);
|
||||
if ($result) {
|
||||
list($result) = array_values($result);
|
||||
foreach ($ref as $key => $val) {
|
||||
if (strpos($key, $type) !== 0) {
|
||||
unset($ref[$key]);
|
||||
$ref["{$type}0.{$key}"] = $val;
|
||||
}
|
||||
}
|
||||
$query = "SELECT {$type}.* From {$prefix}{$table} AS {$type} ";
|
||||
$query .= "LEFT JOIN {$prefix}{$table} AS {$type}0 ";
|
||||
$query .= "ON {$type}.lft <= {$type}0.lft AND {$type}.rght >= {$type}0.rght ";
|
||||
$result = $this->query("{$query} " . $db->conditions($ref) ." ORDER BY {$type}.lft DESC");
|
||||
|
||||
if (!$result) {
|
||||
trigger_error("AclNode::node() - Couldn't find {$type} node identified by \"" . print_r($ref, true) . "\"", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
|
|
@ -97,15 +97,9 @@ class AclBehavior extends ModelBehavior {
|
|||
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
||||
$parent = $this->node($model, $model->parentNode());
|
||||
|
||||
if(isset($parent['id'])) {
|
||||
$parent = $parent['id'];
|
||||
} else {
|
||||
$parent = null;
|
||||
}
|
||||
|
||||
$model->{$type}->create();
|
||||
$model->{$type}->save(array(
|
||||
'parent_id' => $parent,
|
||||
'parent_id' => Set::extract($parent, "0.{$type}.id"),
|
||||
'model' => $model->name,
|
||||
'foreign_key' => $model->id
|
||||
));
|
||||
|
@ -117,9 +111,11 @@ class AclBehavior extends ModelBehavior {
|
|||
* @return void
|
||||
*/
|
||||
function afterDelete(&$model) {
|
||||
$node = $this->node($model);
|
||||
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])];
|
||||
$model->{$type}->delete($node['id']);
|
||||
$node = Set::extract($this->node($model), "0.{$type}.id");
|
||||
if (!empty($node)) {
|
||||
$model->{$type}->delete($node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ class TreeBehavior extends ModelBehavior {
|
|||
}*/
|
||||
$this->settings[$model->name] = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent of the given node
|
||||
*
|
||||
|
|
|
@ -1096,7 +1096,6 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($joined)) {
|
||||
$this->__saveMulti($joined, $this->id);
|
||||
}
|
||||
|
@ -1158,7 +1157,6 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total = count($joinTable);
|
||||
|
||||
if(is_array($newValue)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue