Delete entity

@return \Zend\Http\Response
@throws EntityNotFoundException
174121
public function deleteAction()
    {
        $entity = $this->loadEntity();
        //TODO: change method to post maybe
        $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        $objectManager->remove($entity);
        $objectManager->flush();

        $controller = explode('/', $this->getRequest()->getUri()->getPath())[2];

        if (!$this->getRequest()->isXmlHttpRequest()) {
            return $this->redirect()->toRoute(null, ['controller' => $controller]);
        }
        return;
    }
670424
public function delete($identifiers)
    {
        $parents = func_get_args();

        $id = array_pop($parents);

        $entity = $parents ? $this->resource->singleByParent(end($parents), $id) : $this->resource->single($id);

        if ($this->failsSecurity($entity)) {
            return $this->responseDenied();
        }

        if (!$entity || $this->failsParentMatch($parents)) {
            return $this->responseNotFound();
        }

        $this->resource->delete($id);

        return $this->response(null, 204);
    }
749466
public function deleteEntity(EntityInterface $entity)
    {
        $delete = $this->tableGateway->getSql()->delete();
        $delete->where->equalTo(
            $this->tableGateway->getPrimaryKey(), $entity->getIdentifier()
        );

        try {
            $this->tableGateway->deleteWith($delete);
        } catch (RuntimeException $e) {
            return false;
        }

        return true;
    }
1291621
public <T> void delete(T entity) {
		if (entity == null) {
			throw new ApitraryOrmException("Cannot delete null entity");
		}

		log.debug("Deleting " + entity.getClass());

		DeleteRequest request = new DeleteRequest();
		request.setEntity(resolveApitraryEntity(entity));
		String id = resolveApitraryEntityId(entity);
		request.setId(id);

		new CascadeDeleteCapable(this).deleteCascades(entity);

		DeleteResponse response = resolveApitraryClient().send(request);
		if (HttpStatus.OK.ordinal() != response.getStatusCode()) {
			if (HttpStatus.Not_Found.ordinal() == response.getStatusCode()) {
				throw new ApitraryOrmDeleteException("Object with id " + id + " does not exist.");
			} else {
				String statusMessage = (String) new DeleteResponseUnmarshaller().unMarshall(response, entity);
				throw new ApitraryOrmDeleteException(statusMessage);
			}
		}
	}
266500
public function delete($entity) {
		if (is_null($entity))
			return;
		
		//connect to database
		$this->mapper->connect();
		
		//begin transaction
		$this->mapper->beginTransaction();
		
		//get primary key
		$pk = $this->getPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey());

		foreach ($this->entityProfile->getReferences() as $assoc)
			$this->entityProfile->getAssociation($assoc)->delete($this->mapper, $pk);
		
		//build fluent query
		$query = $this->mapper->newQuery()
		->deleteFrom($this->entityProfile->getEntityTable())
		->where(Column::__callstatic($this->entityProfile->getPrimaryKey(true))->eq($pk));
		
		//run query
		$result = $query->exec();
		
		//commit
		$this->mapper->commit();
		return $result;
	}
664078
public function delete()
    {
        /*
         * TODO: https://github.com/sulu-io/sulu/pull/1171
         * This method needs to be refactored since in the first
         * iteration the logic was just moved from the Controller
         * to this class due to better reusability.
         */
        $delete = function($id) {
            /** @var Contact $contact */
            $contact = $this->contactRepository->findByIdAndDelete($id);

            if (!$contact) {
                throw new EntityNotFoundException($this->contactRepository->getClassName(), $id);
            }

            $addresses = $contact->getAddresses();
            /** @var Address $address */
            foreach ($addresses as $address) {
                if (!$address->hasRelations()) {
                    $this->em->remove($address);
                }
            }

            $phones = $contact->getPhones()->toArray();
            /** @var Phone $phone */
            foreach ($phones as $phone) {
                if (0 == $phone->getAccounts()->count() && 1 == $phone->getContacts()->count()) {
                    $this->em->remove($phone);
                }
            }
            $emails = $contact->getEmails()->toArray();
            /** @var Email $email */
            foreach ($emails as $email) {
                if (0 == $email->getAccounts()->count() && 1 == $email->getContacts()->count()) {
                    $this->em->remove($email);
                }
            }

            $urls = $contact->getUrls()->toArray();
            /** @var Url $url */
            foreach ($urls as $url) {
                if (0 == $url->getAccounts()->count() && 1 == $url->getContacts()->count()) {
                    $this->em->remove($url);
                }
            }

            $faxes = $contact->getFaxes()->toArray();
            /** @var Fax $fax */
            foreach ($faxes as $fax) {
                if (0 == $fax->getAccounts()->count() && 1 == $fax->getContacts()->count()) {
                    $this->em->remove($fax);
                }
            }

            $socialMediaProfiles = $contact->getSocialMediaProfiles()->toArray();
            /** @var SocialMediaProfile $socialMediaProfile */
            foreach ($socialMediaProfiles as $socialMediaProfile) {
                if (0 == $socialMediaProfile->getAccounts()->count()
                    && 1 == $socialMediaProfile->getContacts()->count()
                ) {
                    $this->em->remove($socialMediaProfile);
                }
            }

            $notes = $contact->getNotes()->toArray();
            /** @var Note $note */
            foreach ($notes as $note) {
                if (0 == $note->getAccounts()->count() && 1 == $note->getContacts()->count()) {
                    $this->em->remove($note);
                }
            }

            $this->em->remove($contact);
            $this->em->flush();
        };

        return $delete;
    }
