Index: trunk/core/units/general/helpers/recursive_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/recursive_helper.php (revision 0) +++ trunk/core/units/general/helpers/recursive_helper.php (revision 5177) @@ -0,0 +1,37 @@ +Application->getUnitOption('c', 'IDField'); + $table_name = $this->Application->getUnitOption('c', 'TableName'); + + $sql = 'SELECT '.$id_field.' + FROM '.$table_name.' + WHERE ParentId = '.$category_id; + + $sub_categories = $this->Conn->GetCol($sql); + if ($sub_categories) { + foreach ($sub_categories as $sub_category_id) { + $this->DeleteCategory($sub_category_id); + } + } + else { + // 1. remove category items from this category if it is supplemental (non-primary) category to them + $sql = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems + WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)'; + $this->Conn->Query($sql); + + $temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler'); + + // 2. delete items this have this category as primary +// $temp_handler->DeleteItems($item_prefix, '', $item_ids); + + // 3. delete this category + $temp_handler->DeleteItems('c', '', Array($category_id)); + } + } + } + +?> \ No newline at end of file Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N -r5162 -r5177 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5162) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5177) @@ -504,7 +504,7 @@ // hot items $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = "'.$property_map['HotLimit'].'"'; + WHERE (VarName = "'.$property_map['HotLimit'].'") AND ('.adodb_mktime().' - Cached < 3600)'; $hot_limit = $this->Conn->GetOne($sql); if ($hot_limit === false) { $hot_limit = $this->CalculateHotLimit($event); Index: trunk/kernel/units/categories/categories_event_handler.php =================================================================== diff -u -N -r5176 -r5177 --- trunk/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5176) +++ trunk/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5177) @@ -234,8 +234,22 @@ )'); } + /** + * Set correct parent path for newly created categories + * + * @param kEvent $event + */ + function OnAfterCopyToLive(&$event) + { + if ($event->getEventParam('temp_id') == 0) { + $object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true)); + $object->Load($event->getEventParam('id')); + + $fields_hash = Array('ParentPath' => $object->buildParentPath()); + $this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = '.$object->GetID()); + } + } - /** * Set cache modification mark if needed * @@ -282,6 +296,31 @@ $this->Application->StoreVar('opener_stack', serialize($opener_stack)); } } + + /** + * Deletes all selected items. + * Automatically recurse into sub-items using temp handler, and deletes sub-items + * by calling its Delete method if sub-item has AutoDelete set to true in its config file + * + * @param kEvent $event + */ + function OnMassDelete(&$event) + { + if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + return; + } + +// $event->status = erSUCCESS; + + $ids = $this->StoreSelectedIDs($event); + if ($ids) { + $recursive_helper =& $this->Application->recallObject('RecursiveHelper'); + foreach ($ids as $id) { + $recursive_helper->DeleteCategory($id); + } + } + $this->clearSelectedIDs($event); + } } ?> \ No newline at end of file Index: trunk/kernel/units/general/helpers/recursive_helper.php =================================================================== diff -u -N --- trunk/kernel/units/general/helpers/recursive_helper.php (revision 0) +++ trunk/kernel/units/general/helpers/recursive_helper.php (revision 5177) @@ -0,0 +1,37 @@ +Application->getUnitOption('c', 'IDField'); + $table_name = $this->Application->getUnitOption('c', 'TableName'); + + $sql = 'SELECT '.$id_field.' + FROM '.$table_name.' + WHERE ParentId = '.$category_id; + + $sub_categories = $this->Conn->GetCol($sql); + if ($sub_categories) { + foreach ($sub_categories as $sub_category_id) { + $this->DeleteCategory($sub_category_id); + } + } + else { + // 1. remove category items from this category if it is supplemental (non-primary) category to them + $sql = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems + WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)'; + $this->Conn->Query($sql); + + $temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler'); + + // 2. delete items this have this category as primary +// $temp_handler->DeleteItems($item_prefix, '', $item_ids); + + // 3. delete this category + $temp_handler->DeleteItems('c', '', Array($category_id)); + } + } + } + +?> \ No newline at end of file Index: trunk/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r5176 -r5177 --- trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5176) +++ trunk/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5177) @@ -234,8 +234,22 @@ )'); } + /** + * Set correct parent path for newly created categories + * + * @param kEvent $event + */ + function OnAfterCopyToLive(&$event) + { + if ($event->getEventParam('temp_id') == 0) { + $object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true)); + $object->Load($event->getEventParam('id')); + + $fields_hash = Array('ParentPath' => $object->buildParentPath()); + $this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = '.$object->GetID()); + } + } - /** * Set cache modification mark if needed * @@ -282,6 +296,31 @@ $this->Application->StoreVar('opener_stack', serialize($opener_stack)); } } + + /** + * Deletes all selected items. + * Automatically recurse into sub-items using temp handler, and deletes sub-items + * by calling its Delete method if sub-item has AutoDelete set to true in its config file + * + * @param kEvent $event + */ + function OnMassDelete(&$event) + { + if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + return; + } + +// $event->status = erSUCCESS; + + $ids = $this->StoreSelectedIDs($event); + if ($ids) { + $recursive_helper =& $this->Application->recallObject('RecursiveHelper'); + foreach ($ids as $id) { + $recursive_helper->DeleteCategory($id); + } + } + $this->clearSelectedIDs($event); + } } ?> \ No newline at end of file Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r5162 -r5177 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5162) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5177) @@ -504,7 +504,7 @@ // hot items $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache - WHERE VarName = "'.$property_map['HotLimit'].'"'; + WHERE (VarName = "'.$property_map['HotLimit'].'") AND ('.adodb_mktime().' - Cached < 3600)'; $hot_limit = $this->Conn->GetOne($sql); if ($hot_limit === false) { $hot_limit = $this->CalculateHotLimit($event); Index: trunk/core/units/general/my_application.php =================================================================== diff -u -N -r4758 -r5177 --- trunk/core/units/general/my_application.php (.../my_application.php) (revision 4758) +++ trunk/core/units/general/my_application.php (.../my_application.php) (revision 5177) @@ -31,6 +31,7 @@ $this->registerClass('kModulesHelper', MODULES_PATH.'/kernel/units/general/helpers/modules.php', 'ModulesHelper'); $this->registerClass('kModRewriteHelper', MODULES_PATH.'/kernel/units/general/helpers/mod_rewrite_helper.php', 'ModRewriteHelper'); + $this->registerClass('kRecursiveHelper', MODULES_PATH.'/kernel/units/general/helpers/recursive_helper.php', 'RecursiveHelper'); } function getUserGroups($user_id) Index: trunk/kernel/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r5005 -r5177 --- trunk/kernel/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 5005) +++ trunk/kernel/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 5177) @@ -339,7 +339,7 @@ function ListCatalogTabs($params) { $ret = ''; - $special = $params['special']; + $special = isset($params['special']) ? $params['special'] : ''; $block_params = Array('name' => $params['render_as']); foreach ($this->Application->ModuleInfo as $module_name => $module_info) { $prefix = $module_info['Var']; Index: trunk/core/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r5005 -r5177 --- trunk/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 5005) +++ trunk/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 5177) @@ -339,7 +339,7 @@ function ListCatalogTabs($params) { $ret = ''; - $special = $params['special']; + $special = isset($params['special']) ? $params['special'] : ''; $block_params = Array('name' => $params['render_as']); foreach ($this->Application->ModuleInfo as $module_name => $module_info) { $prefix = $module_info['Var'];