mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
commit
bf33e1cf57
3 changed files with 38 additions and 8 deletions
|
@ -56,7 +56,11 @@ class DbAclSchema extends CakeSchema {
|
||||||
'alias' => array('type' => 'string', 'null' => true),
|
'alias' => array('type' => 'string', 'null' => true),
|
||||||
'lft' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
'lft' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||||
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
'indexes' => array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
|
'idx_acos_lft_rght' => array('column' => array('lft', 'rght'), 'unique' => 0),
|
||||||
|
'idx_acos_alias' => array('column' => 'alias', 'unique' => 0)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +74,11 @@ class DbAclSchema extends CakeSchema {
|
||||||
'alias' => array('type' => 'string', 'null' => true),
|
'alias' => array('type' => 'string', 'null' => true),
|
||||||
'lft' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
'lft' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||||
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
'rght' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
'indexes' => array(
|
||||||
|
'PRIMARY' => array('column' => 'id','unique' => 1),
|
||||||
|
'idx_aros_lft_rght' => array('column' => array('lft', 'rght'), 'unique' => 0),
|
||||||
|
'idx_aros_alias' => array('column' => 'alias', 'unique' => 0)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +93,11 @@ class DbAclSchema extends CakeSchema {
|
||||||
'_read' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
'_read' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||||
'_update' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
'_update' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||||
'_delete' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
'_delete' => array('type' => 'string', 'null' => false, 'default' => '0', 'length' => 2),
|
||||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'ARO_ACO_KEY' => array('column' => array('aro_id', 'aco_id'), 'unique' => 1))
|
'indexes' => array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
|
'ARO_ACO_KEY' => array('column' => array('aro_id', 'aco_id'), 'unique' => 1),
|
||||||
|
'idx_aco_id' => array('column' => 'aco_id', 'unique' => 0)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,3 +39,14 @@ CREATE TABLE aros (
|
||||||
rght INTEGER(10) DEFAULT NULL,
|
rght INTEGER(10) DEFAULT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* this indexes will improve acl perfomance */
|
||||||
|
CREATE INDEX idx_acos_lft_rght ON `acos` (`lft`, `rhgt`);
|
||||||
|
|
||||||
|
CREATE INDEX idx_acos_alias ON `acos` (`alias`);
|
||||||
|
|
||||||
|
CREATE INDEX idx_aros_lft_rght ON `aros` (`lft`, `rhgt`);
|
||||||
|
|
||||||
|
CREATE INDEX idx_aros_alias ON `aros` (`alias`);
|
||||||
|
|
||||||
|
CREATE INDEX idx_aco_id ON `aros_acos` (`aco_id`);
|
|
@ -90,6 +90,8 @@ class AclNode extends Model {
|
||||||
'order' => $db->name("{$type}.lft") . ' DESC'
|
'order' => $db->name("{$type}.lft") . ' DESC'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$conditionsAfterJoin = array();
|
||||||
|
|
||||||
foreach ($path as $i => $alias) {
|
foreach ($path as $i => $alias) {
|
||||||
$j = $i - 1;
|
$j = $i - 1;
|
||||||
|
|
||||||
|
@ -98,18 +100,23 @@ class AclNode extends Model {
|
||||||
'alias' => "{$type}{$i}",
|
'alias' => "{$type}{$i}",
|
||||||
'type' => 'INNER',
|
'type' => 'INNER',
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
|
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string')
|
||||||
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
|
|
||||||
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string'),
|
|
||||||
$db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id")
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// it will be better if this conditions will performs after join operation
|
||||||
|
$conditionsAfterJoin[] = $db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id");
|
||||||
|
$conditionsAfterJoin[] = $db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght");
|
||||||
|
$conditionsAfterJoin[] = $db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft");
|
||||||
|
|
||||||
$queryData['conditions'] = array('or' => array(
|
$queryData['conditions'] = array('or' => array(
|
||||||
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
|
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
|
||||||
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght"))
|
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$queryData['conditions'] = array_merge($queryData['conditions'], $conditionsAfterJoin);
|
||||||
|
|
||||||
$result = $db->read($this, $queryData, -1);
|
$result = $db->read($this, $queryData, -1);
|
||||||
$path = array_values($path);
|
$path = array_values($path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue