Exemplo n.º 1
0
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return mixed
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $sourcePatterns = [];
     $destinationPatters = [];
     foreach ($this->source->getDocumentList() as $document) {
         $destDocumentName = $this->map->getDocumentMap($document, MapInterface::TYPE_SOURCE);
         if ($destDocumentName === false) {
             continue;
         }
         $sourcePatterns[] = sprintf('`%s`', $this->source->addDocumentPrefix($document));
         $destinationPatters[] = sprintf('`%s`', $this->destination->addDocumentPrefix($destDocumentName));
     }
     $newValue = str_replace($sourcePatterns, $destinationPatters, $recordToHandle->getValue($this->field));
     $recordToHandle->setValue($this->field, $newValue);
 }
Exemplo n.º 2
0
 /**
  * @return bool
  */
 public function perform()
 {
     $sourceDocuments = array_keys($this->helper->getDocumentList());
     $this->progress->start(count($sourceDocuments));
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progress->advance();
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $this->checkMapEntities($sourceDocName, $destinationName);
         $this->checkEavEntities();
     }
     $this->progress->finish();
     return $this->checkForErrors();
 }
Exemplo n.º 3
0
 /**
  * Delete backed up documents
  * @return void
  */
 public function deleteBackups()
 {
     foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) {
         $documentName = $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE);
         if ($documentName) {
             $this->destination->deleteDocumentBackup($documentName);
         }
     }
 }
 /**
  * @param string $sourceDocName
  * @param array $keyFields
  * @return array
  */
 public function getDestinationRecords($sourceDocName, $keyFields = [])
 {
     $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
     $data = [];
     $count = $this->destination->getRecordsCount($destinationDocumentName);
     foreach ($this->destination->getRecords($destinationDocumentName, 0, $count) as $row) {
         if ($keyFields) {
             $key = [];
             foreach ($keyFields as $keyField) {
                 $key[] = $row[$keyField];
             }
             $data[implode('-', $key)] = $row;
         } else {
             $data[] = $row;
         }
     }
     return $data;
 }
Exemplo n.º 5
0
 /**
  * Rollback backed up documents
  * @return void
  */
 public function rollback()
 {
     foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) {
         $destinationDocument = $this->destination->getDocument($this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE));
         if ($destinationDocument !== false) {
             $this->destination->rollbackDocument($destinationDocument->getName());
         }
     }
 }
 /**
  * @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();
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $sourceDocuments = $this->source->getDocumentList();
     $this->progressBar->start(count($sourceDocuments));
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progressBar->advance();
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $sourceCount = $this->source->getRecordsCount($sourceDocName);
         $destinationCount = $this->destination->getRecordsCount($destinationName);
         if ($sourceCount != $destinationCount) {
             $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName;
         }
     }
     $this->progressBar->finish();
     return $this->checkForErrors();
 }
Exemplo n.º 8
0
 /**
  * Volume check
  *
  * @return bool
  */
 public function perform()
 {
     $sourceDocuments = array_keys($this->groups->getGroup('source_documents'));
     $this->progress->start(count($sourceDocuments));
     foreach ($sourceDocuments as $sourceName) {
         $this->progress->advance();
         $destinationName = $this->map->getDocumentMap($sourceName, MapInterface::TYPE_SOURCE);
         $sourceFields = $this->source->getDocument($sourceName)->getStructure()->getFields();
         $destinationFields = $this->destination->getDocument($destinationName)->getStructure()->getFields();
         if (!empty(array_diff_key($sourceFields, $destinationFields))) {
             $this->errors[] = 'Mismatch of fields in the document: ' . $destinationName;
         }
         if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) {
             $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName;
         }
     }
     $this->progress->finish();
     return $this->checkForErrors();
 }
Exemplo n.º 9
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progressBar->start(count($this->source->getDocumentList()), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = $this->source->getDocumentList();
     $stage = 'run';
     $processedDocuments = $this->progress->getProcessedEntities($this, $stage);
     foreach (array_diff($sourceDocuments, $processedDocuments) as $sourceDocName) {
         $this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
         $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);
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
         $doCopy = $recordTransformer === null && $this->copyDirectly;
         if ($doCopy && $this->isCopiedDirectly($sourceDocument, $destDocument)) {
             $this->progressBar->start(1, LogManager::LOG_LEVEL_DEBUG);
         } else {
             $pageNumber = 0;
             $this->progressBar->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG);
             while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) {
                 $pageNumber++;
                 $destinationRecords = $destDocument->getRecords();
                 foreach ($items as $data) {
                     if ($recordTransformer) {
                         /** @var Record $record */
                         $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]);
                         /** @var Record $destRecord */
                         $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                         $recordTransformer->transform($record, $destRecord);
                     } else {
                         $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]);
                     }
                     $destinationRecords->addRecord($destRecord);
                 }
                 $this->source->setLastLoadedRecord($sourceDocName, end($items));
                 $this->progressBar->advance(LogManager::LOG_LEVEL_DEBUG);
                 $fieldsUpdateOnDuplicate = $this->helper->getFieldsUpdateOnDuplicate($destinationName);
                 $this->destination->saveRecords($destinationName, $destinationRecords, $fieldsUpdateOnDuplicate);
             }
         }
         $this->source->setLastLoadedRecord($sourceDocName, []);
         $this->progress->addProcessedEntity($this, $stage, $sourceDocName);
         $this->progressBar->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progressBar->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Exemplo n.º 10
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progressBar->start(count($this->source->getDocumentList()), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = $this->source->getDocumentList();
     // TODO: during steps refactoring MAGETWO-35749 stage will be removed
     $stage = 'run';
     $processedDocuments = $this->progress->getProcessedEntities($this, $stage);
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
         if (in_array($sourceDocName, $processedDocuments)) {
             continue;
         }
         $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);
         $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progressBar->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($items as $data) {
                 $this->progressBar->advance(LogManager::LOG_LEVEL_DEBUG);
                 if ($recordTransformer) {
                     /** @var Record $record */
                     $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]);
                     /** @var Record $destRecord */
                     $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                     $recordTransformer->transform($record, $destRecord);
                 } else {
                     $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]);
                 }
                 $destinationRecords->addRecord($destRecord);
             }
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->addProcessedEntity($this, $stage, $sourceDocName);
         $this->progressBar->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progressBar->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
 /**
  * Run step
  *
  * @return bool
  */
 public function perform()
 {
     /** @var \Migration\ResourceModel\Adapter\Mysql $sourceAdapter */
     $sourceAdapter = $this->source->getAdapter();
     /** @var \Migration\ResourceModel\Adapter\Mysql $destinationAdapter */
     $destinationAdapter = $this->destination->getAdapter();
     $sourceDocuments = array_keys($this->groups->getGroup('source_documents'));
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     foreach ($sourceDocuments as $sourceDocumentName) {
         $destinationDocumentName = $this->map->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE);
         $sourceTable = $sourceAdapter->getTableDdlCopy($this->source->addDocumentPrefix($sourceDocumentName), $this->destination->addDocumentPrefix($destinationDocumentName));
         $destinationTable = $destinationAdapter->getTableDdlCopy($this->destination->addDocumentPrefix($destinationDocumentName), $this->destination->addDocumentPrefix($destinationDocumentName));
         foreach ($sourceTable->getColumns() as $columnData) {
             $destinationTable->setColumn($columnData);
         }
         $destinationAdapter->createTableByDdl($destinationTable);
         $destinationDocument = $this->destination->getDocument($destinationDocumentName);
         $this->logger->debug('migrating', ['table' => $sourceDocumentName]);
         $pageNumber = 0;
         $this->progress->start($this->source->getRecordsCount($sourceDocumentName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($sourceRecords = $this->source->getRecords($sourceDocumentName, $pageNumber))) {
             $pageNumber++;
             $recordsToSave = $destinationDocument->getRecords();
             foreach ($sourceRecords as $recordData) {
                 $this->progress->advance(LogManager::LOG_LEVEL_INFO);
                 $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
                 /** @var Record $destinationRecord */
                 $destinationRecord = $this->recordFactory->create(['document' => $destinationDocument]);
                 $destinationRecord->setData($recordData);
                 $recordsToSave->addRecord($destinationRecord);
             }
             $this->destination->saveRecords($destinationDocument->getName(), $recordsToSave);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Exemplo n.º 14
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);
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         $sourceDocumentName = $sourceDocument->getName();
         /** @var \Magento\Framework\DB\Select $select */
         $select = $this->getLogDataSelect();
         while (!empty($bulk = $this->getRecords($sourceDocumentName, $select, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($bulk as $recordData) {
                 $this->progress->advance(LogManager::LOG_LEVEL_INFO);
                 $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $recordData]);
                 $destinationRecords->addRecord($destRecord);
             }
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->clearLog(array_keys($this->readerGroups->getGroup('destination_documents_to_clear')));
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
 /**
  * @param string $sourceDocumentName
  * @return mixed
  */
 protected function getDestDocumentName($sourceDocumentName)
 {
     return $this->mapMain->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE) ? $this->mapMain->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE) : $this->mapSalesOrder->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE);
 }