Index: units/categories/categories_event_handler.php =================================================================== --- units/categories/categories_event_handler.php (revision 15085) +++ units/categories/categories_event_handler.php (working copy) @@ -1038,7 +1038,7 @@ { if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; - return ; + return; } $to_delete = Array (); @@ -1056,15 +1056,19 @@ foreach ($ids as $id) { $cat->Load($id); + if ( preg_match('/^' . preg_quote($rb->GetDBField('ParentPath'), '/') . '/', $cat->GetDBField('ParentPath')) ) { + // already in "Recycle Bin" -> delete for real $to_delete[] = $id; continue; } + + // just move into "Recycle Bin" category $cat->SetDBField('ParentId', $recycle_bin); $cat->Update(); } + $ids = $to_delete; - $event->redirect = 'categories/cache_updater'; } $event->setEventParam('ids', $ids); @@ -1079,10 +1083,10 @@ $recursive_helper->DeleteCategory($id, $event->Prefix); } } + $this->clearSelectedIDs($event); - $this->Application->StoreVar('RefreshStructureTree', 1); - $this->_resetMenuCache(); + $this->_ensurePermCacheRebuild($event); } /** @@ -1229,20 +1233,32 @@ } if ( $clipboard_data['cut'] || $clipboard_data['copy'] ) { - // rebuild with progress bar - if ( $this->Application->ConfigValue('QuickCategoryPermissionRebuild') ) { - $updater =& $this->Application->makeClass('kPermCacheUpdater'); - /* @var $updater kPermCacheUpdater */ + $this->_ensurePermCacheRebuild($event); + } + } - $updater->OneStepRun(); - } - else { - $event->redirect = 'categories/cache_updater'; - } + /** + * Ensures, that category permission cache is rebuild when category is added/edited/deleted + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function _ensurePermCacheRebuild(&$event) + { + if ( $this->Application->ConfigValue('QuickCategoryPermissionRebuild') ) { + $updater =& $this->Application->makeClass('kPermCacheUpdater'); + /* @var $updater kPermCacheUpdater */ - $this->_resetMenuCache(); - $this->Application->StoreVar('RefreshStructureTree', 1); + $updater->OneStepRun(); } + else { + // rebuild with progress bar + $event->redirect = 'categories/cache_updater'; + } + + $this->_resetMenuCache(); + $this->Application->StoreVar('RefreshStructureTree', 1); } /** Index: units/categories/categories_tag_processor.php =================================================================== --- units/categories/categories_tag_processor.php (revision 15085) +++ units/categories/categories_tag_processor.php (working copy) @@ -128,13 +128,27 @@ $ci_table = $this->Application->getUnitOption('ci', 'TableName'); + $module_prefixes = implode(',', $this->Conn->qstrArray($this->_getModulePrefixes())); + $sql = 'SELECT COUNT(*) FROM ' . $object->TableName . ' c - LEFT JOIN ' . $ci_table . ' ci ON c.CategoryId = ci.CategoryId - WHERE (c.TreeLeft BETWEEN ' . $object->GetDBField('TreeLeft') . ' AND ' . $object->GetDBField('TreeRight') . ') AND NOT (ci.CategoryId IS NULL)'; + JOIN ' . $ci_table . ' ci ON c.CategoryId = ci.CategoryId + WHERE (c.TreeLeft BETWEEN ' . $object->GetDBField('TreeLeft') . ' AND ' . $object->GetDBField('TreeRight') . ') AND (ci.ItemPrefix IN (' . $module_prefixes . '))'; + return $this->Conn->GetOne($sql); } + function _getModulePrefixes() + { + $ret = Array (); + + foreach ($this->Application->ModuleInfo as $module_info) { + $ret[] = $module_info['Var']; + } + + return array_unique($ret); + } + function ListCategories($params) { return $this->PrintList2($params);