Delete a classified. Also delete related images.

@param unknown $idOrDocument
@throws \Exception
@return \Neobazaar\Entity\Document
198230
public function touch($idOrDocument) 
    { 
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$document = $documentRepository->getEntity($idOrDocument);
		$document->setDateEdit(new \DateTime());
		$key = $documentRepository->getEncryptedId($document->getDocumentId());
		
		if(!$this->checkIfOwnerOrAdmin($document)) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}
		
		// @todo better manage removal from cache... events?
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		if ($cache->hasItem($key)) {
			$cache->removeItem($key);
		}
		
		$cache = $this->getServiceLocator()->get('ClassifiedCacheOwnerAdmin');
		if ($cache->hasItem($key)) {
			$cache->removeItem($key);
		}
		
		$this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, array('document' => $document));
		$em->persist($document);
		$em->flush();
		$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('document' => $document));
		
    	return $document;
    }
984650
function removeRelatedObjectItem( $contentObjectAttribute, $objectID )
    {
        $xmlText = $contentObjectAttribute->attribute( 'data_text' );
        if ( trim( $xmlText ) == '' ) return;

        $doc = $this->parseXML( $xmlText );

        $return = false;
        $root = $doc->documentElement;
        $relationList = $root->getElementsByTagName( 'relation-list' )->item( 0 );
        if ( $relationList )
        {
            $relationItems = $relationList->getElementsByTagName( 'relation-item' );
            if ( !empty( $relationItems ) )
            {
                foreach( $relationItems as $relationItem )
                {
                    if ( $relationItem->getAttribute( 'contentobject-id' ) == $objectID )
                    {
                        $relationList->removeChild( $relationItem );
                        $return = true;
                    }
                }
            }
        }
        $this->storeObjectDOMDocument( $doc, $contentObjectAttribute );
        return $return;
    }
43057
public function delete() {
		if ($this->dbId()) {
			$this->db()->query('DELETE FROM `'.$this->table().'` WHERE `'.$this->idVar().'` = ?', [$this->dbId()]);
		} else {
			throw new Exception('Cannot delete. No ID was given.');
		}
		return $this;
	}
984904
public function delete($id)
    {
        foreach ($this->_indices as $index) {
            $indexCount = $index->count();

            if ($indexCount > $id) {
                $index->delete($id);
                return;
            }

            $id -= $indexCount;
        }

        include_once 'Zend/Search/Lucene/Exception.php';
        throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
    }
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;
    }
204822
public function deleteDocument(TransferInterface $transfer, $containerName)
    {
        $this->checkTransferMethods($transfer);

        $fileName = $transfer->getFileName();
        $relativePath = $transfer->getRelativePath();

        return $this->fileUploadFacade->deleteFile($containerName, $fileName, $relativePath);
    }
1098149
public function createToolDocument(DropzoneTool $tool, Document $document, $idDocument = null, $reportUrl = null)
    {
        $toolDocument = new DropzoneToolDocument();
        $toolDocument->setTool($tool);
        $toolDocument->setDocument($document);
        $data = ['idDocument' => $idDocument, 'reportUrl' => $reportUrl];
        $toolDocument->setData($data);
        $this->om->persist($toolDocument);
        $this->om->flush();
    }
308379
public static function deleteByObject($object = null, $objectId = null)
    {
        //wybieramy kolekcję i usuwamy całą
        return CmsFileQuery::byObject($object, $objectId)
                ->find()
                ->delete();
    }
