Index: trunk/kernel/units/categories/cache_updater.php
===================================================================
diff -u
--- trunk/kernel/units/categories/cache_updater.php (revision 0)
+++ trunk/kernel/units/categories/cache_updater.php (revision 5164)
@@ -0,0 +1,351 @@
+Stack = Array();
+ }
+
+ function Push($values)
+ {
+ array_push($this->Stack, $values);
+ }
+
+ function Pop()
+ {
+ if ($this->Count() > 0) {
+ return array_pop($this->Stack);
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Get()
+ {
+ if ($this->Count() > 0) {
+// return end($this->Stack);
+ return $this->Stack[count($this->Stack)-1];
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Update($values)
+ {
+ $this->Stack[count($this->Stack)-1] = $values;
+ }
+
+ function Count()
+ {
+ return count($this->Stack);
+ }
+}
+
+
+class clsCachedPermissions
+{
+ 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);
+ if (!in_array($GroupId, $this->Allow[$Perm])) {
+ array_push($this->Allow[$Perm], $GroupId);
+ $this->RemoveDeny($Perm, $GroupId);
+ }
+ }
+
+ function AddDeny($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Deny[$Perm])) {
+ array_push($this->Deny[$Perm], $GroupId);
+ $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) {
+ $values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
+ }
+ }
+ if (!$values) return '';
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
+ return $sql;
+ }
+}
+
+class kPermCacheUpdater extends kHelper
+{
+ var $Stack;
+ var $iteration;
+ var $totalCats;
+ var $doneCats;
+ var $table;
+
+ var $root_prefixes = Array();
+
+ function Init($prefix, $special, $event_params = null)
+ {
+ parent::Init($prefix, $special, $event_params);
+ $continuing = $event_params['continue'];
+
+ foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
+ $this->root_prefixes[ $module_info['RootCat'] ] = $module_info['Var'];
+ }
+
+ $this->iteration = 0;
+ $this->table = $this->Application->GetTempName('permCacheUpdate');
+
+ if (!$continuing) {
+ $this->Stack =& new clsRecursionStack();
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache';
+ $this->Conn->Query($sql);
+ $this->initData();
+ }
+ else {
+ $this->getData();
+ }
+ }
+
+ function getDonePercent()
+ {
+ if(!$this->totalCats)return 0;
+ return intval( round( $this->doneCats / $this->totalCats * 100 ) );
+ }
+
+ function getData()
+ {
+ $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->table);
+ if ($tmp) $tmp = unserialize($tmp);
+
+ $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,
+ );
+
+ $this->Conn->Query('DELETE FROM '.$this->table);
+
+ $fields_hash = Array('data' => serialize($tmp));
+ $this->Conn->doInsert($fields_hash, $this->table);
+ }
+
+ function initData()
+ {
+ $this->clearData(); // drop table before starting anyway
+
+ $this->Conn->Query('CREATE TABLE '.$this->table.'(data LONGTEXT)');
+
+ $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category');
+ $this->doneCats = 0;
+ }
+
+ function clearData()
+ {
+ $this->Conn->Query('DROP TABLE IF EXISTS '.$this->table);
+ }
+
+ function DoTheJob()
+ {
+ $data = $this->Stack->Get();
+ if ($data === false) { //If Stack is empty
+ $data['current_id'] = 0;
+ $data['title'] = Array();
+ $data['named_path'] = Array();
+ $data['category_template'] = '';
+ $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->Query($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']])) {
+ $next_data = Array();
+ $next_data['title'] = $data['title'];
+ $next_data['named_path'] = $data['named_path'];
+ $next_data['category_template'] = $data['category_template'];
+ $next_data['item_template'] = $data['item_template'];
+ $next_data['current_id'] = $data['children'][ $data['current_child'] ]; //next iteration should process child
+ $next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
+ $next_data['perms']->SetCatId($next_data['current_id']);
+ $data['current_child']++;
+ $this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
+ $this->Stack->Push($next_data); //next iteration should process this child
+ return true;
+ }
+ else {
+ $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;
+ }
+ }
+
+ 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']);
+ }
+
+ function QueryTitle(&$data)
+ {
+ $category_id = $data['current_id'];
+
+ $sql = 'SELECT Name, Filename, CategoryTemplate, ItemTemplate
+ FROM '.TABLE_PREFIX.'Category
+ WHERE CategoryId = '.$category_id;
+
+ $record = $this->Conn->GetRow($sql);
+ if ($record) {
+ $data['title'][] = $record['Name'];
+ $data['named_path'][] = $record['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 (!$record['CategoryTemplate']) {
+ $record['CategoryTemplate'] = $this->Application->ConfigValue($root_prefix.'_CategoryTemplate');
+ $fields_hash['CategoryTemplate'] = $record['CategoryTemplate'];
+ }
+
+ if (!$record['ItemTemplate']) {
+ $record['ItemTemplate'] = $this->Application->ConfigValue($root_prefix.'_ItemTemplate');
+ $fields_hash['ItemTemplate'] = $record['ItemTemplate'];
+ }
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id);
+ }
+
+ // if explicitly set, then use it; use parent template otherwise
+ if ($record['CategoryTemplate']) {
+ $data['category_template'] = $record['CategoryTemplate'];
+ }
+
+ if ($record['ItemTemplate']) {
+ $data['item_template'] = $record['ItemTemplate'];
+ }
+ }
+
+ }
+
+ function QueryChildren(&$data)
+ {
+ $sql = 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE ParentId = '.$data['current_id'];
+ $data['children'] = $this->Conn->GetCol($sql);
+ }
+
+ function QueryPermissions(&$data)
+ {
+ // don't search for section "view" permissions here :)
+ $sql = 'SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue
+ FROM '.TABLE_PREFIX.'Permissions AS ip
+ LEFT JOIN '.TABLE_PREFIX.'PermissionConfig AS ipc ON ipc.PermissionName = ip.Permission
+ WHERE (CatId = '.$data['current_id'].') AND (Permission LIKE "%.VIEW") AND (ipc.PermissionConfigId IS NOT NULL)';
+
+ $records = $this->Conn->Query($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']);
+ }
+
+ foreach ($records as $record) {
+ if ($record['PermissionValue'] == 1) {
+ $data['perms']->AddAllow($record['PermissionConfigId'], $record['GroupId']);
+ }
+ else {
+ $data['perms']->AddDeny($record['PermissionConfigId'], $record['GroupId']);
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
Index: trunk/kernel/admin_templates/xml/cache_updater.tpl
===================================================================
diff -u
--- trunk/kernel/admin_templates/xml/cache_updater.tpl (revision 0)
+++ trunk/kernel/admin_templates/xml/cache_updater.tpl (revision 5164)
@@ -0,0 +1 @@
+
\ No newline at end of file
Index: trunk/core/admin_templates/categories/xml/cache_updater.tpl
===================================================================
diff -u
--- trunk/core/admin_templates/categories/xml/cache_updater.tpl (revision 0)
+++ trunk/core/admin_templates/categories/xml/cache_updater.tpl (revision 5164)
@@ -0,0 +1 @@
+
\ No newline at end of file
Index: trunk/core/admin_templates/catalog/catalog.tpl
===================================================================
diff -u -r5153 -r5164
--- trunk/core/admin_templates/catalog/catalog.tpl (.../catalog.tpl) (revision 5153)
+++ trunk/core/admin_templates/catalog/catalog.tpl (.../catalog.tpl) (revision 5164)
@@ -79,7 +79,7 @@
) );
a_toolbar.AddButton( new ToolBarButton('rebuild_cache', '', function() {
- submit_event('c', 'OnRebuildCache');
+ redirect('');
}
) );
Index: trunk/core/units/categories/categories_config.php
===================================================================
diff -u -r5162 -r5164
--- trunk/core/units/categories/categories_config.php (.../categories_config.php) (revision 5162)
+++ trunk/core/units/categories/categories_config.php (.../categories_config.php) (revision 5164)
@@ -6,6 +6,11 @@
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'CategoriesEventHandler','file'=>'categories_event_handler.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'CategoriesTagProcessor','file'=>'categories_tag_processor.php','build_event'=>'OnBuild'),
+
+ 'RegisterClasses' => Array(
+ Array('pseudo' => 'kPermCacheUpdater','class' => 'kPermCacheUpdater', 'file' => 'cache_updater.php','build_event'=>''),
+ ),
+
'AutoLoad' => true,
'QueryString' => Array(
1 => 'id',
@@ -54,6 +59,8 @@
'categories_properties' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Properties!"),
'categories_custom' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Custom!"),
+ 'categories_update' => Array('prefixes' => Array(), 'format' => "!la_title_UpdatingCategories! (0%)"),
+
'tree_site' => Array('format' => '!la_selecting_categories!'),
),
Index: trunk/kernel/admin_templates/catalog.tpl
===================================================================
diff -u -r5153 -r5164
--- trunk/kernel/admin_templates/catalog.tpl (.../catalog.tpl) (revision 5153)
+++ trunk/kernel/admin_templates/catalog.tpl (.../catalog.tpl) (revision 5164)
@@ -79,7 +79,7 @@
) );
a_toolbar.AddButton( new ToolBarButton('rebuild_cache', '', function() {
- submit_event('c', 'OnRebuildCache');
+ redirect('');
}
) );
Index: trunk/kernel/units/categories/categories_config.php
===================================================================
diff -u -r5162 -r5164
--- trunk/kernel/units/categories/categories_config.php (.../categories_config.php) (revision 5162)
+++ trunk/kernel/units/categories/categories_config.php (.../categories_config.php) (revision 5164)
@@ -6,6 +6,11 @@
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'CategoriesEventHandler','file'=>'categories_event_handler.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'CategoriesTagProcessor','file'=>'categories_tag_processor.php','build_event'=>'OnBuild'),
+
+ 'RegisterClasses' => Array(
+ Array('pseudo' => 'kPermCacheUpdater','class' => 'kPermCacheUpdater', 'file' => 'cache_updater.php','build_event'=>''),
+ ),
+
'AutoLoad' => true,
'QueryString' => Array(
1 => 'id',
@@ -54,6 +59,8 @@
'categories_properties' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Properties!"),
'categories_custom' => Array('prefixes' => Array('c'), 'format' => "#c_status# '#c_titlefield#' - !la_title_Custom!"),
+ 'categories_update' => Array('prefixes' => Array(), 'format' => "!la_title_UpdatingCategories! (0%)"),
+
'tree_site' => Array('format' => '!la_selecting_categories!'),
),
Index: trunk/kernel/units/categories/categories_tag_processor.php
===================================================================
diff -u -r5036 -r5164
--- trunk/kernel/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 5036)
+++ trunk/kernel/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 5164)
@@ -321,6 +321,54 @@
}
return $parent_id;
}
+
+ function InitCacheUpdater($params)
+ {
+ safeDefine('CACHE_PERM_CHUNK_SIZE', 30);
+
+ $force = $this->Application->GetVar('force');
+ $continue = $this->Application->GetVar('continue');
+
+ $updater =& $this->Application->recallObject('kPermCacheUpdater', null, Array('continue' => $continue));
+
+ $ret = false; // don't ask for update
+ if ($continue !== false) {
+ if ($continue == 1) {
+ if ($this->Application->GetVar('ajax')) {
+ // call from AJAX request => returns percent
+ $needs_more = true;
+ while ($needs_more && $updater->iteration < CACHE_PERM_CHUNK_SIZE) {
+ // until proceeeded in this step category count exceeds category per step limit
+ $needs_more = $updater->DoTheJob();
+ }
+
+ if ($needs_more) {
+ // still some categories are left for next step
+ $updater->setData();
+ }
+ else {
+ $updater->clearData();
+ $this->Application->StoreVar('PermCache_UpdateRequired', 0);
+ $this->Application->Redirect($params['destination_template']);
+ }
+
+ $ret = $updater->getDonePercent();
+ }
+ }
+ else {
+ // user selected "No" in perm cache update dialog
+ $updater->clearData();
+ $this->Application->Redirect($params['destination_template']);
+ }
+
+ }
+ elseif (!$force && ($updater->totalCats > CACHE_PERM_CHUNK_SIZE)) {
+ // ask before doing anything
+ $updater->setData();
+ $ret = true;
+ }
+ return $ret;
+ }
}
Index: trunk/core/admin_templates/categories/cache_updater.tpl
===================================================================
diff -u
--- trunk/core/admin_templates/categories/cache_updater.tpl (revision 0)
+++ trunk/core/admin_templates/categories/cache_updater.tpl (revision 5164)
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+  |
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: trunk/core/units/categories/categories_tag_processor.php
===================================================================
diff -u -r5036 -r5164
--- trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 5036)
+++ trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 5164)
@@ -321,6 +321,54 @@
}
return $parent_id;
}
+
+ function InitCacheUpdater($params)
+ {
+ safeDefine('CACHE_PERM_CHUNK_SIZE', 30);
+
+ $force = $this->Application->GetVar('force');
+ $continue = $this->Application->GetVar('continue');
+
+ $updater =& $this->Application->recallObject('kPermCacheUpdater', null, Array('continue' => $continue));
+
+ $ret = false; // don't ask for update
+ if ($continue !== false) {
+ if ($continue == 1) {
+ if ($this->Application->GetVar('ajax')) {
+ // call from AJAX request => returns percent
+ $needs_more = true;
+ while ($needs_more && $updater->iteration < CACHE_PERM_CHUNK_SIZE) {
+ // until proceeeded in this step category count exceeds category per step limit
+ $needs_more = $updater->DoTheJob();
+ }
+
+ if ($needs_more) {
+ // still some categories are left for next step
+ $updater->setData();
+ }
+ else {
+ $updater->clearData();
+ $this->Application->StoreVar('PermCache_UpdateRequired', 0);
+ $this->Application->Redirect($params['destination_template']);
+ }
+
+ $ret = $updater->getDonePercent();
+ }
+ }
+ else {
+ // user selected "No" in perm cache update dialog
+ $updater->clearData();
+ $this->Application->Redirect($params['destination_template']);
+ }
+
+ }
+ elseif (!$force && ($updater->totalCats > CACHE_PERM_CHUNK_SIZE)) {
+ // ask before doing anything
+ $updater->setData();
+ $ret = true;
+ }
+ return $ret;
+ }
}
Index: trunk/core/units/categories/cache_updater.php
===================================================================
diff -u
--- trunk/core/units/categories/cache_updater.php (revision 0)
+++ trunk/core/units/categories/cache_updater.php (revision 5164)
@@ -0,0 +1,351 @@
+Stack = Array();
+ }
+
+ function Push($values)
+ {
+ array_push($this->Stack, $values);
+ }
+
+ function Pop()
+ {
+ if ($this->Count() > 0) {
+ return array_pop($this->Stack);
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Get()
+ {
+ if ($this->Count() > 0) {
+// return end($this->Stack);
+ return $this->Stack[count($this->Stack)-1];
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Update($values)
+ {
+ $this->Stack[count($this->Stack)-1] = $values;
+ }
+
+ function Count()
+ {
+ return count($this->Stack);
+ }
+}
+
+
+class clsCachedPermissions
+{
+ 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);
+ if (!in_array($GroupId, $this->Allow[$Perm])) {
+ array_push($this->Allow[$Perm], $GroupId);
+ $this->RemoveDeny($Perm, $GroupId);
+ }
+ }
+
+ function AddDeny($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Deny[$Perm])) {
+ array_push($this->Deny[$Perm], $GroupId);
+ $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) {
+ $values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
+ }
+ }
+ if (!$values) return '';
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
+ return $sql;
+ }
+}
+
+class kPermCacheUpdater extends kHelper
+{
+ var $Stack;
+ var $iteration;
+ var $totalCats;
+ var $doneCats;
+ var $table;
+
+ var $root_prefixes = Array();
+
+ function Init($prefix, $special, $event_params = null)
+ {
+ parent::Init($prefix, $special, $event_params);
+ $continuing = $event_params['continue'];
+
+ foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
+ $this->root_prefixes[ $module_info['RootCat'] ] = $module_info['Var'];
+ }
+
+ $this->iteration = 0;
+ $this->table = $this->Application->GetTempName('permCacheUpdate');
+
+ if (!$continuing) {
+ $this->Stack =& new clsRecursionStack();
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache';
+ $this->Conn->Query($sql);
+ $this->initData();
+ }
+ else {
+ $this->getData();
+ }
+ }
+
+ function getDonePercent()
+ {
+ if(!$this->totalCats)return 0;
+ return intval( round( $this->doneCats / $this->totalCats * 100 ) );
+ }
+
+ function getData()
+ {
+ $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->table);
+ if ($tmp) $tmp = unserialize($tmp);
+
+ $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,
+ );
+
+ $this->Conn->Query('DELETE FROM '.$this->table);
+
+ $fields_hash = Array('data' => serialize($tmp));
+ $this->Conn->doInsert($fields_hash, $this->table);
+ }
+
+ function initData()
+ {
+ $this->clearData(); // drop table before starting anyway
+
+ $this->Conn->Query('CREATE TABLE '.$this->table.'(data LONGTEXT)');
+
+ $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category');
+ $this->doneCats = 0;
+ }
+
+ function clearData()
+ {
+ $this->Conn->Query('DROP TABLE IF EXISTS '.$this->table);
+ }
+
+ function DoTheJob()
+ {
+ $data = $this->Stack->Get();
+ if ($data === false) { //If Stack is empty
+ $data['current_id'] = 0;
+ $data['title'] = Array();
+ $data['named_path'] = Array();
+ $data['category_template'] = '';
+ $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->Query($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']])) {
+ $next_data = Array();
+ $next_data['title'] = $data['title'];
+ $next_data['named_path'] = $data['named_path'];
+ $next_data['category_template'] = $data['category_template'];
+ $next_data['item_template'] = $data['item_template'];
+ $next_data['current_id'] = $data['children'][ $data['current_child'] ]; //next iteration should process child
+ $next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
+ $next_data['perms']->SetCatId($next_data['current_id']);
+ $data['current_child']++;
+ $this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
+ $this->Stack->Push($next_data); //next iteration should process this child
+ return true;
+ }
+ else {
+ $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;
+ }
+ }
+
+ 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']);
+ }
+
+ function QueryTitle(&$data)
+ {
+ $category_id = $data['current_id'];
+
+ $sql = 'SELECT Name, Filename, CategoryTemplate, ItemTemplate
+ FROM '.TABLE_PREFIX.'Category
+ WHERE CategoryId = '.$category_id;
+
+ $record = $this->Conn->GetRow($sql);
+ if ($record) {
+ $data['title'][] = $record['Name'];
+ $data['named_path'][] = $record['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 (!$record['CategoryTemplate']) {
+ $record['CategoryTemplate'] = $this->Application->ConfigValue($root_prefix.'_CategoryTemplate');
+ $fields_hash['CategoryTemplate'] = $record['CategoryTemplate'];
+ }
+
+ if (!$record['ItemTemplate']) {
+ $record['ItemTemplate'] = $this->Application->ConfigValue($root_prefix.'_ItemTemplate');
+ $fields_hash['ItemTemplate'] = $record['ItemTemplate'];
+ }
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id);
+ }
+
+ // if explicitly set, then use it; use parent template otherwise
+ if ($record['CategoryTemplate']) {
+ $data['category_template'] = $record['CategoryTemplate'];
+ }
+
+ if ($record['ItemTemplate']) {
+ $data['item_template'] = $record['ItemTemplate'];
+ }
+ }
+
+ }
+
+ function QueryChildren(&$data)
+ {
+ $sql = 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE ParentId = '.$data['current_id'];
+ $data['children'] = $this->Conn->GetCol($sql);
+ }
+
+ function QueryPermissions(&$data)
+ {
+ // don't search for section "view" permissions here :)
+ $sql = 'SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue
+ FROM '.TABLE_PREFIX.'Permissions AS ip
+ LEFT JOIN '.TABLE_PREFIX.'PermissionConfig AS ipc ON ipc.PermissionName = ip.Permission
+ WHERE (CatId = '.$data['current_id'].') AND (Permission LIKE "%.VIEW") AND (ipc.PermissionConfigId IS NOT NULL)';
+
+ $records = $this->Conn->Query($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']);
+ }
+
+ foreach ($records as $record) {
+ if ($record['PermissionValue'] == 1) {
+ $data['perms']->AddAllow($record['PermissionConfigId'], $record['GroupId']);
+ }
+ else {
+ $data['perms']->AddDeny($record['PermissionConfigId'], $record['GroupId']);
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
Index: trunk/kernel/admin_templates/categories/cache_updater.tpl
===================================================================
diff -u
--- trunk/kernel/admin_templates/categories/cache_updater.tpl (revision 0)
+++ trunk/kernel/admin_templates/categories/cache_updater.tpl (revision 5164)
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+  |
+
+
+
+
+
+
+
+
\ No newline at end of file