Ejemplo n.º 1
0
 /**
  * @param Document $sourceDocument
  * @param Document $destDocument
  * @return \Migration\RecordTransformer
  */
 public function getRecordTransformer(Document $sourceDocument, Document $destDocument)
 {
     if ($this->canJustCopy($sourceDocument, $destDocument)) {
         return null;
     }
     /** @var \Migration\RecordTransformer $recordTransformer */
     $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
     $recordTransformer->init();
     return $recordTransformer;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * Entry point. Run migration of SalesOrder structure.
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = array_keys($this->helper->getDocumentList());
     foreach ($sourceDocuments as $sourceDocName) {
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationDocumentName) {
             continue;
         }
         $destDocument = $this->destination->getDocument($destinationDocumentName);
         $this->destination->clearDocument($destinationDocumentName);
         $eavDocumentName = $this->helper->getDestEavDocument();
         $eavDocumentResource = $this->destination->getDocument($eavDocumentName);
         /** @var \Migration\RecordTransformer $recordTransformer */
         $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
         $recordTransformer->init();
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationCollection = $destDocument->getRecords();
             $destEavCollection = $eavDocumentResource->getRecords();
             foreach ($bulk as $recordData) {
                 $this->progress->advance(LogManager::LOG_LEVEL_INFO);
                 $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
                 /** @var Record $sourceRecord */
                 $sourceRecord = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                 $recordTransformer->transform($sourceRecord, $destRecord);
                 $destinationCollection->addRecord($destRecord);
                 $this->migrateAdditionalOrderData($recordData, $sourceDocument, $destEavCollection);
             }
             $this->destination->saveRecords($destinationDocumentName, $destinationCollection);
             $this->destination->saveRecords($eavDocumentName, $destEavCollection);
             $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
         }
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destinationDocument
  * @return \Migration\RecordTransformer
  */
 protected function getRecordTransformer($sourceDocument, $destinationDocument)
 {
     $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destinationDocument, 'mapReader' => $this->mapReader]);
     $recordTransformer->init();
     return $recordTransformer;
 }
Ejemplo n.º 5
0
 /**
  * @param Document $sourceDocument
  * @param Document $destinationDocument
  * @return RecordTransformer
  */
 public function getRecordTransformer($sourceDocument, $destinationDocument)
 {
     return $this->factory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destinationDocument, 'mapReader' => $this->map])->init();
 }