428873
public function delete_object_from_relationships( $id, $object, $name = null ) {

		/**
		 * @var $pods_init \PodsInit
		 */
		global $pods_init;

		$pod = false;

		// Run any bidirectional delete operations
		if ( is_array( $object ) ) {
			$pod = $object;
		} elseif ( is_object( $pods_init ) ) {
			$pod = PodsInit::$meta->get_object( $object, $name );
		}

		if ( ! empty( $pod ) ) {
			$object = $pod['type'];
			$name   = $pod['name'];

			foreach ( $pod['fields'] as $field ) {
				PodsForm::delete( $field['type'], $id, $field['name'], array_merge( $field, $field['options'] ), $pod );
			}
		}

		// Lookup related fields (non-bidirectional)
		$params = array(
			'where' => array(
				array(
					'key'   => 'type',
					'value' => 'pick'
				),
				array(
					'key'   => 'pick_object',
					'value' => $object
				)
			)
		);

		if ( ! empty( $name ) && $name !== $object ) {
			$params['where'][] = array(
				'key'   => 'pick_val',
				'value' => $name
			);
		}

		$fields = $this->load_fields( $params, false );

		if ( ! empty( $pod ) && 'media' === $pod['type'] ) {
			$params['where'] = array(
				array(
					'key'   => 'type',
					'value' => 'file'
				)
			);

			$fields = array_merge( $fields, $this->load_fields( $params, false ) );
		}

		if ( is_array( $fields ) && ! empty( $fields ) ) {
			foreach ( $fields as $related_field ) {
				$related_pod = $this->load_pod( array( 'id' => $related_field['pod_id'], 'fields' => false ), false );

				if ( empty( $related_pod ) ) {
					continue;
				}

				$related_from = $this->lookup_related_items_from( $related_field['id'], $related_pod['id'], $id, $related_field, $related_pod );

				$this->delete_relationships( $related_from, $id, $related_pod, $related_field );
			}
		}

		if ( ! empty( $pod ) && ! pods_tableless() ) {
			pods_query( "
				DELETE FROM `@wp_podsrel`
				WHERE
				(
					`pod_id` = %d
					AND `item_id` = %d
				)
				OR (
					`related_pod_id` = %d
					AND `related_item_id` = %d
				)
			", array(
				$pod['id'],
				$id,

				$pod['id'],
				$id
			) );
		}

		return true;
	}
388522
public function deleteObject($entity, $_id)
	{
		$retValue = true;

		try{
			$m = new MongoDB\Driver\Manager($this->url);
			$bulk = new MongoDB\Driver\BulkWrite;

			$bulk->delete(['_id' => new MongoDB\BSON\ObjectId($_id)], ['limit' => 1]);

			$mCol = $this->db . "."  . $entity;

			$m->executeBulkWrite($mCol, $bulk);
		}
		catch (Exception $e) {
			$this->_log->addError($e->getMessage());
		    $retValue = false;
		}

		return $retValue;
	}
1207857
static function removeRelationObject( $contentObjectAttribute, $deletionItem )
    {
        if ( self::isItemPublished( $deletionItem ) )
        {
            return;
        }

        $hostObject = $contentObjectAttribute->attribute( 'object' );
        $hostObjectID = $hostObject->attribute( 'id' );

        // Do not try removing the object if present in trash
        // Only objects being really orphaned (not even being in trash) should be removed by this method.
        // See issue #019457
        if (
            (int)eZPersistentObject::count(
                eZContentObjectTrashNode::definition(),
                array( "contentobject_id" => $hostObjectID )
            ) > 0
        )
        {
            return;
        }

        $hostObjectVersions = $hostObject->versions();
        $isDeletionAllowed = true;

        // check if the relation item to be deleted is unique in the domain of all host-object versions
        foreach ( $hostObjectVersions as $version )
        {
            if ( $isDeletionAllowed and
                 $version->attribute( 'version' ) != $contentObjectAttribute->attribute( 'version' ) )
            {
                $relationAttribute = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
                                                                           null,
                                                                           array( 'version' => $version->attribute( 'version' ),
                                                                                  'contentobject_id' => $hostObjectID,
                                                                                  'contentclassattribute_id' => $contentObjectAttribute->attribute( 'contentclassattribute_id' ) ) );

                if ( count( $relationAttribute ) > 0 )
                {
                    $relationContent = $relationAttribute[0]->content();
                    if ( is_array( $relationContent ) and
                         is_array( $relationContent['relation_list'] ) )
                    {
                        foreach( $relationContent['relation_list'] as $relationItem )
                        {
                            if ( $deletionItem['contentobject_id'] == $relationItem['contentobject_id'] &&
                                 $deletionItem['contentobject_version'] == $relationItem['contentobject_version'] )
                            {
                                $isDeletionAllowed = false;
                                break 2;
                            }
                        }
                    }
                }
            }
        }

        if ( $isDeletionAllowed )
        {
            $subObjectVersion = eZContentObjectVersion::fetchVersion( $deletionItem['contentobject_version'],
                                                                      $deletionItem['contentobject_id'] );
            if ( $subObjectVersion instanceof eZContentObjectVersion )
            {
                $subObjectVersion->removeThis();
            }
            else
            {
                eZDebug::writeError( 'Cleanup of subobject-version failed. Could not fetch object from relation list.\n' .
                                     'Requested subobject id: ' . $deletionItem['contentobject_id'] . '\n' .
                                     'Requested Subobject version: ' . $deletionItem['contentobject_version'],
                                     __METHOD__ );
            }
        }
    }
