Changeset 172 for trunk/lib/ACL.inc.php
- Timestamp:
- Jun 15, 2006 7:59:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/ACL.inc.php
r171 r172 12 12 */ 13 13 14 require_once dirname(__FILE__) . '/Cache.inc.php'; 15 14 16 class ACL { 15 17 16 18 // Configuration parameters for this object. 17 19 var $_params = array( 20 21 // If false nothing will be cached or retreived. Useful for testing realtime data requests. 22 'enable_cache' => true, 18 23 19 24 // Automatically create table and verify columns. Better set to false after site launch. … … 27 32 { 28 33 $app =& App::getInstance(); 34 35 // Configure the cache object. 36 $this->cache = new Cache('acl'); 37 $this->cache->setParam(array('enabled' => true)); 29 38 30 39 // Get create tables config from global context. … … 170 179 } 171 180 $_db_tested = true; 181 return true; 172 182 } 173 183 … … 219 229 $qid = $db->query("SELECT 1 FROM $tbl WHERE name = '" . $db->escapeString($name) . "'"); 220 230 if (mysql_num_rows($qid) > 0) { 221 $app->logMsg(sprintf('Cannot add %s node, name exists: %s', $type, $name), LOG_WARNING, __FILE__, __LINE__);231 $app->logMsg(sprintf('Cannot add %s node, already exists: %s', $type, $name), LOG_NOTICE, __FILE__, __LINE__); 222 232 return false; 223 233 } … … 299 309 $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'"); 300 310 if (!list($lft, $rgt) = mysql_fetch_row($qid)) { 301 $app->logMsg(sprintf('Cannot delete nonexistant %s name: %s', $type, $name), LOG_ WARNING, __FILE__, __LINE__);311 $app->logMsg(sprintf('Cannot delete nonexistant %s name: %s', $type, $name), LOG_NOTICE, __FILE__, __LINE__); 302 312 return false; 303 313 } … … 412 422 $aco = is_null($aco) ? 'root' : $aco; 413 423 $axo = is_null($axo) ? 'root' : $axo; 414 415 $qid = $db->query(" 416 SELECT acl_tbl.access 417 FROM acl_tbl 418 LEFT JOIN aro_tbl ON (acl_tbl.aro_id = aro_tbl.aro_id) 419 LEFT JOIN aco_tbl ON (acl_tbl.aco_id = aco_tbl.aco_id) 420 LEFT JOIN axo_tbl ON (acl_tbl.axo_id = axo_tbl.axo_id) 421 WHERE aro_tbl.lft <= (SELECT lft FROM aro_tbl WHERE name = '" . $db->escapeString($aro) . "') 422 AND aco_tbl.lft <= (SELECT lft FROM aco_tbl WHERE name = '" . $db->escapeString($aco) . "') 423 AND axo_tbl.lft <= (SELECT lft FROM axo_tbl WHERE name = '" . $db->escapeString($axo) . "') 424 ORDER BY aro_tbl.aro_id DESC, aco_tbl.aco_id DESC, axo_tbl.axo_id DESC 425 LIMIT 1 426 "); 427 if (!list($access) = mysql_fetch_row($qid)) { 428 $app->logMsg(sprintf('Access denyed: %s -> %s -> %s. No records found.', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__); 429 return false; 424 425 $cache_hash = $aro . '|' . $aco . '|' . $axo; 426 if ($this->cache->exists($cache_hash) && true === $this->getParam('enable_cache')) { 427 // Access value is cached. 428 $access = $this->cache->get($cache_hash); 429 } else { 430 // Retreive access value from db. 431 $qid = $db->query(" 432 SELECT acl_tbl.access 433 FROM acl_tbl 434 LEFT JOIN aro_tbl ON (acl_tbl.aro_id = aro_tbl.aro_id) 435 LEFT JOIN aco_tbl ON (acl_tbl.aco_id = aco_tbl.aco_id) 436 LEFT JOIN axo_tbl ON (acl_tbl.axo_id = axo_tbl.axo_id) 437 WHERE aro_tbl.lft <= (SELECT lft FROM aro_tbl WHERE name = '" . $db->escapeString($aro) . "') 438 AND aco_tbl.lft <= (SELECT lft FROM aco_tbl WHERE name = '" . $db->escapeString($aco) . "') 439 AND axo_tbl.lft <= (SELECT lft FROM axo_tbl WHERE name = '" . $db->escapeString($axo) . "') 440 ORDER BY aro_tbl.aro_id DESC, aco_tbl.aco_id DESC, axo_tbl.axo_id DESC 441 LIMIT 1 442 "); 443 if (!list($access) = mysql_fetch_row($qid)) { 444 $app->logMsg(sprintf('Access denyed: %s -> %s -> %s. No records found.', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__); 445 return false; 446 } 447 $this->cache->set($cache_hash, $access); 430 448 } 431 449
Note: See TracChangeset
for help on using the changeset viewer.