Index: branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/recursive_helper.php =================================================================== diff -u -r7036 -r7061 --- branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 7036) +++ branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 7061) @@ -74,10 +74,21 @@ $id_field = $this->Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); - $sql = 'UPDATE '.$table_name.' - SET ParentId = '.$dest_category_id.' - WHERE '.$id_field.' IN ('.implode(',', $category_ids).')'; - $this->Conn->Query($sql); + // do not move categories into their children + $sql = 'SELECT ParentPath + FROM '.$table_name.' + WHERE '.$id_field.' = '.$dest_category_id; + $dest_parent_path = explode('|', substr($this->Conn->GetOne($sql), 1, -1)); + + $child_categories = array_intersect($dest_parent_path, $category_ids); // get categories, then can't be moved + $category_ids = array_diff($category_ids, $child_categories); // remove them from movable categories list + + if ($category_ids) { + $sql = 'UPDATE '.$table_name.' + SET ParentId = '.$dest_category_id.' + WHERE '.$id_field.' IN ('.implode(',', $category_ids).')'; + $this->Conn->Query($sql); + } } /**