Index: trunk/kernel/units/categories/cache_updater.php =================================================================== diff -u -N -r5212 -r6093 --- trunk/kernel/units/categories/cache_updater.php (.../cache_updater.php) (revision 5212) +++ trunk/kernel/units/categories/cache_updater.php (.../cache_updater.php) (revision 6093) @@ -136,22 +136,26 @@ var $doneCats; var $table; + var $primaryLanguageId = 0; + var $languageCount = 0; var $root_prefixes = Array(); - var $TitleField = ''; - + function Init($prefix, $special, $event_params = null) { parent::Init($prefix, $special, $event_params); - - $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); - $this->TitleField = $ml_formatter->LangFieldName('Name'); - + $continuing = $event_params['continue']; - + + // cache widely used values to speed up process: begin + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + $this->languageCount = $ml_helper->getLanguageCount(); + $this->primaryLanguageId = $this->Application->GetDefaultLanguageId(); + // cache widely used values to speed up process: end + 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'); @@ -162,21 +166,21 @@ $this->getData(); } } - - function InitUpdater($continue) + + function InitUpdater() { $this->Stack =& new clsRecursionStack(); $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache'; $this->Conn->Query($sql); $this->initData(); } - + function getDonePercent() { if(!$this->totalCats)return 0; - return intval( round( $this->doneCats / $this->totalCats * 100 ) ); + return min(100, intval( round( $this->doneCats / $this->totalCats * 100 ) )); } - + function getData() { $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->table); @@ -191,31 +195,31 @@ $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); @@ -226,7 +230,8 @@ $data = $this->Stack->Get(); if ($data === false) { //If Stack is empty $data['current_id'] = 0; - $data['title'] = Array(); + $data['titles'] = Array(); + $data['parent_path'] = Array(); $data['named_path'] = Array(); $data['category_template'] = ''; $data['item_template'] = ''; @@ -241,7 +246,7 @@ if ($sql = $data['perms']->GetInsertSQL()) { $this->Conn->Query($sql); - $this->doneCats++; + // $this->doneCats++; // moved to the place where it pops out of the stack by Kostja } $this->iteration++; } @@ -252,7 +257,8 @@ // if we have more children if (isset($data['children'][$data['current_child']])) { $next_data = Array(); - $next_data['title'] = $data['title']; + $next_data['titles'] = $data['titles']; + $next_data['parent_path'] = $data['parent_path']; $next_data['named_path'] = $data['named_path']; $next_data['category_template'] = $data['category_template']; $next_data['item_template'] = $data['item_template']; @@ -268,33 +274,47 @@ $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. + + $this->doneCats++; // moved by Kostja from above, seems to fix the prob 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'], + $fields_hash = Array ( + 'ParentPath' => '|'.implode('|', $data['parent_path']).'|', + 'NamedParentPath' => implode('/', $data['named_path'] ), + 'CachedCategoryTemplate' => $data['category_template'], ); + $i = 1; + while ($i <= $this->languageCount) { + $fields_hash['l'.$i.'_CachedNavbar'] = implode('&|&', $data['titles'][$i]); + $i++; + } + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']); } function QueryTitle(&$data) { $category_id = $data['current_id']; - $sql = 'SELECT '.$this->TitleField.', Filename, CategoryTemplate, ItemTemplate + $sql = 'SELECT * FROM '.TABLE_PREFIX.'Category WHERE CategoryId = '.$category_id; $record = $this->Conn->GetRow($sql); if ($record) { - $data['title'][] = $record[$this->TitleField]; + $i = 1; + while ($i <= $this->languageCount) { + $data['titles'][$i][] = $record['l'.$i.'_Name'] ? $record['l'.$i.'_Name'] : $record['l'.$this->primaryLanguageId.'_Name']; + $i++; + } + + $data['parent_path'][] = $category_id; $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) { @@ -303,25 +323,16 @@ $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) @@ -340,7 +351,7 @@ LEFT JOIN '.TABLE_PREFIX.'PermissionConfig AS ipc ON ipc.PermissionName = ip.Permission WHERE (CatId = '.$data['current_id'].') AND (Permission LIKE "%.VIEW") AND (ip.Type = 0)'; - $records = $this->Conn->Query($sql); + $records = $this->Conn->Query($sql); //create permissions array only if we don't have it yet (set by parent) if (!isset($data['perms'])) {