Index: branches/unlabeled/unlabeled-1.15.2/kernel/admin_templates/xml/categories_list.tpl
===================================================================
diff -u -r5620 -r5627
--- branches/unlabeled/unlabeled-1.15.2/kernel/admin_templates/xml/categories_list.tpl (.../categories_list.tpl) (revision 5620)
+++ branches/unlabeled/unlabeled-1.15.2/kernel/admin_templates/xml/categories_list.tpl (.../categories_list.tpl) (revision 5627)
@@ -57,6 +57,9 @@
( / )
+
+ ParentPath:
+
()
Index: branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php
===================================================================
diff -u -r5625 -r5627
--- branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5625)
+++ branches/unlabeled/unlabeled-1.22.2/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5627)
@@ -295,16 +295,6 @@
}
parent::OnSave($event);
- $this->UpdateCategoryCache($event);
- }
-
- /**
- * Redirects to Category Cache Updater
- *
- * @param kEvent $event
- */
- function UpdateCategoryCache(&$event)
- {
if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) {
// "catalog" should be in opener stack by now
$opener_stack = unserialize($this->Application->RecallVar('opener_stack'));
@@ -372,6 +362,10 @@
foreach ($clipboard as $prefix => $clipboard_data) {
$paste_event = new kEvent($prefix.':OnPaste', Array('clipboard_data' => $clipboard_data));
$this->Application->HandleEvent($paste_event);
+
+ $event->redirect = $paste_event->redirect;
+ $event->redirect_params = $paste_event->redirect_params;
+ $event->status = $paste_event->status;
}
}
@@ -394,7 +388,7 @@
$recursive_helper =& $this->Application->recallObject('RecursiveHelper');
if ($clipboard_data['cut']) {
- $recursive_helper->MoveCategories($clipboard_data['cut']);
+ $recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id'));
}
if ($clipboard_data['copy']) {
@@ -404,7 +398,10 @@
}
if ($clipboard_data['cut'] || $clipboard_data['copy']) {
- $this->UpdateCategoryCache($event);
+ if ($this->Application->RecallVar('PermCache_UpdateRequired')) {
+ $this->Application->RemoveVar('PermCache_UpdateRequired');
+ $event->redirect = 'categories/cache_updater';
+ }
}
}
Index: branches/unlabeled/unlabeled-1.15.2/core/admin_templates/categories/xml/categories_list.tpl
===================================================================
diff -u -r5620 -r5627
--- branches/unlabeled/unlabeled-1.15.2/core/admin_templates/categories/xml/categories_list.tpl (.../categories_list.tpl) (revision 5620)
+++ branches/unlabeled/unlabeled-1.15.2/core/admin_templates/categories/xml/categories_list.tpl (.../categories_list.tpl) (revision 5627)
@@ -57,6 +57,9 @@
( / )
+
+ ParentPath:
+
()
Index: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php
===================================================================
diff -u -r5626 -r5627
--- branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5626)
+++ branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5627)
@@ -27,16 +27,8 @@
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
// 2. delete items this have this category as primary
- $sql = 'SELECT ItemPrefix, ItemResourceId
- FROM '.$ci_table.'
- WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
- $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+ $delete_ids = $this->getCategoryItems($category_id, true);
- $delete_ids = Array();
- foreach ($category_items as $resource_id => $item_prefix) {
- $delete_ids[$item_prefix][] = $resource_id;
- }
-
foreach ($delete_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
@@ -84,7 +76,7 @@
$sql = 'UPDATE '.$table_name.'
SET ParentId = '.$dest_category_id.'
- WHERE '.$id_field.' IN ('.$category_ids.')';
+ WHERE '.$id_field.' IN ('.implode(',', $category_ids).')';
$this->Conn->Query($sql);
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
@@ -97,34 +89,37 @@
*/
function PasteCategory($category_id)
{
+ $backup_category_id = $this->Application->GetVar('m_cat_id');
+
+ // 1. clone category
+ $temp_handler->BuildTables('c', Array($category_id));
+ $new_category_id = array_pop( $temp_handler->CloneItems('c', '', Array($category_id)) );
+ $this->Application->SetVar('m_cat_id', $new_category_id);
+
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
- $sql = 'SELECT '.$id_field.'
- FROM '.$table_name.'
- WHERE ParentId = '.$category_id;
+ // 2. assign supplemental items to current category to new category
+ $paste_ids = $this->getCategoryItems($category_id, false);
- $sub_categories = $this->Conn->GetCol($sql);
- if ($sub_categories) {
- foreach ($sub_categories as $sub_category_id) {
- $this->PasteCategory($sub_category_id);
+ foreach ($paste_ids as $item_prefix => $resource_ids) {
+ if (!$item_prefix) {
+ // not ItemPrefix filled -> old categoryitem linking
+ continue;
}
+
+ $item_object =& $this->Application->recallObject($item_prefix.'.-item', null, Array('skip_autoload' => true));
+ foreach ($resource_ids as $item_resource_id) {
+ $item_object->Load($item_resource_id, 'ResourceId');
+ $item_object->assignToCategory($new_category_id, false);
+ }
}
- $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+ // 3. clone items that have current category as primary
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
- // 1. select all items from this category
- $sql = 'SELECT ItemPrefix, ItemResourceId
- FROM '.$ci_table.'
- WHERE ('.$id_field.' = '.$category_id.')';
- $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+ $paste_ids = $this->getCategoryItems($category_id, true);
- $paste_ids = Array();
- foreach ($category_items as $resource_id => $item_prefix) {
- $paste_ids[$item_prefix][] = $resource_id;
- }
-
foreach ($paste_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
@@ -137,10 +132,43 @@
$temp_handler->CloneItems($item_prefix, '', $item_ids);
}
- // 3. clone this category
- $temp_handler->BuildTables('c', Array($category_id));
- $temp_handler->CloneItems('c', '', Array($category_id));
+ // 4. do same stuff for each subcategory
+ $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->PasteCategory($sub_category_id);
+ }
+ }
+
+ $this->Application->SetVar('m_cat_id', $backup_category_id);
}
+
+ /**
+ * Returns grouped category items
+ *
+ * @param int $category_id
+ * @param bool $item_primary_category
+ * @return Array
+ */
+ function getCategoryItems($category_id, $item_primary_category = true)
+ {
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+
+ $sql = 'SELECT ItemPrefix, ItemResourceId
+ FROM '.$ci_table.'
+ WHERE (CategoryId = '.$category_id.') AND (PrimaryCat = '.($item_primary_category ? 1 : 0).')';
+ $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+
+ $item_ids = Array();
+ foreach ($category_items as $resource_id => $item_prefix) {
+ $item_ids[$item_prefix][] = $resource_id;
+ }
+ return $item_ids;
+ }
}
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.6.2/core/units/categories/cache_updater.php
===================================================================
diff -u -r5561 -r5627
--- branches/unlabeled/unlabeled-1.6.2/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 5561)
+++ branches/unlabeled/unlabeled-1.6.2/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 5627)
@@ -227,6 +227,7 @@
if ($data === false) { //If Stack is empty
$data['current_id'] = 0;
$data['title'] = Array();
+ $data['parent_path'] = Array();
$data['named_path'] = Array();
$data['category_template'] = '';
$data['item_template'] = '';
@@ -253,6 +254,7 @@
if (isset($data['children'][$data['current_child']])) {
$next_data = Array();
$next_data['title'] = $data['title'];
+ $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'];
@@ -275,6 +277,7 @@
function UpdateCachedPath(&$data)
{
$fields_hash = Array( 'CachedNavbar' => implode('>', $data['title']),
+ 'ParentPath' => '|'.implode('|', $data['parent_path']).'|',
'NamedParentPath' => implode('/', $data['named_path'] ),
'CachedCategoryTemplate'=> $data['category_template'],
'CachedItemTemplate' => $data['item_template'],
@@ -293,6 +296,7 @@
$record = $this->Conn->GetRow($sql);
if ($record) {
$data['title'][] = $record[$this->TitleField];
+ $data['parent_path'][] = $category_id;
$data['named_path'][] = $record['Filename'];
// it is one of the modules root category
Index: branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php
===================================================================
diff -u -r5626 -r5627
--- branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5626)
+++ branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5627)
@@ -27,16 +27,8 @@
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
// 2. delete items this have this category as primary
- $sql = 'SELECT ItemPrefix, ItemResourceId
- FROM '.$ci_table.'
- WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
- $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+ $delete_ids = $this->getCategoryItems($category_id, true);
- $delete_ids = Array();
- foreach ($category_items as $resource_id => $item_prefix) {
- $delete_ids[$item_prefix][] = $resource_id;
- }
-
foreach ($delete_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
@@ -84,7 +76,7 @@
$sql = 'UPDATE '.$table_name.'
SET ParentId = '.$dest_category_id.'
- WHERE '.$id_field.' IN ('.$category_ids.')';
+ WHERE '.$id_field.' IN ('.implode(',', $category_ids).')';
$this->Conn->Query($sql);
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
@@ -97,34 +89,37 @@
*/
function PasteCategory($category_id)
{
+ $backup_category_id = $this->Application->GetVar('m_cat_id');
+
+ // 1. clone category
+ $temp_handler->BuildTables('c', Array($category_id));
+ $new_category_id = array_pop( $temp_handler->CloneItems('c', '', Array($category_id)) );
+ $this->Application->SetVar('m_cat_id', $new_category_id);
+
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
- $sql = 'SELECT '.$id_field.'
- FROM '.$table_name.'
- WHERE ParentId = '.$category_id;
+ // 2. assign supplemental items to current category to new category
+ $paste_ids = $this->getCategoryItems($category_id, false);
- $sub_categories = $this->Conn->GetCol($sql);
- if ($sub_categories) {
- foreach ($sub_categories as $sub_category_id) {
- $this->PasteCategory($sub_category_id);
+ foreach ($paste_ids as $item_prefix => $resource_ids) {
+ if (!$item_prefix) {
+ // not ItemPrefix filled -> old categoryitem linking
+ continue;
}
+
+ $item_object =& $this->Application->recallObject($item_prefix.'.-item', null, Array('skip_autoload' => true));
+ foreach ($resource_ids as $item_resource_id) {
+ $item_object->Load($item_resource_id, 'ResourceId');
+ $item_object->assignToCategory($new_category_id, false);
+ }
}
- $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+ // 3. clone items that have current category as primary
$temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler');
- // 1. select all items from this category
- $sql = 'SELECT ItemPrefix, ItemResourceId
- FROM '.$ci_table.'
- WHERE ('.$id_field.' = '.$category_id.')';
- $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+ $paste_ids = $this->getCategoryItems($category_id, true);
- $paste_ids = Array();
- foreach ($category_items as $resource_id => $item_prefix) {
- $paste_ids[$item_prefix][] = $resource_id;
- }
-
foreach ($paste_ids as $item_prefix => $resource_ids) {
if (!$item_prefix) {
// not ItemPrefix filled -> old categoryitem linking
@@ -137,10 +132,43 @@
$temp_handler->CloneItems($item_prefix, '', $item_ids);
}
- // 3. clone this category
- $temp_handler->BuildTables('c', Array($category_id));
- $temp_handler->CloneItems('c', '', Array($category_id));
+ // 4. do same stuff for each subcategory
+ $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->PasteCategory($sub_category_id);
+ }
+ }
+
+ $this->Application->SetVar('m_cat_id', $backup_category_id);
}
+
+ /**
+ * Returns grouped category items
+ *
+ * @param int $category_id
+ * @param bool $item_primary_category
+ * @return Array
+ */
+ function getCategoryItems($category_id, $item_primary_category = true)
+ {
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+
+ $sql = 'SELECT ItemPrefix, ItemResourceId
+ FROM '.$ci_table.'
+ WHERE (CategoryId = '.$category_id.') AND (PrimaryCat = '.($item_primary_category ? 1 : 0).')';
+ $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+
+ $item_ids = Array();
+ foreach ($category_items as $resource_id => $item_prefix) {
+ $item_ids[$item_prefix][] = $resource_id;
+ }
+ return $item_ids;
+ }
}
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.6.2/kernel/units/categories/cache_updater.php
===================================================================
diff -u -r5561 -r5627
--- branches/unlabeled/unlabeled-1.6.2/kernel/units/categories/cache_updater.php (.../cache_updater.php) (revision 5561)
+++ branches/unlabeled/unlabeled-1.6.2/kernel/units/categories/cache_updater.php (.../cache_updater.php) (revision 5627)
@@ -227,6 +227,7 @@
if ($data === false) { //If Stack is empty
$data['current_id'] = 0;
$data['title'] = Array();
+ $data['parent_path'] = Array();
$data['named_path'] = Array();
$data['category_template'] = '';
$data['item_template'] = '';
@@ -253,6 +254,7 @@
if (isset($data['children'][$data['current_child']])) {
$next_data = Array();
$next_data['title'] = $data['title'];
+ $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'];
@@ -275,6 +277,7 @@
function UpdateCachedPath(&$data)
{
$fields_hash = Array( 'CachedNavbar' => implode('>', $data['title']),
+ 'ParentPath' => '|'.implode('|', $data['parent_path']).'|',
'NamedParentPath' => implode('/', $data['named_path'] ),
'CachedCategoryTemplate'=> $data['category_template'],
'CachedItemTemplate' => $data['item_template'],
@@ -293,6 +296,7 @@
$record = $this->Conn->GetRow($sql);
if ($record) {
$data['title'][] = $record[$this->TitleField];
+ $data['parent_path'][] = $category_id;
$data['named_path'][] = $record['Filename'];
// it is one of the modules root category
Index: branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php
===================================================================
diff -u -r5625 -r5627
--- branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5625)
+++ branches/unlabeled/unlabeled-1.22.2/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 5627)
@@ -295,16 +295,6 @@
}
parent::OnSave($event);
- $this->UpdateCategoryCache($event);
- }
-
- /**
- * Redirects to Category Cache Updater
- *
- * @param kEvent $event
- */
- function UpdateCategoryCache(&$event)
- {
if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) {
// "catalog" should be in opener stack by now
$opener_stack = unserialize($this->Application->RecallVar('opener_stack'));
@@ -372,6 +362,10 @@
foreach ($clipboard as $prefix => $clipboard_data) {
$paste_event = new kEvent($prefix.':OnPaste', Array('clipboard_data' => $clipboard_data));
$this->Application->HandleEvent($paste_event);
+
+ $event->redirect = $paste_event->redirect;
+ $event->redirect_params = $paste_event->redirect_params;
+ $event->status = $paste_event->status;
}
}
@@ -394,7 +388,7 @@
$recursive_helper =& $this->Application->recallObject('RecursiveHelper');
if ($clipboard_data['cut']) {
- $recursive_helper->MoveCategories($clipboard_data['cut']);
+ $recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id'));
}
if ($clipboard_data['copy']) {
@@ -404,7 +398,10 @@
}
if ($clipboard_data['cut'] || $clipboard_data['copy']) {
- $this->UpdateCategoryCache($event);
+ if ($this->Application->RecallVar('PermCache_UpdateRequired')) {
+ $this->Application->RemoveVar('PermCache_UpdateRequired');
+ $event->redirect = 'categories/cache_updater';
+ }
}
}