/**
  * Tests key() method.
  */
 public function testKey()
 {
     $this->syncStorage->expects($this->once())->method('getChunk')->will($this->returnValue([0 => ['document_id' => 11, 'type' => ActionTypes::DELETE]]));
     $iterator = new SyncStorageImportIterator(['sync_storage' => $this->syncStorage, 'shop_id' => 1, 'document_type' => 'product'], $this->elasticsearchRepository, $this->entityManager, 'Product');
     $iterator->next();
     $this->assertEquals(11, $iterator->key());
 }
Пример #2
0
 /**
  * Test getChunk action.
  */
 public function testSyncStorageGetChunk()
 {
     $valueMap = [[1, null, null, [1]], [2, null, null, [1, 2]], [0, null, null, null]];
     $this->storageManager->expects($this->exactly(count($valueMap) - 1))->method('getNextRecords')->will($this->returnValueMap($valueMap));
     foreach ($valueMap as $record) {
         $records = $this->service->getChunk($record[0], $record[1], $record[2]);
         $this->assertEquals(count($record[3]), count($records));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function next()
 {
     $this->currentChunk = $this->syncStorage->getChunk(1, $this->documentType, $this->shopId);
     if (empty($this->currentChunk)) {
         $this->valid = false;
         return;
     }
     $this->currentEntity = $this->entityManager->getRepository($this->entityClass)->find($this->currentChunk[0]['document_id']);
     if (!empty($this->currentEntity) || $this->currentChunk[0]['type'] == ActionTypes::DELETE) {
         $this->valid = true;
         return;
     }
     $this->valid = false;
 }
 /**
  * {@inheritdoc}
  */
 protected function persistDocument()
 {
     switch ($this->syncStorageData['type']) {
         case ActionTypes::CREATE:
             $this->manager->persist($this->importItem->getDocument());
             break;
         case ActionTypes::UPDATE:
             $this->manager->persist($this->importItem->getDocument());
             break;
         case ActionTypes::DELETE:
             $this->manager->getRepository($this->documentType)->remove($this->importItem->getDocument()->getId());
             break;
         default:
             $this->log(sprintf('Failed to update document of type  %s id: %s: no valid operation type defined', get_class($this->importItem->getDocument()), $this->importItem->getDocument()->getId()));
             return false;
     }
     $this->syncStorage->deleteItem($this->syncStorageData['id'], [$this->syncStorageData['shop_id']]);
     return true;
 }