Index: branches/unlabeled/unlabeled-1.5.20/admin/category/permcacheupdate.php =================================================================== diff -u -r3331 -r4500 --- branches/unlabeled/unlabeled-1.5.20/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 3331) +++ branches/unlabeled/unlabeled-1.5.20/admin/category/permcacheupdate.php (.../permcacheupdate.php) (revision 4500) @@ -135,8 +135,30 @@ var $doneCats; var $table; + var $root_prefixes = Array(); + + /** + * Kernel Application + * + * @var kApplication + */ + var $Application = null; + /** + * Enter description here... + * + * @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'); @@ -209,6 +231,12 @@ $data['current_id'] = 0; $data['title'] = Array(); $data['named_path'] = Array(); + + $i = 0; + while ($i < ZONE_COUNT) { + $data['zone'.++$i] = ''; + } + $this->Stack->Push($data); } @@ -236,6 +264,13 @@ $next_data = Array(); $next_data['title'] = $data['title']; $next_data['named_path'] = $data['named_path']; + + $i = 1; + while ($i <= ZONE_COUNT) { + $next_data['zone'.$i] = $data['zone'.$i]; + $i++; + } + $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']); @@ -251,26 +286,69 @@ return $this->Stack->Count() > 0; } } + function UpdateCachedPath(&$data) { - $sql = 'UPDATE '.GetTablePrefix().'Category SET CachedNavbar="'.addslashes(join('>',$data['title'])) .'" WHERE CategoryId = '.$data['current_id']; - $this->conn->Execute($sql); + $fields_hash = Array( + 'CachedNavbar' => implode('>', $data['title']), + 'NamedParentPath' => implode('/', $data['named_path'] ), + ); + + $i = 1; + while($i <= ZONE_COUNT) { + $fields_hash['CachedZone'.$i] = $data['zone'.$i]; + $i++; + } - $path = implode('/', $data['named_path'] ); - $sql = 'UPDATE '.GetTablePrefix().'Category SET NamedParentPath = "'.addslashes($path).'" WHERE CategoryId = '.$data['current_id']; - $this->conn->Execute($sql); + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']); } function QueryTitle(&$data) { - $sql = sprintf('SELECT Name, Filename FROM '.GetTablePrefix().'Category WHERE CategoryId = %s', - $data['current_id']); + $category_id = $data['current_id']; + + $select_fields = Array('Name', 'Filename'); + $i = 1; + while ($i <= ZONE_COUNT) { + $select_fields[] = 'Zone'.$i; + $i++; + } + + $sql = 'SELECT '.implode(',', $select_fields).' + FROM '.GetTablePrefix().'Category + 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(); + + $i = 1; + while ($i <= ZONE_COUNT) { + if (!$rs->fields['Zone'.$i]) { + $rs->fields['Zone'.$i] = $this->Application->ConfigValue('Banner'.$i); + $fields_hash['Zone'.$i] = $rs->fields['Zone'.$i]; + } + $i++; + } + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id); + } + + // if explicitly set, then use it; use parent category zone otherwise + $i = 1; + while ($i <= ZONE_COUNT) { + if ($rs->fields['Zone'.$i]) { + $data['zone'.$i] = $rs->fields['Zone'.$i]; + } + $i++; + } } }