Changeset 173 for trunk/lib/ACL.inc.php
- Timestamp:
- Jun 15, 2006 8:29:03 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/ACL.inc.php
r172 r173 4 4 * 5 5 * 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 6 8 * Includes a command-line tool for managing rights. 7 9 * … … 124 126 125 127 // acl_tbl 126 $db->query("CREATE TABLE IF NOT EXISTS acl_tbl ( 128 $db->query(" 129 CREATE TABLE IF NOT EXISTS acl_tbl ( 127 130 aro_id SMALLINT(11) UNSIGNED NOT NULL DEFAULT '0', 128 131 aco_id SMALLINT(11) UNSIGNED NOT NULL DEFAULT '0', … … 143 146 $app->logMsg(sprintf('Database table acl_tbl has invalid columns. Please update this table manually.', null), LOG_ALERT, __FILE__, __LINE__); 144 147 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 } 145 154 } 146 155 147 // The tuples of objects.156 // aro_tbl, aco_tbl, axo_tbl 148 157 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 ( 152 160 {$a_o}_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, 153 161 name VARCHAR(32) NOT NULL DEFAULT '', … … 155 163 rgt MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0', 156 164 added_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', 157 UNIQUE name (name),165 UNIQUE KEY name (name(15)), 158 166 KEY transversal (lft, rgt) 159 167 ) ENGINE=MyISAM; 160 168 "); 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 }167 169 168 170 if (!$db->columnExists("{$a_o}_tbl", array( … … 175 177 $app->logMsg(sprintf('Database table %s has invalid columns. Please update this table manually.', "{$a_o}_tbl"), LOG_ALERT, __FILE__, __LINE__); 176 178 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 } 177 185 } 186 178 187 } 179 188 } … … 357 366 358 367 // 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! 359 369 $aro = is_null($aro) ? 'root' : $aro; 360 370 $aco = is_null($aco) ? 'root' : $aco; … … 418 428 $this->initDB(); 419 429 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; 424 434 425 435 $cache_hash = $aro . '|' . $aco . '|' . $axo;
Note: See TracChangeset
for help on using the changeset viewer.