Index: trunk/core/units/categories/cache_updater.php =================================================================== diff -u -r6791 -r7391 --- trunk/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 6791) +++ trunk/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 7391) @@ -130,6 +130,11 @@ class kPermCacheUpdater extends kHelper { + /** + * Holds Stack + * + * @var clsRecursionStack + */ var $Stack; var $iteration; var $totalCats; @@ -139,12 +144,17 @@ var $primaryLanguageId = 0; var $languageCount = 0; var $root_prefixes = Array(); + var $StrictPath = false; function Init($prefix, $special, $event_params = null) { parent::Init($prefix, $special, $event_params); - $continuing = $event_params['continue']; + $continuing = isset($event_params['continue']) ? $event_params['continue'] : 1; + $this->StrictPath = isset($event_params['strict_path']) ? $event_params['strict_path'] : false; + if ($this->StrictPath && !is_array($this->StrictPath)) { + $this->StrictPath = explode('|', trim($this->StrictPath, '|')); + } // cache widely used values to speed up process: begin $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); @@ -171,6 +181,9 @@ { $this->Stack =& new clsRecursionStack(); $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache'; + if ($this->StrictPath) { + $sql .= ' WHERE CategoryId IN ('.implode(',',$this->StrictPath).')'; + } $this->Conn->Query($sql); $this->initData(); } @@ -236,12 +249,14 @@ $data['named_path'] = Array(); $data['category_template'] = ''; $data['item_template'] = ''; + $data['children_count'] = 0; $this->Stack->Push($data); } if (!isset($data['queried'])) { $this->QueryTitle($data); $this->QueryChildren($data); + $data['children_count'] = count($data['children']); $this->QueryPermissions($data); $data['queried'] = 1; @@ -257,6 +272,13 @@ // if we have more children if (isset($data['children'][$data['current_child']])) { + if ($this->StrictPath) { + while ( isset($data['children'][ $data['current_child'] ]) && !in_array($data['children'][ $data['current_child'] ], $this->StrictPath) ) { + $data['current_child']++; + continue; + } + if (!isset($data['children'][ $data['current_child'] ])) return false; //error + } $next_data = Array(); $next_data['titles'] = $data['titles']; $next_data['parent_path'] = $data['parent_path']; @@ -273,11 +295,17 @@ } else { $this->UpdateCachedPath($data); - $this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none) + $prev_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. $this->doneCats++; // moved by Kostja from above, seems to fix the prob - return $this->Stack->Count() > 0; + $has_more = $this->Stack->Count() > 0; + if ($has_more) { + $next_data = $this->Stack->Get(); + $next_data['children_count'] += $data['children_count']; + $this->Stack->Update($next_data); + } + return $has_more; } } @@ -287,6 +315,7 @@ 'ParentPath' => '|'.implode('|', $data['parent_path']).'|', 'NamedParentPath' => implode('/', $data['named_path'] ), 'CachedCategoryTemplate' => $data['category_template'], + 'CachedDescendantCatsQty' => $data['children_count'], ); $i = 1; @@ -368,5 +397,20 @@ } } } + + /** + * Rebuild all cache in one step + * + */ + function OneStepRun($path='') + { + $this->InitUpdater(); + $needs_more = true; + while ($needs_more) { + // until proceeeded in this step category count exceeds category per step limit + $needs_more = $this->DoTheJob(); + } + $this->clearData(); + } } ?> \ No newline at end of file