INTERNAL:
Removes a document from the identity map. This effectively detaches the
document from the persistence management of Doctrine.

@ignore
@param object $document
@throws \InvalidArgumentException
@return boolean
330224
public function removeFromIdentityMap($document)
    {
        $oid = spl_object_hash($document);

        // Check if id is registered first
        if ( ! isset($this->documentIdentifiers[$oid])) {
            return false;
        }

        $class = $this->dm->getClassMetadata(get_class($document));

        if ( ! $class->identifier) {
            $id = spl_object_hash($document);
        } else {
            $id = $this->documentIdentifiers[spl_object_hash($document)];
            $id = serialize($class->getDatabaseIdentifierValue($id));
        }

        if (isset($this->identityMap[$class->name][$id])) {
            unset($this->identityMap[$class->name][$id]);
            $this->documentStates[$oid] = self::STATE_DETACHED;
            return true;
        }

        return false;
    }
1044332
public function computeSingleDocumentChangeSet($document)
    {
        $state = $this->getDocumentState($document);

        if ($state !== self::STATE_MANAGED && $state !== self::STATE_REMOVED) {
            throw new InvalidArgumentException('Document has to be managed for single computation '.self::objToStr($document, $this->dm));
        }

        foreach ($this->scheduledInserts as $insertedDocument) {
            $class = $this->dm->getClassMetadata(get_class($insertedDocument));
            $this->computeChangeSet($class, $insertedDocument);
        }

        // Ignore uninitialized proxy objects
        if ($document instanceof Proxy && !$document->__isInitialized()) {
            return;
        }

        $oid = spl_object_hash($document);
        if (!isset($this->scheduledInserts[$oid])) {
            $class = $this->dm->getClassMetadata(get_class($document));
            $this->computeChangeSet($class, $document);
        }
    }
687750
public function detach($entity)
    {
        $this->entityRegistry->deregisterEntity($entity);
        $objectHashId = $this->entityRegistry->getObjectHashId($entity);
        unset($this->scheduledForInsertion[$objectHashId]);
        unset($this->scheduledForUpdate[$objectHashId]);
        unset($this->scheduledForDeletion[$objectHashId]);
    }
260947
private function removeFromIdentityMap($object)
    {
        $class = $this->manager->getClassMetadata(get_class($object));
        $id = $class->getSingleIdentifier($object);

        if (empty($id)) {
            throw new InvalidIdentifierException('Documents must have an identifier in order to be added to the identity map.');
        }

        unset($this->identityMap[$class->name][$id]);
    }
104119
public function delete($idOrDocument) 
    {
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
		$entityManager = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$entity = $documentRepository->getEntity($idOrDocument);
		// It can NOT exists when add a NEW classified (parent still doesn't exists)
		$parent = $entity->getParent(); 
		
		// checking for permission, only if we are in edit mode
		if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}
		
		$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
		$imageModel = new ImageModel($entity, $this->getServiceLocator());

		// 1) Delete the image
		$phisical = $imageModel->deleteImages();
		
		// 3) Remove the document
		$entityManager->remove($entity);
		$entityManager->flush();
		
		// 4) Remove parent classified cache
		if($cache->hasItem($cacheKey)) {
			$cache->removeItem($cacheKey);
		}
		
		return $phisical;
    }
905580
private function invalidateDocumentStructure($document)
    {
        if (!$this->cacheManager) {
            return;
        }

        $structureBridge = $this->structureManager->wrapStructure(
            $this->documentInspector->getMetadata($document)->getAlias(),
            $this->documentInspector->getStructureMetadata($document)
        );
        $structureBridge->setDocument($document);

        $this->cacheManager->invalidateTag($document->getUuid());
    }
1359596
public function remove($entity)
    {
        $objectManager = $this->getObjectManager();
        $objectManager->remove($entity);
        $objectManager->flush();
    }
