public function handle(MassActionHandlerArgs $args) { $entityIdentifiedField = $this->getEntityIdentifierField($args); $entityName = $this->getEntityName($args); /** @var $result ResultRecordInterface */ $results = new DeletionIterableResult($args->getResults()->getSource()); foreach ($results as $result) { $entity = $this->getEntity($entityName, $result->getValue($entityIdentifiedField)); if ($this->branchService->isBranchHasTickets($entity->getId())) { return new MassActionResponse(false, $this->translator->trans('diamante.desk.branch.messages.delete.exist_tickets_error')); } } return parent::handle($args); }
/** * Delete Branch * * @ApiDoc( * description="Delete branch", * uri="/branches/{id}.{_format}", * method="DELETE", * resource=true, * requirements={ * { * "name"="id", * "dataType"="integer", * "requirement"="\d+", * "description"="Branch Id" * } * }, * statusCodes={ * 204="Returned when successful", * 403="Returned when the user is not authorized to delete branch", * 404="Returned when the branch is not found", * 409="Branch has tickets and can't be deleted" * } * ) * * @param int $id * @throws BranchHasTicketsException */ public function deleteBranch($id) { if (!parent::isBranchHasTickets($id)) { parent::deleteBranch($id); } else { throw new BranchHasTicketsException("Branch has tickets and can't be deleted"); } }