Changeset 172
- Timestamp:
- Jun 15, 2006 7:59:45 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/acl.cli.php
r171 r172 116 116 break; 117 117 118 case 'flush' : 119 echo $acl->initDB(true) ? "Ok\n" : "Error!\n"; 120 break; 121 118 122 case 'grant' : 119 123 $aro = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : null; … … 195 199 <?php echo $_SERVER['argv'][0]; ?> rmaco <aco_object> 196 200 <?php echo $_SERVER['argv'][0]; ?> rmaxo <axo_object> 201 <?php echo $_SERVER['argv'][0]; ?> flush 197 202 <?php echo $_SERVER['argv'][0]; ?> grant <aro_object> [aco_object] [axo_object] 198 203 <?php echo $_SERVER['argv'][0]; ?> revoke <aro_object> [aco_object] [axo_object] -
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 -
trunk/lib/App.inc.php
r170 r172 156 156 // Initialize default parameters. 157 157 $this->_params = array_merge($this->_params, $this->_param_defaults); 158 159 // Begin timing script. 160 require_once dirname(__FILE__) . '/ScriptTimer.inc.php'; 161 $this->timer = new ScriptTimer(); 162 $this->timer->start('_app'); 158 163 } 159 164 … … 334 339 restore_include_path(); 335 340 $this->running = false; 341 $num_queries = 0; 336 342 if (true === $this->getParam('enable_db')) { 343 $num_queries = $this->db->numQueries(); 337 344 $this->db->close(); 338 345 } 346 $this->timer->stop('_app'); 347 $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s.', $this->timer->getTime('_app'), $num_queries), LOG_DEBUG, __FILE__, __LINE__); 339 348 } 340 349 -
trunk/lib/Cache.inc.php
r162 r172 47 47 function Cache($namespace='') 48 48 { 49 $app =& App::getInstance(); 50 49 51 $this->_ns = $namespace; 52 53 if (true !== $app->getParam('enable_session')) { 54 $app->logMsg('Cache disabled, enable_session is false.', LOG_DEBUG, __FILE__, __LINE__); 55 $this->setParam(array('enabled' => false)); 56 } 50 57 51 58 if (!isset($_SESSION['_cache'][$this->_ns])) { … … 191 198 return unserialize($_SESSION['_cache'][$this->_ns][$keyhash]); 192 199 } else { 200 $app->logMsg(sprintf('Missing %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__); 193 201 return false; 194 202 } -
trunk/lib/DB.inc.php
r156 r172 17 17 // Database handle. 18 18 var $dbh; 19 20 // Count how many queries run during the whole instance. 21 var $_query_count = 0; 19 22 20 23 // Hash of DB parameters. … … 229 232 function query($query, $debug=false) 230 233 { 231 static $_query_count = 0;232 234 $app =& App::getInstance(); 233 235 … … 236 238 } 237 239 238 $_query_count++; 240 $this->_query_count++; 241 239 242 $debugqry = preg_replace("/\n[\t ]+/", "\n", $query); 240 243 if ($this->getParam('db_always_debug') || $debug) { 241 echo "<!-- ----------------- Query $ _query_count ---------------------\n$debugqry\n-->\n";244 echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n"; 242 245 } 243 246 … … 342 345 } 343 346 } 347 348 /* 349 * Return the total number of queries run this for. 350 * 351 * @access public 352 * @return int Number of queries 353 * @author Quinn Comendant <quinn@strangecode.com> 354 * @version 1.0 355 * @since 15 Jun 2006 11:46:05 356 */ 357 function numQueries() 358 { 359 return $this->_query_count; 360 } 344 361 345 362 /** -
trunk/lib/ScriptTimer.inc.php
r136 r172 18 18 function stop($name='default') 19 19 { 20 if (!isset($this->_timing_stop_times[$name]) || !isset($this->_timing_cumulative_times[$name])) { 21 $this->_timing_stop_times[$name] = null; 22 $this->_timing_cumulative_times[$name] = null; 23 } 20 24 $this->_timing_stop_times[$name] = explode(' ', microtime()); 21 25 $this->_timing_cumulative_times[$name] += $this->getTime($name); … … 25 29 { 26 30 if (!isset($this->_timing_start_times[$name])) { 27 31 return 0; 28 32 } 29 33 if (!isset($this->_timing_stop_times[$name])) { … … 48 52 } 49 53 50 $this->_timing_cumulative_times[ "TOTAL"] = array_sum($this->_timing_cumulative_times);54 $this->_timing_cumulative_times['TOTAL'] = array_sum($this->_timing_cumulative_times); 51 55 52 56 echo '<pre>';
Note: See TracChangeset
for help on using the changeset viewer.