Changeset 174


Ignore:
Timestamp:
Jun 18, 2006 8:50:35 AM (18 years ago)
Author:
scdev
Message:

Q - added move method to ACL class, added polish.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/acl.cli.php

    r173 r174  
    1414********************************************************************/
    1515
     16$this_script = basename($_SERVER['argv'][0]);
     17
    1618// Give them a fighting chance. Show the help message. ;P
    1719if ($_SERVER['argc'] <= 1) {
     
    2325$db_quth_file = COMMON_BASE . '/global/db_auth.inc.php';
    2426if (!file_exists($db_quth_file)) {
    25     die(sprintf("%s error: the current directory must be common site directory (i.e. the parent directory of the document root) AND the global/db_auth.inc.php file must exist.\n", $_SERVER['argv'][0]));
     27    die(sprintf("%s error: the current directory must be common site directory (i.e. the parent directory of the document root) AND the global/db_auth.inc.php file must exist.\n", $this_script));
    2628}
    2729
    2830if (fileowner($db_quth_file) != getmyuid()) {
    29     die(sprintf("%s error: you must execute this script as the owner of the web files.\n", $_SERVER['argv'][0]));
     31    die(sprintf("%s error: you must execute this script as the owner of the web files.\n", $this_script));
    3032}
    3133
     
    5557    'display_errors' => true,
    5658    'error_reporting' => E_ALL,
    57     'log_file_priority' => LOG_DEBUG,
    58     'log_screen_priority' => LOG_NOTICE,
     59    'log_file_priority' => LOG_INFO,
     60    'log_screen_priority' => LOG_ERR,
    5961    'log_directory' => COMMON_BASE . '/log',
    6062    'log_filename' => 'site_log',
     
    8284switch ($op) {
    8385case 'list' :
    84 $type = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null;
    85 if (isset($type)) {
    86     listACL('root', $type);
    87 } else {
    88 
    89     echo "\n_______________________Access Request Objects________________________\n\n";
    90     listACL('root', 'aro');                               
    91     echo "\n_______________________Access Control Objects________________________\n\n";
    92     listACL('root', 'aco');                               
    93     echo "\n______________________Access eXtension Objects_______________________\n\n";
    94     listACL('root', 'axo');
    95 }
    96 break;
     86    $type = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null;
     87    switch ($type) {
     88    case 'aro' :
     89    case 'aco' :
     90    case 'axo' :
     91        listObjects('root', $type);
     92        break;
     93    case 'all' :
     94        listObjects('root', 'aro');                               
     95        listObjects('root', 'aco');                               
     96        listObjects('root', 'axo');
     97        break;
     98    case 'perms' :
     99        default :
     100        listPerms();
     101        break;
     102    }
     103    break;
    97104
    98105case 'addaro' :
     
    107114    break;
    108115
     116case 'mvaro' :
     117case 'mvaco' :
     118case 'mvaxo' :
     119    $object = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null;
     120    $parent = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : null;
     121    if (!isset($object)) {
     122        echo "'mv*' commands require at least one argument. Try 'help' if you are lost.\n";
     123    }
     124    echo $acl->move($object, $parent, str_replace('mv', '', $op)) ? "Ok\n" : "Error!\n";
     125    break;
     126
    109127case 'rmaro' :
    110128case 'rmaco' :
     
    167185function help()
    168186{
     187    global $this_script;
     188
    169189    ?>
    170190Access Control List command line tool.
     
    176196
    177197Three types of objects are managed by this interface: ARO - Access
    178 Request Objects, ACO - Access Control Objects, and AXO - Access eXtention
     198Request Objects, ACO - Access Control Objects, and AXO - Access Xtra
    179199Objects. These are most often used as a USER -> ACTION -> OBJECT model,
    180200but can just as easily be SPICES -> CUISINES -> DISHES A privilege is
     
    190210"anything" since it is at the top of all branches.
    191211
    192 Usage: <?php echo $_SERVER['argv'][0]; ?> <command> [args]
    193 
    194 
    195 <?php echo $_SERVER['argv'][0]; ?> initdb
    196 <?php echo $_SERVER['argv'][0]; ?> list [aro | aco | axo]
    197 <?php echo $_SERVER['argv'][0]; ?> addaro <aro_object> [parent]
    198 <?php echo $_SERVER['argv'][0]; ?> addaco <aco_object> [parent]
    199 <?php echo $_SERVER['argv'][0]; ?> addaxo <axo_object> [parent]
    200 <?php echo $_SERVER['argv'][0]; ?> rmaro <aro_object>
    201 <?php echo $_SERVER['argv'][0]; ?> rmaco <aco_object>
    202 <?php echo $_SERVER['argv'][0]; ?> rmaxo <axo_object>
    203 <?php echo $_SERVER['argv'][0]; ?> grant <aro_object> [aco_object] [axo_object]
    204 <?php echo $_SERVER['argv'][0]; ?> revoke <aro_object> [aco_object] [axo_object]
    205 
    206 For the add*, grant, and revoke commands, if any of the optional
     212Usage: <?php echo $this_script; ?> <command> [args]
     213
     214Where <command> is any of the following (with arguments):
     215   
     216    initdb
     217    list [aro | aco | axo | all | perms]
     218    addaro <aro_object> [parent]
     219    addaco <aco_object> [parent]
     220    addaxo <axo_object> [parent]
     221    mvaro <aro_object> [parent]
     222    mvaco <aco_object> [parent]
     223    mvaxo <axo_object> [parent]
     224    rmaro <aro_object>
     225    rmaco <aco_object>
     226    rmaxo <axo_object>
     227    grant <aro_object> [aco_object] [axo_object]
     228    revoke <aro_object> [aco_object] [axo_object]
     229
     230For the add*, mv*, grant, and revoke commands if any of the optional
    207231args are not provided, 'root' is assumed.
    208232
     
    213237
    214238
    215 function listACL($root, $type)
     239/*
     240* Print the tree structure of a specified table (aro_tbl, aco_tbl, or axo_tbl).
     241*
     242* @access   public
     243* @param    string $root Root node from which to begin calculating.
     244* @param    string $type Table to call, one of: aro, aco, or axo.
     245* @return   bool Returns false on error.
     246* @author   Quinn Comendant <quinn@strangecode.com>
     247* @version  1.0
     248* @since    17 Jun 2006 23:41:22
     249*/
     250function listObjects($root, $type)
    216251{
    217252    $app =& App::getInstance();
    218253    $db =& DB::getInstance();
    219    
     254    global $this_script;
     255   
     256    echo "\n";
     257
    220258    switch ($type) {
    221259    case 'aro' :
    222260        $tbl = 'aro_tbl';
     261        printf("%-35s %-5s %-5s %s\n", 'Request objects', 'lft', 'rgt', 'Added');
    223262        break;
    224263    case 'aco' :
    225264        $tbl = 'aco_tbl';
     265        printf("%-35s %-5s %-5s %s\n", 'Control objects', 'lft', 'rgt', 'Added');
    226266        break;
    227267    case 'axo' :
    228268        $tbl = 'axo_tbl';
     269        printf("%-35s %-5s %-5s %s\n", 'Xtra objects', 'lft', 'rgt', 'Added');
    229270        break;
    230271    default :
     
    233274        break;
    234275    }
    235    
     276
     277    echo "-----------------------------------------------------------\n";
     278
    236279    // Retrieve the left and right value of the $root node.
    237280    $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($root) . "'");
     
    249292   
    250293        // Display indented node title.
    251         printf("%-20s %-5s %-5s %s\n", str_repeat('    ', sizeof($depth)) . $name, $lft, $rgt, $added_datetime);
     294        printf("%-35s %-5s %-5s %s\n", str_repeat('    ', sizeof($depth)) . $name, $lft, $rgt, date($app->getParam('date_format'), strtotime($added_datetime)));
    252295       
    253296        // Add this node to the stack.
     
    256299}
    257300
     301/*
     302* List all entries in the acl_tbl.
     303*
     304* @access   public
     305* @author   Quinn Comendant <quinn@strangecode.com>
     306* @version  1.0
     307* @since    17 Jun 2006 15:11:53
     308*/
     309function listPerms()
     310{
     311    $app =& App::getInstance();
     312    $db =& DB::getInstance();
     313    global $this_script;
     314   
     315    // Retreive access value from db.
     316    $qid = $db->query("
     317        SELECT aro_tbl.name AS aro, aco_tbl.name AS aco, axo_tbl.name AS axo, acl_tbl.access, acl_tbl.added_datetime
     318        FROM acl_tbl
     319        LEFT JOIN aro_tbl ON (acl_tbl.aro_id = aro_tbl.aro_id)
     320        LEFT JOIN aco_tbl ON (acl_tbl.aco_id = aco_tbl.aco_id)
     321        LEFT JOIN axo_tbl ON (acl_tbl.axo_id = axo_tbl.axo_id)
     322        ORDER BY aro_tbl.aro_id ASC, aco_tbl.aco_id ASC, axo_tbl.axo_id ASC
     323    ");
     324    echo "\n";
     325    printf("%-25s %-25s %-25s %-6s %-10s\n", 'Request objects', 'Control objects', 'Xtra objects', '', 'Added');
     326    echo "------------------------------------------------------------------------------------------------\n";
     327    while ($p = mysql_fetch_assoc($qid)) {
     328        printf("%-25s %-25s %-25s \033[0;%sm%-6s\033[0m %-10s\n", $p['aro'], $p['aco'], $p['axo'], ('allow' == $p['access'] ? '32' : '31'), $p['access'], date($app->getParam('date_format'), strtotime($p['added_datetime'])));
     329    }   
     330}
     331
    258332
    259333?>
  • trunk/lib/ACL.inc.php

    r173 r174  
    66* Uses Modified Preorder Tree Traversal to maintain a tree-structure.
    77* See: http://www.sitepoint.com/print/hierarchical-data-database
    8 * Includes a command-line tool for managing rights.
     8* Includes a command-line tool for managing rights (codebase/bin/acl.cli.php).
    99*
    1010* Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
     
    2929
    3030    /**
    31      * Prefs constructor.
     31     * Constructor.
    3232     */
    3333    function ACL()
     
    102102
    103103    /**
    104      * Setup the database table for this class.
     104     * Setup the database tables for this class.
    105105     *
    106106     * @access  public
     
    192192
    193193    /*
    194     *
     194    * Add a node to one of the aro/aco/axo tables.
    195195    *
    196196    * @access   public
    197     * @param   
    198     * @return   
     197    * @param    string $name A unique identifier for the new node.
     198    * @param    string $parent The name of the parent under-which to attach the new node.
     199    * @param    string $type The tree to add to, one of: aro, aco, axo.
     200    * @return   bool | int False on error, or the last_insert_id primary key of the new node.
    199201    * @author   Quinn Comendant <quinn@strangecode.com>
    200202    * @version  1.0
     
    244246        // Select the rgt of $parent.
    245247        $qid = $db->query("SELECT rgt FROM $tbl WHERE name = '" . $db->escapeString($parent) . "'");
    246         if (!list($rgt) = mysql_fetch_row($qid)) {
     248        if (!list($parent_rgt) = mysql_fetch_row($qid)) {
    247249            $app->logMsg(sprintf('Cannot add %s node to nonexistant parent: %s', $type, $parent), LOG_WARNING, __FILE__, __LINE__);
    248250            return false;
    249251        }
     252
    250253        // Update transversal numbers for all nodes to the rgt of $parent.
    251         $db->query("UPDATE $tbl SET lft = lft + 2 WHERE lft >= $rgt");
    252         $db->query("UPDATE $tbl SET rgt = rgt + 2 WHERE rgt >= $rgt");
     254        $db->query("UPDATE $tbl SET lft = lft + 2 WHERE lft >= $parent_rgt");
     255        $db->query("UPDATE $tbl SET rgt = rgt + 2 WHERE rgt >= $parent_rgt");
    253256       
    254257        // Insert new node just below parent. Lft is parent's old rgt.
    255258        $db->query("
    256259            INSERT INTO $tbl (name, lft, rgt, added_datetime)
    257             VALUES ('" . $db->escapeString($name) . "', $rgt, $rgt + 1, NOW())
     260            VALUES ('" . $db->escapeString($name) . "', $parent_rgt, $parent_rgt + 1, NOW())
    258261        ");
    259262
     
    263266
    264267    // Alias functions for the different object types.
    265     function addARO($name, $parent=null)
     268    function addRequestObject($name, $parent=null)
    266269    {
    267270        return $this->add($name, $parent, 'aro');
    268271    }
    269     function addACO($name, $parent=null)
     272    function addControlObject($name, $parent=null)
    270273    {
    271274        return $this->add($name, $parent, 'aco');
    272275    }
    273     function addAXO($name, $parent=null)
     276    function addXtraObject($name, $parent=null)
    274277    {
    275278        return $this->add($name, $parent, 'axo');
     
    277280
    278281    /*
    279     *
     282    * Remove a node from one of the aro/aco/axo tables.
    280283    *
    281284    * @access   public
    282     * @param   
    283     * @return   
     285    * @param    string $name The identifier for the node to remove.
     286    * @param    string $type The tree to modify, one of: aro, aco, axo.
     287    * @return   bool | int False on error, or true on success.
    284288    * @author   Quinn Comendant <quinn@strangecode.com>
    285289    * @version  1.0
     
    296300        case 'aro' :
    297301            $tbl = 'aro_tbl';
     302            $primary_key = 'aro_id';
    298303            break;
    299304        case 'aco' :
    300305            $tbl = 'aco_tbl';
     306            $primary_key = 'aco_id';
    301307            break;
    302308        case 'axo' :
    303309            $tbl = 'axo_tbl';
     310            $primary_key = 'axo_id';
    304311            break;
    305312        default :
     
    315322        }
    316323       
    317         // Select the lft of $name
     324        // Select the lft and rgt of $name to use for selecting children and reordering transversals.
    318325        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
    319326        if (!list($lft, $rgt) = mysql_fetch_row($qid)) {
     
    322329        }
    323330       
    324         // Remove node and all children of node.
    325         $db->query("DELETE FROM $tbl WHERE lft BETWEEN $lft AND $rgt");
     331        // Remove node and all children of node, as well as acl_tbl links.
     332        $db->query("
     333            DELETE $tbl, acl_tbl
     334            FROM $tbl
     335            LEFT JOIN acl_tbl ON ($tbl.$primary_key = acl_tbl.$primary_key)
     336            WHERE $tbl.lft BETWEEN $lft AND $rgt
     337        ");
    326338        $num_deleted_nodes = mysql_affected_rows($db->getDBH());
    327339
     
    335347   
    336348    // Alias functions for the different object types.
    337     function removeUser($name, $parent=null)
    338     {
    339         return $this->remove($name, $parent, 'aro');
    340     }
    341     function removeAction($name, $parent=null)
    342     {
    343         return $this->remove($name, $parent, 'aco');
    344     }
    345     function removeObject($name, $parent=null)
    346     {
    347         return $this->remove($name, $parent, 'axo');
     349    function removeRequestObject($name)
     350    {
     351        return $this->remove($name, 'aro');
     352    }
     353    function removeControlObject($name)
     354    {
     355        return $this->remove($name, 'aco');
     356    }
     357    function removeXtraObject($name)
     358    {
     359        return $this->remove($name, 'axo');
     360    }
     361
     362    /*
     363    * Move a node to a new parent in one of the aro/aco/axo tables.
     364    *
     365    * @access   public
     366    * @param    string $name The identifier for the node to remove.
     367    * @param    string $new_parent The name of the parent under-which to attach the new node.
     368    * @param    string $type The tree to modify, one of: aro, aco, axo.
     369    * @return   bool | int False on error, or the last_insert_id primary key of the new node.
     370    * @author   Quinn Comendant <quinn@strangecode.com>
     371    * @version  1.0
     372    * @since    14 Jun 2006 22:39:29
     373    */
     374    function move($name, $new_parent, $type)
     375    {
     376        $app =& App::getInstance();
     377        $db =& DB::getInstance();
     378       
     379        $this->initDB();
     380
     381        switch ($type) {
     382        case 'aro' :
     383            $tbl = 'aro_tbl';
     384            $primary_key = 'aro_id';
     385            break;
     386        case 'aco' :
     387            $tbl = 'aco_tbl';
     388            $primary_key = 'aco_id';
     389            break;
     390        case 'axo' :
     391            $tbl = 'axo_tbl';
     392            $primary_key = 'axo_id';
     393            break;
     394        default :
     395            $app->logMsg(sprintf('Invalid access object type: %s', $type), LOG_ERR, __FILE__, __LINE__);
     396            return false;
     397            break;
     398        }
     399       
     400        // If $parent is null, use root object.
     401        if (is_null($parent)) {
     402            $parent = 'root';
     403        }
     404       
     405        // Ensure node and parent name aren't empty.
     406        if ('' == trim($name) || '' == trim($parent)) {
     407            $app->logMsg(sprintf('Cannot add node, parent (%s) or name (%s) missing.', $name, $parent), LOG_WARNING, __FILE__, __LINE__);
     408            return false;
     409        }
     410       
     411        // Select the lft and rgt of $name to use for selecting children and reordering transversals.
     412        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
     413        if (!list($lft, $rgt) = mysql_fetch_row($qid)) {
     414            $app->logMsg(sprintf('Cannot delete nonexistant %s name: %s', $type, $name), LOG_NOTICE, __FILE__, __LINE__);
     415            return false;
     416        }
     417       
     418        // Total number of transversal values (that is, the count of self plus all children times two).
     419        $total_transversal_value = ($rgt - $lft + 1);
     420
     421        // Select the rgt of the new parent.
     422        $qid = $db->query("SELECT rgt FROM $tbl WHERE name = '" . $db->escapeString($new_parent) . "'");
     423        if (!list($new_parent_rgt) = mysql_fetch_row($qid)) {
     424            $app->logMsg(sprintf('Cannot move %s node to nonexistant parent: %s', $type, $new_parent), LOG_WARNING, __FILE__, __LINE__);
     425            return false;
     426        }
     427       
     428        // Ensure the new parent is not a child of the node being moved.
     429        if ($new_parent_rgt <= $rgt && $new_parent_rgt >= $lft) {
     430            $app->logMsg(sprintf('Cannot move %s node %s to parent %s because it is a child of itself.', $type, $name, $new_parent), LOG_WARNING, __FILE__, __LINE__);
     431            return false;
     432        }
     433       
     434        // Collect unique ids of all nodes being moved. The transversal numbers will become duplicated so these will be needed to identify these.
     435        $qid = $db->query("
     436            SELECT $primary_key
     437            FROM $tbl
     438            WHERE lft BETWEEN $lft AND $rgt
     439            AND rgt BETWEEN $lft AND $rgt
     440        ");
     441        $ids = array();
     442        while (list($id) = mysql_fetch_row($qid)) {
     443            $ids[] = $id;
     444        }
     445
     446        // Update transversal numbers for all nodes to the rgt of the node being moved, taking in to account the absence of it's children.
     447        // This will temporarily "remove" the node from the tree, and its transversal values will be duplicated.
     448        $db->query("UPDATE $tbl SET lft = lft - $total_transversal_value WHERE lft > $rgt");
     449        $db->query("UPDATE $tbl SET rgt = rgt - $total_transversal_value WHERE rgt > $rgt");
     450        // Apply transformation to new parent rgt also.
     451        $new_parent_rgt = $new_parent_rgt > $rgt ? $new_parent_rgt - $total_transversal_value : $new_parent_rgt;
     452       
     453        // Update transversal values of moved node and children.
     454        $db->query("
     455            UPDATE $tbl SET
     456                lft = lft - ($lft - $new_parent_rgt),
     457                rgt = rgt - ($lft - $new_parent_rgt)
     458            WHERE $primary_key IN ('" . join("','", $ids) . "')
     459        ");
     460
     461        // Update transversal values of all nodes to the rgt of moved node.
     462        $db->query("UPDATE $tbl SET lft = lft + $total_transversal_value WHERE lft >= $new_parent_rgt AND $primary_key NOT IN ('" . join("','", $ids) . "')");
     463        $db->query("UPDATE $tbl SET rgt = rgt + $total_transversal_value WHERE rgt >= $new_parent_rgt AND $primary_key NOT IN ('" . join("','", $ids) . "')");
     464
     465        die;
     466        $app->logMsg(sprintf('Moved %s node %s to new parent %s.', $type, $name, $new_parent), LOG_DEBUG, __FILE__, __LINE__);
     467        return true;
     468    }
     469   
     470    // Alias functions for the different object types.
     471    function moveRequestObject($name, $new_parent=null)
     472    {
     473        return $this->move($name, $new_parent, 'aro');
     474    }
     475    function moveControlObject($name, $new_parent=null)
     476    {
     477        return $this->move($name, $new_parent, 'aco');
     478    }
     479    function moveXtraObject($name, $new_parent=null)
     480    {
     481        return $this->move($name, $new_parent, 'axo');
    348482    }
    349483   
    350484    /*
    351     *
     485    * Add an entry to the acl_tbl to allow (or deny) a truple with the specified
     486    * ARO -> ACO -> AXO entry.
    352487    *
    353488    * @access   public
    354     * @param   
    355     * @return   
     489    * @param    string $aro Identifier of an existing ARO object.
     490    * @param    string $aco Identifier of an existing ACO object (or null to use root).
     491    * @param    string $axo Identifier of an existing AXO object (or null to use root).
     492    * @return   bool False on error, true on success.
    356493    * @author   Quinn Comendant <quinn@strangecode.com>
    357494    * @version  1.0
     
    397534
    398535    /*
    399     *
     536    * Add an entry to the acl_tbl to deny a truple with the specified
     537    * ARO -> ACO -> AXO entry. This calls the ACL::grant function to create the entry
     538    * but uses 'deny' as the fourth argument.
    400539    *
    401540    * @access   public
    402     * @param   
    403     * @return   
     541    * @param    string $aro Identifier of an existing ARO object.
     542    * @param    string $aco Identifier of an existing ACO object (or null to use root).
     543    * @param    string $axo Identifier of an existing AXO object (or null to use root).
     544    * @return   bool False on error, true on success.
    404545    * @author   Quinn Comendant <quinn@strangecode.com>
    405546    * @version  1.0
     
    412553   
    413554    /*
    414     *
     555    * Calculates the most specific cascading privilege found for a requested
     556    * ARO -> ACO -> AXO entry. Returns FALSE if the entry is denied. By default,
     557    * all entries are denied, unless some point in the hierarchy is set ao "allow."
    415558    *
    416559    * @access   public
    417     * @param   
    418     * @return   
     560    * @param    string $aro Identifier of an existing ARO object.
     561    * @param    string $aco Identifier of an existing ACO object (or null to use root).
     562    * @param    string $axo Identifier of an existing AXO object (or null to use root).
     563    * @return   bool False if denied, true on allowed.
    419564    * @author   Quinn Comendant <quinn@strangecode.com>
    420565    * @version  1.0
  • trunk/lib/App.inc.php

    r172 r174  
    110110        // LOG_INFO      informational message
    111111        // LOG_DEBUG     debug-level message
    112         'log_file_priority' => false,
     112        'log_file_priority' => LOG_INFO,
    113113        'log_email_priority' => false,
    114114        'log_sms_priority' => false,
  • trunk/lib/Auth_SQL.inc.php

    r159 r174  
    711711     * @return string           a password
    712712     */
    713     function generatePassword($pattern='CvccvCdd')
    714     {
     713    function generatePassword($pattern='CvcdCvc')
     714    {
     715        $app =& App::getInstance();
     716        if (preg_match('/[^xCVcvd]/', $pattern)) {
     717            $app->logMsg(sprintf('Invalid pattern: %s', $pattern), LOG_WARNING, __FILE__, __LINE__);
     718            $pattern='CvcdCvc';
     719        }
    715720        $str = '';
    716721        for ($i=0; $i<strlen($pattern); $i++) {
  • trunk/lib/Cache.inc.php

    r172 r174  
    117117
    118118    /**
    119      * Stores a new variable in the session cache. The $key is is md5'ed
    120      * because if a key is numeric, the array_shift function
    121      * will reset the key to the next largest int key. Weird behavior I can't
    122      * understand. For example $cache["123"] will become $cache[0]
     119     * Stores a new variable in the session cache. The $key should not be numberic
     120     * because the array_shift function will reset the key to the next largest
     121     * int key. Weird behavior I can't understand. For example $cache["123"] will become $cache[0]
    123122     *
    124123     * @param str   $key        An identifier for the cached object.
     
    138137        }
    139138
    140         $keyhash = md5($key);
    141139        $var = serialize($var);
    142140        $var_len = strlen($var);
     
    153151
    154152        // Remove any value already stored under this key.
    155         unset($_SESSION['_cache'][$this->_ns][$keyhash]);
     153        unset($_SESSION['_cache'][$this->_ns][$key]);
    156154
    157155        // Continue to prune the cache if its size is greater than stack_size_limit, but keep at least min_items.
     
    161159
    162160        // Save this value under the specified key.
    163         $_SESSION['_cache'][$this->_ns][$keyhash] =& $var;
     161        $_SESSION['_cache'][$this->_ns][$key] =& $var;
    164162
    165163        if ($var_len >= 1024000) {
     
    188186        }
    189187
    190         $keyhash = md5($key);
    191         if (isset($_SESSION['_cache'][$this->_ns][$keyhash])) {
     188        if (isset($_SESSION['_cache'][$this->_ns][$key])) {
    192189            $app->logMsg(sprintf('Retreiving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__);
    193190            // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
    194             $tmp =& $_SESSION['_cache'][$this->_ns][$keyhash];
    195             unset($_SESSION['_cache'][$this->_ns][$keyhash]);
    196             $_SESSION['_cache'][$this->_ns][$keyhash] =& $tmp;
     191            $tmp =& $_SESSION['_cache'][$this->_ns][$key];
     192            unset($_SESSION['_cache'][$this->_ns][$key]);
     193            $_SESSION['_cache'][$this->_ns][$key] =& $tmp;
    197194            // Return the unserialized datum.
    198             return unserialize($_SESSION['_cache'][$this->_ns][$keyhash]);
     195            return unserialize($_SESSION['_cache'][$this->_ns][$key]);
    199196        } else {
    200197            $app->logMsg(sprintf('Missing %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__);
     
    215212        }
    216213
    217         $keyhash = md5($key);
    218         return array_key_exists($keyhash, $_SESSION['_cache'][$this->_ns]);
     214        return array_key_exists($key, $_SESSION['_cache'][$this->_ns]);
    219215    }
    220216
     
    227223    function delete($key)
    228224    {
    229         $keyhash = md5($key);
    230         unset($_SESSION['_cache'][$this->_ns][$keyhash]);
     225        unset($_SESSION['_cache'][$this->_ns][$key]);
    231226    }
    232227   
  • trunk/lib/Prefs.inc.php

    r159 r174  
    186186        if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val || isset($_SESSION['_prefs'][$this->_ns]['persistent'][$key])) {
    187187            $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val;           
    188             $app->logMsg(sprintf('Setting preference %s to %s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
     188            $app->logMsg(sprintf('Setting preference %s => %s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
    189189        } else {
    190             $app->logMsg(sprintf('not setting %s to %s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
     190            $app->logMsg(sprintf('not setting %s => %s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
    191191        }
    192192    }
Note: See TracChangeset for help on using the changeset viewer.