Index: trunk/admin/category/permcacheupdate.php =================================================================== diff -u -r4124 -r4446 --- trunk/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 4124) +++ trunk/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 4446) @@ -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,6 +134,8 @@ var $totalCats; var $doneCats; var $table; + + var $root_prefixes = Array(); /** * Kernel Application @@ -147,18 +149,22 @@ * @var kDBConnection */ var $Conn = null; - + function clsCacheUpdater($continuing=false) { $this->Application =& kApplication::Instance(); $this->Conn =& $this->Application->GetADODBConnection(); + + foreach ($this->Application->ModuleInfo as $module_name => $module_info) { + $this->root_prefixes[ $module_info['RootCat'] ] = $module_info['Var']; + } $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 +184,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 +222,8 @@ { $sql='DROP TABLE IF EXISTS '.$this->table; $this->conn->Execute($sql); - } - + } + function DoTheJob() { $data = $this->Stack->Get(); @@ -229,27 +235,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,7 +274,7 @@ $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) @@ -277,48 +283,68 @@ '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) { + $category_id = $data['current_id']; + $sql = 'SELECT Name, Filename, CategoryTemplate, ItemTemplate FROM '.GetTablePrefix().'Category - WHERE CategoryId = '.$data['current_id']; - + WHERE CategoryId = '.$category_id; + $rs = $this->conn->Execute($sql); - + if ($rs && !$rs->EOF) { $data['title'][] = $rs->fields['Name']; $data['named_path'][] = $rs->fields['Filename']; + + // it is one of the modules root category + $root_prefix = isset($this->root_prefixes[$category_id]) ? $this->root_prefixes[$category_id] : false; + if ($root_prefix) { + $fields_hash = Array(); + if (!$rs->fields['CategoryTemplate']) { + $rs->fields['CategoryTemplate'] = $this->Application->ConfigValue($root_prefix.'_CategoryTemplate'); + $fields_hash['CategoryTemplate'] = $rs->fields['CategoryTemplate']; + } + + if (!$rs->fields['ItemTemplate']) { + $rs->fields['ItemTemplate'] = $this->Application->ConfigValue($root_prefix.'_ItemTemplate'); + $fields_hash['ItemTemplate'] = $rs->fields['ItemTemplate']; + } + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id); + } // if explicitly set, then use it; use parent template otherwise if ($rs->fields['CategoryTemplate']) { $data['category_template'] = $rs->fields['CategoryTemplate']; } + if ($rs->fields['ItemTemplate']) { $data['item_template'] = $rs->fields['ItemTemplate']; } } } - + 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 +353,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) {