Index: branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php =================================================================== diff -u -r4315 -r4382 --- branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 4315) +++ branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 4382) @@ -2,17 +2,17 @@ class clsRecursionStack { var $Stack; - + function clsRecursionStack() { $this->Stack = Array(); } - + function Push($values) { array_push($this->Stack, $values); } - + function Pop() { if ($this->Count() > 0) { @@ -22,7 +22,7 @@ return false; } } - + function Get() { if ($this->Count() > 0) { @@ -33,12 +33,12 @@ return false; } } - + function Update($values) { $this->Stack[count($this->Stack)-1] = $values; } - + function Count() { return count($this->Stack); @@ -51,25 +51,25 @@ var $Allow; var $Deny; var $CatId; - + function clsCachedPermissions($CatId) { $this->CatId = $CatId; } - + function SetCatId($CatId) { $this->CatId = $CatId; } - + function CheckPermArray($Perm) { if (!isset($this->Allow[$Perm])) { $this->Allow[$Perm] = array(); $this->Deny[$Perm] = array(); } } - + function AddAllow($Perm, $GroupId) { $this->CheckPermArray($Perm); @@ -78,7 +78,7 @@ $this->RemoveDeny($Perm, $GroupId); } } - + function AddDeny($Perm, $GroupId) { $this->CheckPermArray($Perm); @@ -87,34 +87,34 @@ $this->RemoveAllow($Perm, $GroupId); } } - + function RemoveDeny($Perm, $GroupId) { if (in_array($GroupId, $this->Deny[$Perm])) { array_splice($this->Deny[$Perm], array_search($GroupId, $this->Deny[$Perm]), 1); } } - + function RemoveAllow($Perm, $GroupId) { if (in_array($GroupId, $this->Allow[$Perm])) { array_splice($this->Allow[$Perm], array_search($GroupId, $this->Allow[$Perm]), 1); } } - + function GetInsertSQL() { $values = array(); - + $has_deny = array(); - + foreach ($this->Deny as $perm => $groups) { if (count($groups) > 0) { $values[] = '('.$this->CatId.', '.$perm.', "", "'.join(',', $groups).'")'; $has_deny[] = $perm; } } - + foreach ($this->Allow as $perm => $groups) { if (in_array($perm, $has_deny)) continue; if (count($groups) > 0) { @@ -123,7 +123,7 @@ } if (!$values) return ''; $sql = 'INSERT INTO '.GetTablePrefix().'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values); - return $sql; + return $sql; } } @@ -134,7 +134,7 @@ var $totalCats; var $doneCats; var $table; - + /** * Kernel Application * @@ -147,18 +147,18 @@ * @var kDBConnection */ var $Conn = null; - + function clsCacheUpdater($continuing=false) { $this->Application =& kApplication::Instance(); $this->Conn =& $this->Application->GetADODBConnection(); - + $this->conn =& GetADODBConnection(); $this->iteration = 0; $this->table=$GLOBALS['objSession']->GetEditTable('permCacheUpdate'); if (!$continuing) { - $this->Stack =& new clsRecursionStack(); + $this->Stack =& new clsRecursionStack(); $sql = 'DELETE FROM '.GetTablePrefix().'PermCache'; $this->conn->Execute($sql); $this->initData(); @@ -178,29 +178,29 @@ $sql='SELECT data FROM '.$this->table; if( $rs = $this->conn->Execute($sql) ) $tmp = unserialize($rs->fields['data']); - + $this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0; $this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0; if(isset($tmp['stack'])) $this->Stack = $tmp['stack']; else $this->Stack = & new clsRecursionStack(); - - } + + } function setData() { $tmp=Array ( 'totalCats' =>$this->totalCats, 'doneCats' =>$this->doneCats, 'stack' =>$this->Stack, - + ); $sql='DELETE FROM '.$this->table; $this->conn->Execute($sql); $sql='INSERT '.$this->table.' SET data="'.addslashes(serialize($tmp)).'"'; $this->conn->Execute($sql); - } + } function initData() { $sql='CREATE TABLE '.$this->table.'(data LONGTEXT)'; @@ -216,8 +216,8 @@ { $sql='DROP TABLE IF EXISTS '.$this->table; $this->conn->Execute($sql); - } - + } + function DoTheJob() { $data = $this->Stack->Get(); @@ -229,27 +229,27 @@ $data['item_template'] = ''; $this->Stack->Push($data); } - + if (!isset($data['queried'])) { - + $this->QueryTitle($data); $this->QueryChildren($data); $this->QueryPermissions($data); $data['queried'] = 1; - + if($sql = $data['perms']->GetInsertSQL()) { $this->conn->Execute($sql); $this->doneCats++; } $this->iteration++; } - + // start with first child if we haven't started yet if (!isset($data['current_child'])) $data['current_child'] = 0; - + // if we have more children - if (isset($data['children'][$data['current_child']])) + if (isset($data['children'][$data['current_child']])) { $next_data = Array(); $next_data['title'] = $data['title']; @@ -268,33 +268,34 @@ $this->UpdateCachedPath($data); $this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none) // we are getting here if we finished with current level, so check if it's first level - then bail out. - return $this->Stack->Count() > 0; + return $this->Stack->Count() > 0; } } function UpdateCachedPath(&$data) { + $fields_hash = Array( 'CachedNavbar' => implode('>', $data['title']), 'NamedParentPath' => implode('/', $data['named_path'] ), 'CachedCategoryTemplate'=> $data['category_template'], 'CachedItemTemplate' => $data['item_template'], - ); - - $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']); + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']); } - + function QueryTitle(&$data) { $sql = 'SELECT Name, Filename, CategoryTemplate, ItemTemplate FROM '.GetTablePrefix().'Category WHERE CategoryId = '.$data['current_id']; - + $rs = $this->conn->Execute($sql); - + if ($rs && !$rs->EOF) { $data['title'][] = $rs->fields['Name']; $data['named_path'][] = $rs->fields['Filename']; - + // if explicitly set, then use it; use parent template otherwise if ($rs->fields['CategoryTemplate']) { $data['category_template'] = $rs->fields['CategoryTemplate']; @@ -304,21 +305,21 @@ } } } - + function QueryChildren(&$data) { $sql = sprintf('SELECT CategoryId FROM '.GetTablePrefix().'Category WHERE ParentId = %s', $data['current_id']); $rs = $this->conn->Execute($sql); - + $data['children'] = Array(); while ($rs && !$rs->EOF) { $data['children'][] = $rs->fields['CategoryId']; $rs->MoveNext(); } } - + function QueryPermissions(&$data) { $sql = sprintf('SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue FROM '.GetTablePrefix().'Permissions AS ip @@ -327,12 +328,12 @@ WHERE CatId = %s AND Permission LIKE "%%.VIEW"', $data['current_id']); $rs = $this->conn->Execute($sql); - + //create permissions array only if we don't have it yet (set by parent) if (!isset($data['perms'])) { $data['perms'] = new clsCachedPermissions($data['current_id']); } - + while ($rs && !$rs->EOF) { if ($rs->fields['PermissionValue'] == 1) {