Index: branches/5.0.x/core/units/general/helpers/recursive_helper.php =================================================================== diff -u -r12117 -r12196 --- branches/5.0.x/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 12117) +++ branches/5.0.x/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 12196) @@ -1,6 +1,6 @@ Conn->Query($sql); } } - + /** * Complete cloning or category with subcategories and subitems * @@ -111,14 +111,22 @@ function PasteCategory($category_id, $prefix = 'c') { $backup_category_id = $this->Application->GetVar('m_cat_id'); - + + $src_parent_path = $this->_getParentPath($category_id); + $dst_parent_path = $this->_getParentPath($backup_category_id); + + if (substr($dst_parent_path, 0, strlen($src_parent_path)) == $src_parent_path) { + // target path contains source path -> recursion + return ; + } + // 1. clone category $temp_handler =& $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler*/ $temp_handler->BuildTables($prefix, Array($category_id)); $new_category_id = array_pop( $temp_handler->CloneItems($prefix, '', Array($category_id)) ); $this->Application->SetVar('m_cat_id', $new_category_id); - + $id_field = $this->Application->getUnitOption($prefix, 'IDField'); $table_name = $this->Application->getUnitOption($prefix, 'TableName'); @@ -190,6 +198,26 @@ } return $item_ids; } + + /** + * Returns parent path for given category + * + * @param int $category_id + * @return Array + */ + function _getParentPath($category_id) + { + static $cache = Array (); + + if (!array_key_exists($category_id, $cache)) { + $sql = 'SELECT ParentPath + FROM ' . TABLE_PREFIX . 'Category + WHERE CategoryId = ' . $category_id; + $cache[$category_id] = $this->Conn->GetOne($sql); + } + + return $cache[$category_id]; + } } ?> \ No newline at end of file