public function moveTo(CategoryItem $item, CategoryItem $parent = null)
{
$oldParent = $item->getParent();
if ($parent !== null) {
if ($item->getKey() === $parent->getKey()) {
throw new UnableMoveToSelfException();
}
if ($oldParent !== null && $oldParent->getKey() == $parent->getKey()) {
return;
}
}
if ($oldParent !== null) {
$this->unlinkHierarchy($item, $oldParent);
$item->{$item->getParentIdName()} = null;
}
if ($parent !== null) {
$this->linkHierarchy($item, $parent);
$item->{$item->getParentIdName()} = $parent->getKey();
}
$item->save();
// 연관 객체 정보들이 변경 되었으므로 객채를 갱신 함
return $item->newQuery()->find($item->getKey());
}