예제 #1
0
 /**
  * Delete single entity
  *
  * @param \XLite\Model\AEntity $entity Entity to detach
  *
  * @return void
  */
 protected function performDelete(\XLite\Model\AEntity $entity)
 {
     // Update quick flags
     if ($entity->getParent()) {
         $this->updateQuickFlags($entity->getParent(), $this->prepareQuickFlags(-1, $entity->getEnabled() ? -1 : 0));
     }
     // Root category cannot be removed. Only its subtree
     $onlySubtree = $entity->getCategoryId() == $this->getRootCategoryId();
     // Calculate some variables
     $right = $entity->getRpos() - ($onlySubtree ? 1 : 0);
     $width = $entity->getRpos() - $entity->getLpos() - ($onlySubtree ? 1 : -1);
     // Update indexes in the nested set.
     // FIXME: must not use execute()
     $this->defineUpdateIndexQuery('lpos', $right, -$width)->execute();
     $this->defineUpdateIndexQuery('rpos', $right, -$width)->execute();
     if ($onlySubtree) {
         $this->deleteInBatch($this->getSubtree($entity->getCategoryId()), false);
     } else {
         parent::performDelete($entity);
     }
 }