Example #1
0
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return void
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $ids = explode(',', $recordToHandle->getValue($this->field));
     $normalizedRecords = [];
     foreach ($ids as $id) {
         $normalizedRecords[] = ['rule_id' => $recordToHandle->getValue('rule_id'), $this->normalizationField => $id];
     }
     if ($normalizedRecords) {
         $this->destination->clearDocument($this->normalizationDocument);
         $this->destination->saveRecords($this->normalizationDocument, $normalizedRecords);
     }
 }
Example #2
0
 public function testClearDocument()
 {
     $docName = 'somename';
     $this->adapter->expects($this->once())->method('deleteAllRecords')->with('pfx_' . $docName);
     $this->config->expects($this->once())->method('getOption')->with('dest_prefix')->will($this->returnValue('pfx_'));
     $this->resourceDestination->clearDocument($docName);
 }
Example #3
0
 /**
  * @param array $documents
  * @return void
  */
 protected function clearLog($documents)
 {
     foreach ($documents as $documentName) {
         $this->progress->advance();
         $this->destination->clearDocument($documentName);
     }
 }
 /**
  * @return bool
  */
 protected function data()
 {
     $this->progress->start(count($this->getDocumentList()));
     $documents = $this->getDocumentList();
     foreach ($documents as $sourceDocName => $destDocName) {
         $this->progress->advance();
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationDocument = $this->destination->getDocument($destDocName);
         $this->destination->clearDocument($destDocName);
         $pageNumber = 0;
         while (!empty($sourceRecords = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $recordsToSave = $destinationDocument->getRecords();
             foreach ($sourceRecords as $recordData) {
                 /** @var Resource\Record $destinationRecord */
                 $destinationRecord = $this->recordFactory->create(['document' => $destinationDocument]);
                 if ($this->haveEqualStructure($sourceDocument, $destinationDocument)) {
                     $destinationRecord->setData($recordData);
                 } else {
                     $destinationRecord = $this->transformRecord($destinationRecord, $recordData);
                 }
                 $recordsToSave->addRecord($destinationRecord);
             }
             $this->destination->saveRecords($destinationDocument->getName(), $recordsToSave);
         }
     }
     $this->progress->finish();
     return true;
 }
Example #5
0
 /**
  * Run step
  *
  * @return bool
  */
 protected function data()
 {
     $this->progress->start($this->source->getRecordsCount(self::SOURCE));
     $sourceDocument = $this->source->getDocument(self::SOURCE);
     $destDocument = $this->destination->getDocument(self::DESTINATION);
     $destProductCategory = $this->destination->getDocument(self::DESTINATION_PRODUCT_CATEGORY);
     $this->destination->clearDocument(self::DESTINATION);
     $this->destination->clearDocument(self::DESTINATION_PRODUCT_CATEGORY);
     $pageNumber = 0;
     while (!empty($bulk = $this->source->getRecords(self::SOURCE, $pageNumber))) {
         $pageNumber++;
         $destinationRecords = $destDocument->getRecords();
         $destProductCategoryRecords = $destProductCategory->getRecords();
         foreach ($bulk as $recordData) {
             $this->progress->advance();
             /** @var Record $record */
             $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]);
             /** @var Record $destRecord */
             $destRecord = $this->recordFactory->create(['document' => $destDocument]);
             $this->transform($record, $destRecord);
             if ($record->getValue('is_system') && $record->getValue('product_id') && $record->getValue('category_id')) {
                 $destProductCategoryRecord = $this->recordFactory->create(['document' => $destProductCategory]);
                 $destProductCategoryRecord->setValue('url_rewrite_id', $record->getValue('url_rewrite_id'));
                 $destProductCategoryRecord->setValue('category_id', $record->getValue('category_id'));
                 $destProductCategoryRecord->setValue('product_id', $record->getValue('product_id'));
                 $destProductCategoryRecords->addRecord($destProductCategoryRecord);
             }
             $destinationRecords->addRecord($destRecord);
         }
         $this->destination->saveRecords(self::DESTINATION, $destinationRecords);
         $this->destination->saveRecords(self::DESTINATION_PRODUCT_CATEGORY, $destProductCategoryRecords);
     }
     $this->progress->finish();
     return true;
 }
Example #6
0
 /**
  * @return bool
  * @throws \Migration\Exception
  */
 protected function data()
 {
     $destinationDocument = $this->destination->getDocument(self::CONFIG_TABLE_NAME_DESTINATION);
     $recordsCountSource = $this->source->getRecordsCount(self::CONFIG_TABLE_NAME_SOURCE);
     $recordsCountDestination = $this->destination->getRecordsCount(self::CONFIG_TABLE_NAME_DESTINATION);
     $this->progress->start($recordsCountSource);
     $sourceRecords = $this->source->getRecords(self::CONFIG_TABLE_NAME_SOURCE, 0, $recordsCountSource);
     $destinationRecords = $this->destination->getRecords(self::CONFIG_TABLE_NAME_DESTINATION, 0, $recordsCountDestination);
     foreach ($sourceRecords as $sourceRecord) {
         $this->progress->advance();
         if (!$this->readerSettings->isNodeIgnored($sourceRecord[self::CONFIG_FIELD_PATH])) {
             $sourceRecordPathMapped = $this->readerSettings->getNodeMap($sourceRecord[self::CONFIG_FIELD_PATH]);
             foreach ($destinationRecords as &$destinationRecord) {
                 if ($destinationRecord[self::CONFIG_FIELD_SCOPE] == $sourceRecord[self::CONFIG_FIELD_SCOPE] && $destinationRecord[self::CONFIG_FIELD_SCOPE_ID] == $sourceRecord[self::CONFIG_FIELD_SCOPE_ID] && $destinationRecord[self::CONFIG_FIELD_PATH] == $sourceRecordPathMapped) {
                     $record = $this->applyHandler($destinationDocument, $sourceRecord, $destinationRecord);
                     $destinationRecord[self::CONFIG_FIELD_VALUE] = $record->getValue(self::CONFIG_FIELD_VALUE);
                     continue 2;
                 }
             }
             $record = $this->applyHandler($destinationDocument, $sourceRecord, []);
             $record->setValue(self::CONFIG_FIELD_PATH, $sourceRecordPathMapped);
             $destinationRecords[] = $record->getData();
         }
     }
     foreach ($destinationRecords as &$destinationRecord) {
         unset($destinationRecord[self::CONFIG_FIELD_CONFIG_ID]);
     }
     $this->destination->clearDocument(self::CONFIG_TABLE_NAME_DESTINATION);
     $this->destination->saveRecords(self::CONFIG_TABLE_NAME_DESTINATION, $destinationRecords);
     $this->progress->finish();
     return true;
 }
Example #7
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     foreach ($this->getDocumentList() as $methodToExecute => $document) {
         $destinationDocumentName = $document['destination'];
         $this->destination->clearDocument($destinationDocumentName);
         $this->progress->start(1, LogManager::LOG_LEVEL_DEBUG);
         $sourceGridDocument = array_flip($this->helper->getDocumentList())[$destinationDocumentName];
         $entityIds = $this->getEntityIdsFromSourceGrid($sourceGridDocument);
         if ($entityIds) {
             $this->destination->getAdapter()->insertFromSelect($this->{$methodToExecute}($document['columns'], $entityIds), $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Example #8
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);
                 $this->destination->saveRecords($destinationName, $destinationRecords);
             }
         }
         $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;
 }
Example #9
0
 /**
  * Migrate EAV tables which in result must have all unique records from both source and destination documents
  * @return void
  */
 protected function migrateMappedTables()
 {
     $documents = $this->readerGroups->getGroup('mapped_documents');
     foreach ($documents as $documentName => $mappingFields) {
         $this->progress->advance();
         $sourceDocument = $this->source->getDocument($documentName);
         $destinationDocument = $this->destination->getDocument($this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE));
         $this->destination->backupDocument($destinationDocument->getName());
         $mappingFields = explode(',', $mappingFields);
         $destinationRecords = $this->helper->getDestinationRecords($documentName, $mappingFields);
         $recordsToSave = $destinationDocument->getRecords();
         foreach ($this->helper->getSourceRecords($documentName) as $recordData) {
             /** @var Record $sourceRecord */
             $sourceRecord = $this->factory->create(['document' => $sourceDocument, 'data' => $recordData]);
             /** @var Record $destinationRecord */
             $destinationRecord = $this->factory->create(['document' => $destinationDocument]);
             $mappingValue = $this->getMappingValue($sourceRecord, $mappingFields);
             if (isset($destinationRecords[$mappingValue])) {
                 $destinationRecordData = $destinationRecords[$mappingValue];
                 unset($destinationRecords[$mappingValue]);
             } else {
                 $destinationRecordData = array_fill_keys($destinationRecord->getFields(), null);
             }
             $destinationRecord->setData($destinationRecordData);
             $this->helper->getRecordTransformer($sourceDocument, $destinationDocument)->transform($sourceRecord, $destinationRecord);
             if ($documentName == 'eav_entity_type') {
                 $oldAttributeSetValue = $destinationRecord->getValue('default_attribute_set_id');
                 if (isset($this->destAttributeSetsOldNewMap[$oldAttributeSetValue])) {
                     $destinationRecord->setValue('default_attribute_set_id', $this->destAttributeSetsOldNewMap[$oldAttributeSetValue]);
                 }
             }
             $recordsToSave->addRecord($destinationRecord);
         }
         $this->destination->clearDocument($destinationDocument->getName());
         $this->saveRecords($destinationDocument, $recordsToSave);
         $recordsToSave = $destinationDocument->getRecords();
         if ($mappingFields) {
             foreach ($destinationRecords as $record) {
                 $destinationRecord = $this->factory->create(['document' => $destinationDocument, 'data' => $record]);
                 if (isset($record['attribute_id']) && isset($this->destAttributeOldNewMap[$record['attribute_id']])) {
                     $destinationRecord->setValue('attribute_id', $this->destAttributeOldNewMap[$record['attribute_id']]);
                 }
                 $recordsToSave->addRecord($destinationRecord);
             }
         }
         $this->saveRecords($destinationDocument, $recordsToSave);
     }
 }
Example #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;
 }
Example #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;
 }
Example #12
0
 /**
  * @param Document $document
  * @param Record\Collection $recordsToSave
  * @return void
  */
 protected function saveRecords(Document $document, Record\Collection $recordsToSave)
 {
     $this->destination->clearDocument($document->getName());
     $this->destination->saveRecords($document->getName(), $recordsToSave);
 }
 /**
  * Perform rollback
  *
  * @return void
  */
 public function rollback()
 {
     $this->destination->clearDocument('url_rewrite');
     $this->destination->clearDocument('catalog_url_rewrite_product_category');
 }