605709
private function unregisterDocument($document)
    {
        $oid = spl_object_hash($document);

        if (isset($this->documentIds[$oid])) {
            unset($this->identityMap[$this->documentIds[$oid]]);
        }

        unset($this->scheduledRemovals[$oid],
            $this->scheduledUpdates[$oid],
            $this->scheduledMoves[$oid],
            $this->scheduledReorders[$oid],
            $this->scheduledInserts[$oid],
            $this->originalData[$oid],
            $this->originalTranslatedData[$oid],
            $this->documentIds[$oid],
            $this->documentState[$oid],
            $this->documentTranslations[$oid],
            $this->documentLocales[$oid],
            $this->nonMappedData[$oid],
            $this->documentChangesets[$oid],
            $this->documentHistory[$oid],
            $this->documentVersion[$oid]
        );

        $this->changesetComputed = array_diff($this->changesetComputed, [$oid]);
    }
1274937
public function unlock($document)
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $criteria = array('_id' => $this->class->getDatabaseIdentifierValue($id));
        $lockMapping = $this->class->fieldMappings[$this->class->lockField];
        $this->collection->update($criteria, array('$unset' => array($lockMapping['name'] => true)));
        $this->class->reflFields[$this->class->lockField]->setValue($document, null);
    }
832137
public function deleteDocument(\Document $document)
  {
    $objStmt = $this->Database->prepare("DELETE FROM tl_dms_documents WHERE id=?")->execute($document->id);
    
    return ($objStmt->affectedRows > 0);
  }
8343
public function delete($id)
    {
        if ($id instanceof DocumentInterface) {
            $id = $id->getId();
        }

        $path = $this->getPathForDocument($id);

        return unlink($path);
    }
1037068
public function removeTranslation($document, $locale)
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        if ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::preRemoveTranslation)) {
            $this->eventListenersInvoker->invoke(
                $class,
                Event::preRemoveTranslation,
                $document,
                new LifecycleEventArgs($document, $this->dm),
                $invoke
            );
        }

        $metadata = $this->dm->getClassMetadata(get_class($document));
        if (!$this->isDocumentTranslatable($metadata)) {
            return;
        }

        if (1 === count($this->getLocalesFor($document))) {
            throw new PHPCRException('The last translation of a translatable document may not be removed');
        }

        if ($document instanceof Proxy) {
            $document->__load();
        }

        $oid = spl_object_hash($document);
        $this->documentTranslations[$oid][$locale] = null;
        $this->setLocale($document, $metadata, null);
    }
410598
public function scheduleForInsert(ClassMetadata $class, object $document) : void
    {
        $oid = spl_object_hash($document);

        if (isset($this->documentUpdates[$oid])) {
            throw new InvalidArgumentException('Dirty document can not be scheduled for insertion.');
        }
        if (isset($this->documentDeletions[$oid])) {
            throw new InvalidArgumentException('Removed document can not be scheduled for insertion.');
        }
        if (isset($this->documentInsertions[$oid])) {
            throw new InvalidArgumentException('Document can not be scheduled for insertion twice.');
        }

        $this->documentInsertions[$oid] = $document;

        if (! isset($this->documentIdentifiers[$oid])) {
            return;
        }

        $this->addToIdentityMap($document);
    }
1028245
private function getIdForIdentityMap($document)
    {
        $class = $this->dm->getClassMetadata(get_class($document));

        if ($class->getIndex() === null) {
            $id = spl_object_hash($document);
        } else {
            $id = $class->createIdentifier($document)->getSerialized();
        }

        return $id;
    }
590499
public function removeEntity($entity)
    {
        $this->entityManager->remove($entity);
        $this->entityManager->flush();
        return true;
    }
799415
public function removeDocument(\Innova\CollecticielBundle\Entity\Document $documents)
    {
        $this->documents->removeElement($documents);
    }
1064528
public function lock($document, $lockMode, $lockVersion = null)
    {
        if (!is_object($document)) {
            throw new \InvalidArgumentException(gettype($document));
        }
        $this->unitOfWork->lock($document, $lockMode, $lockVersion);
    }