clear() public method

All documents that are currently managed by this DocumentManager become detached.
public clear ( string | null $documentName = null )
$documentName string | null if given, only documents of this type will get detached
Beispiel #1
0
 /**
  * @param User $user
  * @param Router $router
  * @return \Zend\EventManager\ResponseCollection
  */
 public function removeItems(User $user)
 {
     try {
         $this->getEventManager()->trigger(static::EVENT_REMOVE_ITEMS, $this, compact('user'));
         $this->documentManager->flush();
         return true;
     } catch (\Exception $e) {
         $this->documentManager->clear();
         return false;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $products)
 {
     $this->collection = $this->documentManager->getDocumentCollection($this->productClass);
     $productsToInsert = [];
     $productsToUpdate = [];
     foreach ($products as $product) {
         if (null === $product->getId()) {
             $productsToInsert[] = $product;
             $product->setId($this->mongoFactory->createMongoId());
         } else {
             $productsToUpdate[] = $product;
         }
     }
     $this->eventDispatcher->dispatch(self::PRE_INSERT, new GenericEvent($productsToInsert));
     $this->eventDispatcher->dispatch(self::PRE_UPDATE, new GenericEvent($productsToUpdate));
     $insertDocs = $this->getDocsFromProducts($productsToInsert);
     $updateDocs = $this->getDocsFromProducts($productsToUpdate);
     if (count($insertDocs) > 0) {
         $this->insertDocuments($insertDocs);
     }
     if (count($updateDocs) > 0) {
         $this->updateDocuments($updateDocs);
     }
     $this->pendingPersister->persistPendingVersions($products);
     $this->eventDispatcher->dispatch(self::POST_INSERT, new GenericEvent($productsToInsert));
     $this->eventDispatcher->dispatch(self::POST_UPDATE, new GenericEvent($productsToUpdate));
     $this->documentManager->clear();
     $this->cacheClearer->clear();
 }
 /**
  * @param BasicQuestion $question
  *
  * @return CorrectAnswer
  */
 private function persistQuestionWithAnswer(BasicQuestion $question)
 {
     $a = new CorrectAnswer();
     $a->text = 'a text';
     $this->dm->persist($a);
     $question->answer = $a;
     $this->dm->persist($question);
     $this->dm->flush();
     $this->dm->clear();
     return $a;
 }
Beispiel #4
0
 /**
  * @return Folder[]
  */
 function methodB()
 {
     $a = $this->getFolder('a');
     $b = $this->getFolder('b');
     foreach ($a->getFiles() as $file) {
         if ($file->getOrder() === 1) {
             $a->removeFile($file);
             $this->dm->detach($file);
             $b->addFile($file);
             $this->dm->flush();
             $this->dm->clear();
             return array($a, $b);
         }
     }
     throw new \RuntimeException('Test folder A has run out of files!');
 }
 /**
  * Clears the repository, causing all managed documents to become detached.
  */
 public function clear()
 {
     $this->dm->clear($this->class->rootDocumentName);
 }
 /**
  * {@inheritdoc}
  */
 public function initialize()
 {
     $this->query = null;
     $this->documentManager->clear();
     $this->executed = false;
 }
 /**
  * {@inheritdoc}
  */
 public function clear($entityName = null)
 {
     $this->dm->clear($entityName);
 }
Beispiel #8
0
 /**
  * @param Item $item
  */
 public function onDelete(Item $item)
 {
     $this->im->getRepository()->removeAllSimilarReferencesForItem($item);
     $this->dm->clear();
 }
Beispiel #9
0
 /**
  * Tear down document manager
  *
  * @param Doctrine\ODM\MongoDB\DocumentManager $odm
  * @return void
  */
 protected function tearDownOdm(\Doctrine\ODM\MongoDB\DocumentManager $odm)
 {
     $odm->getSchemaManager()->dropDatabases();
     $odm->clear();
 }