977572
public function delete()
    {
        if (!$this->hasId()) {
            throw new DeleteException('ID not set - did you call find($id) before delete()?');
        }

        if (!$this->isDeletable()) {
            throw new DeleteException('Permission denied: Entity can not be deleted');
        }

        $this->transactional(function () {
            $this->forceDelete();
        });

        return $this;
    }
772146
public function delete()
    {
        $em = Application::getFacadeApplication()->make(EntityManagerInterface::class);
        $em->remove($this);
        $em->flush();
    }
858144
public function remove($entity)
    {
        $idAccessorRegistry = $this->unitOfWork->getEntityRegistry()->getIdAccessorRegistry();
        $entityId           = $idAccessorRegistry->getEntityId($entity);

        $this->updateMap();

        if (!in_array($entityId, $this->map)) {
            throw new EntityNotFoundException;
        }

        $colJoinName = $this->relation->colJoinName();
        $mapObject   = $this->mapRepository->findOne()->with($colJoinName, Operator::EQUAL, $entityId)->getItem();
        $this->mapRepository->remove($mapObject);
        $this->map = array_diff($this->map, [$entityId]);
    }
921064
public function deleteAction($id)
    {
        $delete = function($id) {
            $group = $this->getDoctrine()
                ->getRepository(static::$entityName)
                ->findGroupById($id);

            if (!$group) {
                throw new EntityNotFoundException(static::$entityName, $id);
            }

            $em = $this->getDoctrine()->getManager();
            $em->remove($group);
            $em->flush();
        };

        $view = $this->responseDelete($id, $delete);

        return $this->handleView($view);
    }
459544
public function delete()
	{
		$this->frozen(true);
		$query = \DB::delete(static::$_table_name)
		            ->where(static::primary_key(), '=', $this->{static::primary_key()});

		$this->pre_delete($query);
		$result = $query->execute(static::get_connection(true));

		return $this->post_delete($result);
	}
610331
public function deleteAction($id)
    {
        try {
            $deleteCallback = $this->getContactManager()->delete();
            $view = $this->responseDelete($id, $deleteCallback);
        } catch (EntityNotFoundException $e) {
            $view = $this->view($e->toArray(), 404);
        }

        return $this->handleView($view);
    }
978995
public function deleteAction()
    {
        $model = $this->loadModel();
        if ($model->isObjectNew()) {
            $this->_forward('noroute');
            return;
        }

        try {
            $model->delete();
            $this->_redirectUrl($this->getHelper()->getGridUrl());
            $this->_getSession()->addSuccess('Deleted Successfully');
        } catch (Exception $e) {
            if ($e instanceof Zend_Db_Statement_Exception && $e->getChainedException() instanceof PDOException) {
                $e = $e->getChainedException();
            }
            Mage::logException($e);
            $this->_getSession()->addError($e->getMessage());
            $this->_redirectUrl($this->getHelper()->getEditUrl($model));
        }
    }
1332997
public static function remove() {
		if(self::$entity_manager == null)
			self::initialize();

		return call_user_func_array(array(self::$entity_manager, "remove"), func_get_args());
	}
1057392
public function delete() {
        $url = "entities";

        if ($this->_id) {
            $url .= "/{$this->_id}";
        }

        if ($this->_type) {
            $url .= "?type={$this->_type}";
        }

        return $this->_orion->delete($url);
    }
800440
public function deleteAction(Request $request, $id)
    {
        $language = $this->getLanguage($request);
        $webspace = $this->getWebspace($request);
        $force = $this->getBooleanRequestParameter($request, 'force', false, false);

        if (!$force) {
            $references = array_filter(
                $this->getRepository()->getReferences($id),
                function(PropertyInterface $reference) {
                    return $reference->getParent()->isNodeType('sulu:page');
                }
            );

            if (count($references) > 0) {
                $data = [
                    'structures' => [],
                    'other' => [],
                ];

                foreach ($references as $reference) {
                    $content = $this->get('sulu.content.mapper')->load(
                        $reference->getParent()->getIdentifier(),
                        $webspace,
                        $language,
                        true
                    );
                    $data['structures'][] = $content->toArray();
                }

                return $this->handleView($this->view($data, 409));
            }
        }

        $view = $this->responseDelete(
            $id,
            function($id) use ($webspace) {
                try {
                    $this->getRepository()->deleteNode($id, $webspace);
                } catch (DocumentNotFoundException $ex) {
                    throw new EntityNotFoundException('Content', $id);
                }
            }
        );

        return $this->handleView($view);
    }
784975
public function delete($entityId)
    {
        $response = $this->client->delete(sprintf('/entities/%s', $entityId));

        return $this->decodeResponse($response);
    }