/** * Handle delete entity object. * * @param mixed $id * @param ApiEntityManager $manager * @throws EntityNotFoundException if an entity with the given id does not exist * @throws ForbiddenException if a delete operation is forbidden */ public function handleDelete($id, ApiEntityManager $manager) { $entity = $manager->find($id); if (!$entity) { throw new EntityNotFoundException(); } $em = $manager->getObjectManager(); $this->checkPermissions($entity, $em); $this->deleteEntity($entity, $em); $em->flush(); }
/** * @param $id * @param ApiEntityManager $manager * * @throws \Exception */ public function handleDelete($id, ApiEntityManager $manager) { /** @var ContactPhone $contactPhone */ $contactPhone = $manager->find($id); if (!$this->securityFacade->isGranted('EDIT', $contactPhone->getOwner())) { throw new AccessDeniedException(); } if ($this->contactPhoneDeleteValidator->validate($contactPhone)) { $em = $manager->getObjectManager(); $em->remove($contactPhone); $em->flush(); } else { throw new \Exception("oro.contact.phone.error.delete.more_one", 500); } }
/** * {@inheritdoc} */ public function find($id) { $result = parent::find($id); if (!$result) { throw new EntityNotFoundException(); } $entityId = null; $target = $result->getTarget(); if ($target) { $entityId = new EntityIdSoap(); $entityId->setEntity(ClassUtils::getClass($target))->setId($target->getId()); $result->entityId = $entityId; } else { throw new \LogicException('Note entity cannot be unassigned.'); } return $result; }