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


Ignore:
Timestamp:
Jun 15, 2006 8:29:03 PM (18 years ago)
Author:
scdev
Message:

Q - little bugs fixing in ACL and acl.cli.php.

File:
1 edited

Legend:

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

    r172 r173  
    44*
    55* Uses the ARO/ACO/AXO model of Access Control Lists.
     6* Uses Modified Preorder Tree Traversal to maintain a tree-structure.
     7* See: http://www.sitepoint.com/print/hierarchical-data-database
    68* Includes a command-line tool for managing rights.
    79*
     
    124126           
    125127            // acl_tbl
    126             $db->query("CREATE TABLE IF NOT EXISTS acl_tbl (
     128            $db->query("
     129                CREATE TABLE IF NOT EXISTS acl_tbl (
    127130                    aro_id SMALLINT(11) UNSIGNED NOT NULL DEFAULT '0',
    128131                    aco_id SMALLINT(11) UNSIGNED NOT NULL DEFAULT '0',
     
    143146                $app->logMsg(sprintf('Database table acl_tbl has invalid columns. Please update this table manually.', null), LOG_ALERT, __FILE__, __LINE__);
    144147                trigger_error(sprintf('Database table acl_tbl has invalid columns. Please update this table manually.', null), E_USER_ERROR);
     148            } else {
     149                // Insert root node data if nonexistant, dely all by default.
     150                $qid = $db->query("SELECT 1 FROM acl_tbl");
     151                if (mysql_num_rows($qid) == 0) {
     152                    $qid = $db->query("REPLACE INTO acl_tbl VALUES ('1', '1', '1', 'deny', NOW())");                   
     153                }               
    145154            }
    146155
    147             // The tuples of objects.
     156            // aro_tbl, aco_tbl, axo_tbl
    148157            foreach (array('aro', 'aco', 'axo') as $a_o) {
    149                 // Each of these uses Modified Preorder Tree Traversal to maintain a tree-structure in a flat format.
    150                 // See: http://www.sitepoint.com/print/hierarchical-data-database
    151                 $db->query("CREATE TABLE IF NOT EXISTS {$a_o}_tbl (
     158                $db->query("
     159                    CREATE TABLE IF NOT EXISTS {$a_o}_tbl (
    152160                        {$a_o}_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    153161                        name VARCHAR(32) NOT NULL DEFAULT '',
     
    155163                        rgt MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',
    156164                        added_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    157                         UNIQUE name (name),
     165                        UNIQUE KEY name (name(15)),
    158166                        KEY transversal (lft, rgt)
    159167                    ) ENGINE=MyISAM;
    160168                ");
    161 
    162                 $qid = $db->query("SELECT 1 FROM {$a_o}_tbl WHERE name = 'root'");
    163                 if (mysql_num_rows($qid) == 0) {
    164                     // Insert root node data.
    165                     $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())");                   
    166                 }
    167169
    168170                if (!$db->columnExists("{$a_o}_tbl", array(
     
    175177                    $app->logMsg(sprintf('Database table %s has invalid columns. Please update this table manually.', "{$a_o}_tbl"), LOG_ALERT, __FILE__, __LINE__);
    176178                    trigger_error(sprintf('Database table %s has invalid columns. Please update this table manually.', "{$a_o}_tbl"), E_USER_ERROR);
     179                } else {
     180                    // Insert root node data if nonexistant.
     181                    $qid = $db->query("SELECT 1 FROM {$a_o}_tbl WHERE name = 'root'");
     182                    if (mysql_num_rows($qid) == 0) {
     183                        $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())");                   
     184                    }                   
    177185                }
     186
    178187            }
    179188        }
     
    357366
    358367        // If any access objects are null, assume using root values.
     368        // However if they're empty we don't want to escalate the grant command to root!
    359369        $aro = is_null($aro) ? 'root' : $aro;
    360370        $aco = is_null($aco) ? 'root' : $aco;
     
    418428        $this->initDB();
    419429
    420         // If any access objects are null, assume using root values.
    421         $aro = is_null($aro) ? 'root' : $aro;
    422         $aco = is_null($aco) ? 'root' : $aco;
    423         $axo = is_null($axo) ? 'root' : $axo;
     430        // If any access objects are null or empty, assume using root values.
     431        $aro = is_null($aro) || '' == trim($aro) ? 'root' : $aro;
     432        $aco = is_null($aco) || '' == trim($aco) ? 'root' : $aco;
     433        $axo = is_null($axo) || '' == trim($axo) ? 'root' : $axo;
    424434       
    425435        $cache_hash = $aro . '|' . $aco . '|' . $axo;
Note: See TracChangeset for help on using the changeset viewer.