Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Sep 23, 6:11 AM

in-portal

Index: branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (revision 5593)
+++ branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php (revision 5594)
@@ -1,37 +1,78 @@
<?php
class kRecursiveHelper extends kHelper {
function DeleteCategory($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;
$sub_categories = $this->Conn->GetCol($sql);
if ($sub_categories) {
foreach ($sub_categories as $sub_category_id) {
$this->DeleteCategory($sub_category_id);
}
}
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
// 1. remove category items from this category if it is supplemental (non-primary) category to them
- $sql = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems
+ $sql = 'DELETE FROM '.$ci_table.'
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);
+ $sql = 'SELECT ItemPrefix, ItemResourceId
+ FROM '.$ci_table.'
+ WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
+ $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+
+ $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
+ continue;
+ }
+ $item_ids = $this->GetItemIDs($item_prefix, $resource_ids);
+ $temp_handler->BuildTables($item_prefix, $item_ids);
+ $temp_handler->DeleteItems($item_prefix, '', $item_ids);
+ }
// 3. delete this category
+ $temp_handler->BuildTables('c', Array($category_id));
$temp_handler->DeleteItems('c', '', Array($category_id));
+ }
+
+ /**
+ * Converts resource ids list to id field list for given prefix
+ *
+ * @param string $prefix
+ * @param Array $resource_ids
+ * @return Array
+ */
+ function GetItemIDs($prefix, $resource_ids)
+ {
+ if (!$resource_ids) {
+ return Array();
+ }
+
+ $id_field = $this->Application->getUnitOption($prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ $sql = 'SELECT '.$id_field.'
+ FROM '.$table_name.'
+ WHERE ResourceId IN ('.implode(',', $resource_ids).')';
+ return $this->Conn->GetCol($sql);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.2.2/kernel/units/general/helpers/recursive_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.2.2.1
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (revision 5593)
+++ branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (revision 5594)
@@ -1,37 +1,78 @@
<?php
class kRecursiveHelper extends kHelper {
function DeleteCategory($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;
$sub_categories = $this->Conn->GetCol($sql);
if ($sub_categories) {
foreach ($sub_categories as $sub_category_id) {
$this->DeleteCategory($sub_category_id);
}
}
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
// 1. remove category items from this category if it is supplemental (non-primary) category to them
- $sql = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems
+ $sql = 'DELETE FROM '.$ci_table.'
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);
+ $sql = 'SELECT ItemPrefix, ItemResourceId
+ FROM '.$ci_table.'
+ WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)';
+ $category_items = $this->Conn->GetCol($sql, 'ItemResourceId');
+
+ $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
+ continue;
+ }
+ $item_ids = $this->GetItemIDs($item_prefix, $resource_ids);
+ $temp_handler->BuildTables($item_prefix, $item_ids);
+ $temp_handler->DeleteItems($item_prefix, '', $item_ids);
+ }
// 3. delete this category
+ $temp_handler->BuildTables('c', Array($category_id));
$temp_handler->DeleteItems('c', '', Array($category_id));
+ }
+
+ /**
+ * Converts resource ids list to id field list for given prefix
+ *
+ * @param string $prefix
+ * @param Array $resource_ids
+ * @return Array
+ */
+ function GetItemIDs($prefix, $resource_ids)
+ {
+ if (!$resource_ids) {
+ return Array();
+ }
+
+ $id_field = $this->Application->getUnitOption($prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ $sql = 'SELECT '.$id_field.'
+ FROM '.$table_name.'
+ WHERE ResourceId IN ('.implode(',', $resource_ids).')';
+ return $this->Conn->GetCol($sql);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.2.2.1
\ No newline at end of property

Event Timeline