471014
public function delete($id)
    {
        if ($id instanceof Zend_Search_Lucene_Search_QueryHit) {
            /* @var $id Zend_Search_Lucene_Search_QueryHit */
            $id = $id->id;
        }

        if ($id >= $this->_docCount) {
            include_once 'Zend/Search/Lucene/Exception.php';
            throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
        }

        $segmentStartId = 0;
        foreach ($this->_segmentInfos as $segmentInfo) {
            if ($segmentStartId + $segmentInfo->count() > $id) {
                break;
            }

            $segmentStartId += $segmentInfo->count();
        }
        $segmentInfo->delete($id - $segmentStartId);

        $this->_hasChanges = true;
    }
1011055
public static function tearDown()
    {
        $dm = static::$dm;

        if (is_null($dm)) {
            return;
        }

        $documents = [
            'Applications\Entity\Application',
            'Cv\Entity\Cv',
            'Jobs\Entity\Job',
            'Organizations\Entity\Organization',
            'Auth\Entity\User',
            'Jobs\Entity\Category',
            'Auth\Entity\UserImage',
            'Organizations\Entity\OrganizationName',
        ];
        foreach ($documents as $document) {
            try {
                $dm->createQueryBuilder($document)
                    ->remove()
                    ->getQuery()
                    ->execute()
                ;
            } catch (\Exception $e) {
            }
        }
    }
38546
public function setDomDocument(\DOMDocument $document)
    {
        if (isset($this->document) && $this->document !== $document) {
            throw new \Exception('Other DOMDocument already set!');
        }

        $this->document = $document;
    }
577069
public function activate($idOrDocument) 
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$document = $this->getEntity($idOrDocument);
		
		/**
		 * Activate ONLY IF document was never activated yet
		 * Do not check for edit to be equal as insert, may cause 
		 * problem if an admin edited a never activated classified
		 */ 
// 		if(!($document->getState() == Document::DOCUMENT_STATE_DEACTIVE && 
// 			$document->getDateEdit() == $document->getDateInsert())) {
		if($document->getState() != Document::DOCUMENT_STATE_DEACTIVE) {
			throw new \Exception('Non è possibile attivare questo annuncio, probabilmente è già stato attivato');
		}
		
		$document->setState(Document::DOCUMENT_STATE_ACTIVE);
		
		$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
		$classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
		$classifiedModel->init($document, $this->getServiceLocator());
		$event = new ClassifiedActivatedEvent(__FUNCTION__, null, array(
		    'to' => $classifiedModel->email,
		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
		    'fullname' => $classifiedModel->fullname,
		    'title' => $classifiedModel->title
		));
		$this->getEventManager()->trigger('classifiedActivated.pre', $this, $event);
		
		if($cache->hasItem($classifiedModel->hashId)) {
			$cache->removeItem($classifiedModel->hashId);
		}

		$em->persist($document);
		$em->flush();
		
		$this->getEventManager()->trigger('classifiedActivated.post', $this, $event);
		
		return $document;
    }
192118
def delete(self):
        
        if self.abstract:
            raise AbstractDocumentException()

        self._api.delete_document(self.id)
        self._id = None

        return True
77964
public function deleteAction($id)
    {
        $contentType = $this->contentTypeManager->getContentTypeById($id);

        if ($contentType === null) {
            throw EntityNotFoundException::fromClassNameAndIdentifier(
                $this->configurationManager->getEntityClass('content_type'),
                [$id]
            );
        }

        $this->om->remove($contentType);
        $this->om->flush();

        return $this->redirectToRoute('sherlockode_acb_content_type_list');
    }