/** * {@inheritdoc} */ public function write(array $products) { $this->collection = $this->documentManager->getDocumentCollection($this->productClass); $productsToInsert = array(); $productsToUpdate = array(); foreach ($products as $product) { if (null === $product->getId()) { $productsToInsert[] = $product; $product->setId($this->mongoFactory->createMongoId()); } else { $productsToUpdate[] = $product; } } $this->productManager->handleAllMedia($products); $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(); }
/** * {@inheritdoc} */ public function write(array $items) { $this->versionManager->setRealTimeVersioning($this->realTimeVersioning); foreach ($items as $item) { $this->incrementCount($item); } $this->productManager->handleAllMedia($items); $this->productManager->saveAllProducts($items, ['recalculate' => false]); $this->cacheClearer->clear(); }
/** * {@inheritdoc} */ public function perform() { parent::perform(); $this->productManager->handleAllMedia($this->objects); }