Closes the DocumentManager. All documents that are currently managed
by this DocumentManager become detached. The DocumentManager may no longer
be used after it is closed.
public close ( ) |
/** * @param Doctrine\ODM\MongoDB\DocumentManager $documentManager */ private function _save(DocumentManager $documentManager) { try { if ($this->queue->count() <= 0) { $this->getLog()->debug('Queue contains no documents for processing.'); return; } $this->getLog()->debug('Queue contains: ' . $this->queue->count() . ' documents.'); foreach ($this->queue as $object) { $name = $object->getName(); $_id = $object->getId(); if (empty($_id)) { $document = $object->getInstance(); $this->getLog()->info('Saving document: ' . $name . ' (' . $document->__toString() . ')'); //Debug::dump($document, 3); $documentManager->persist($document); $documentManager->flush(); $documentId = $document->getId(); if (!empty($name) && !empty($documentId)) { $this->getLog()->info('Marking document: ' . $name . ' (' . get_class($document) . ') as persisted in cache with ID: ' . $documentId); $this->markAsPersisted($name, $documentId, $document); } } } $this->queue->clear(); $this->getLog()->debug('Finished saving documents, queue now contains: ' . $this->queue->count() . ' documents.'); } catch (\Exception $ex) { $this->getLog()->err('An error occurred while attempting to save one or more documents. ' . get_class($ex) . ' handled, with message: ' . $ex->getMessage()); $documentManager->close(); throw $ex; } }