Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function processChangedRecords($documentName, $idKey)
 {
     $items = $this->source->getChangedRecords($documentName, $idKey);
     if (empty($items)) {
         return;
     }
     if (!$this->eolOnce) {
         $this->eolOnce = true;
         echo PHP_EOL;
     }
     $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE);
     $attributeType = $this->helper->getAttributeType($documentName);
     $sourceDocument = $this->source->getDocument($documentName);
     $destDocument = $this->destination->getDocument($destinationName);
     $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
     do {
         $destinationRecords = $destDocument->getRecords();
         $ids = [];
         foreach ($items as $data) {
             echo '.';
             $ids[] = $data[$idKey];
             if ($this->helper->isSkipRecord($attributeType, $documentName, $data)) {
                 continue;
             }
             $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords);
         }
         $this->helper->updateAttributeData($attributeType, $documentName, $destinationRecords);
         $this->destination->updateChangedRecords($destinationName, $destinationRecords);
         $documentNameDelta = $this->source->getDeltaLogName($documentName);
         $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta);
         $this->markRecordsProcessed($documentNameDelta, $idKey, $ids);
     } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey)));
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents'));
     $this->progress->start($this->getIterationsCount());
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progress->advance();
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $sourceCount = $this->helper->getSourceRecordsCount($sourceDocName);
         $destinationCount = $this->destination->getRecordsCount($destinationName);
         if ($sourceCount != $destinationCount) {
             $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName;
         }
     }
     $this->progress->finish();
     return $this->checkForErrors();
 }
 /**
  * Init EAV attributes
  * @return void
  */
 protected function getAttributeType()
 {
     $entities = [self::ENTITY => ''];
     $documentGroups = [self::ATTRIBUTE => ''];
     $this->readerGroups->expects($this->at(0))->method('getGroup')->with('eav_entities')->willReturn($entities);
     $this->readerGroups->expects($this->at(1))->method('getGroup')->with(self::ENTITY)->willReturn($this->sourceDocuments);
     $this->source->expects($this->any())->method('getAdapter')->willReturn($this->adapter);
     $this->adapter->expects($this->at(1))->method('fetchAll')->with($this->select)->willReturn($this->attribute);
     $this->readerAttributes->expects($this->any())->method('getGroup')->willReturn($documentGroups);
     $this->helper->getAttributeType(self::DOCUMENT);
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $messages = [];
     $this->progress->start($this->getIterationsCount());
     $srcDocuments = array_keys($this->readerGroups->getGroup('source_documents'));
     $dstDocuments = [];
     foreach ($srcDocuments as $sourceDocumentName) {
         $dstDocuments[] = $this->map->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE);
         try {
             $this->helper->getAttributeType($sourceDocumentName);
         } catch (\Migration\Exception $e) {
             $messages[] = $e->getMessage();
         }
         $this->progress->advance();
     }
     $this->check($srcDocuments, MapInterface::TYPE_SOURCE);
     $this->check($dstDocuments, MapInterface::TYPE_DEST);
     $this->progress->finish();
     foreach ($messages as $message) {
         $this->logger->error($message);
     }
     return $this->checkForErrors() && empty($messages);
 }
Example #5
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents'));
     foreach ($sourceDocuments as $sourceDocName) {
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $destDocument = $this->destination->getDocument($destinationName);
         $this->destination->clearDocument($destinationName);
         /** @var \Migration\RecordTransformer $recordTransformer */
         $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
         $recordTransformer->init();
         $attributeType = $this->helper->getAttributeType($sourceDocName);
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($bulk as $recordData) {
                 $this->source->setLastLoadedRecord($sourceDocName, $recordData);
                 if ($this->helper->isSkipRecord($attributeType, $sourceDocName, $recordData)) {
                     continue;
                 }
                 /** @var Record $record */
                 $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                 $recordTransformer->transform($record, $destRecord);
                 $destinationRecords->addRecord($destRecord);
             }
             $this->progress->advance(LogManager::LOG_LEVEL_INFO);
             $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
             $this->helper->updateAttributeData($attributeType, $sourceDocName, $destinationRecords);
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->helper->updateEavAttributes();
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }