Changeset 172 for trunk/lib/ACL.inc.php


Ignore:
Timestamp:
Jun 15, 2006 7:59:45 PM (18 years ago)
Author:
scdev
Message:

Q - added caching to ACL, and flush command to acl.cli.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/ACL.inc.php

    r171 r172  
    1212*/
    1313
     14require_once dirname(__FILE__) . '/Cache.inc.php';
     15
    1416class ACL {
    1517
    1618    // Configuration parameters for this object.
    1719    var $_params = array(
     20       
     21        // If false nothing will be cached or retreived. Useful for testing realtime data requests.
     22        'enable_cache' => true,
    1823
    1924        // Automatically create table and verify columns. Better set to false after site launch.
     
    2732    {
    2833        $app =& App::getInstance();
     34
     35        // Configure the cache object.
     36        $this->cache = new Cache('acl');
     37        $this->cache->setParam(array('enabled' => true));
    2938
    3039        // Get create tables config from global context.
     
    170179        }
    171180        $_db_tested = true;
     181        return true;
    172182    }
    173183
     
    219229        $qid = $db->query("SELECT 1 FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
    220230        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__);
    222232            return false;
    223233        }
     
    299309        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
    300310        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__);
    302312            return false;
    303313        }
     
    412422        $aco = is_null($aco) ? 'root' : $aco;
    413423        $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);
    430448        }
    431449       
Note: See TracChangeset for help on using the changeset viewer.