/** * {@inheritdoc} */ public function handle(Record $recordToHandle, Record $oppositeRecord) { $this->validate($recordToHandle); $record['value_id'] = $recordToHandle->getValue($this->field); $record['entity_id'] = $recordToHandle->getValue($this->entityField); $this->destination->saveRecords($this->valueToEntityDocument, [$record]); }
/** * {@inheritdoc} */ public function perform() { $this->progress->start(count($this->helper->getDocumentList())); $documents = $this->helper->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 ResourceModel\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; }
/** * @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); } }
/** * @param int $storeId * @param int $metaId * @return void */ protected function addDataProfileTable($storeId, $metaId) { $incrementPrefix = $this->getIncrementPrefix($storeId); $data = ['meta_id' => $metaId, 'prefix' => $incrementPrefix ?: '']; $data = array_merge($this->defaultValuesProfile, $data); $this->destination->saveRecords($this->helper->getSequenceProfileTable(), [$data]); }
/** * {@inheritdoc} */ public function perform() { $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; }
/** * @return bool */ public function perform() { // catalog_product_entity_tier_price should be migrated first to save same value_id as into magento1 $sourceDocuments = array_keys($this->helper->getSourceDocumentFields()); $this->progress->start(count($sourceDocuments), LogManager::LOG_LEVEL_INFO); $destinationName = $this->helper->getDestinationName(); $this->destination->clearDocument($destinationName); $destDocument = $this->destination->getDocument($destinationName); foreach ($sourceDocuments as $sourceDocName) { $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocName]); $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG); while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) { $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($items as $recordData) { unset($recordData['value_id']); $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->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * @dataProvider saveRecordsDataSet() * @param string|null @prefix * @return void */ public function testSaveRecords($prefix) { $resourceName = 'core_config_data'; $this->config->expects($this->any())->method('getOption')->willReturnMap([['bulk_size', 3], ['dest_prefix', $prefix]]); $this->adapter->expects($this->at(0))->method('insertRecords')->with($prefix . $resourceName, [['data' => 'value1'], ['data' => 'value2'], ['data' => 'value3']])->will($this->returnSelf()); $this->adapter->expects($this->at(1))->method('insertRecords')->with($prefix . $resourceName, [['data' => 'value4']])->will($this->returnSelf()); $records = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $records->expects($this->any())->method('current')->willReturnCallback(function () { static $count = 0; $count++; $data = ['data' => "value{$count}"]; $record = $this->getMock('\\Migration\\ResourceModel\\Record', ['getData'], [], '', false); $record->expects($this->once())->method('getData')->will($this->returnValue($data)); return $record; }); $records->expects($this->any())->method('valid')->willReturnCallback(function () { static $count = 0; $count++; if ($count <= 4) { return true; } else { return false; } }); $this->resourceDestination->saveRecords($resourceName, $records); }
/** * @param string $sourceName * @param string $destinationName * @param string $type * @return void */ protected function copyEavData($sourceName, $destinationName, $type) { $destinationDocument = $this->destination->getDocument($destinationName); $pageNumber = 0; while (!empty($recordsData = $this->source->getRecords($sourceName, $pageNumber))) { $pageNumber++; $records = $destinationDocument->getRecords(); foreach ($recordsData as $row) { $this->progress->advance(); $row['value_id'] = null; unset($row['entity_type_id']); if (!empty($this->resolvedDuplicates[$type][$row['entity_id']][$row['store_id']])) { $row['value'] = $row['value'] . '-' . $this->resolvedDuplicates[$type][$row['entity_id']][$row['store_id']]; } elseif (!empty($this->resolvedDuplicates[$type][$row['entity_id']]) && $row['store_id'] == 0) { foreach ($this->resolvedDuplicates[$type][$row['entity_id']] as $storeId => $urlKey) { $storeRow = $row; $storeRow['store_id'] = $storeId; $storeRow['value'] = $storeRow['value'] . '-' . $urlKey; $records->addRecord($this->recordFactory->create(['data' => $storeRow])); if (!isset($this->resolvedDuplicates[$destinationName])) { $this->resolvedDuplicates[$destinationName] = 0; } $this->resolvedDuplicates[$destinationName]++; } } $records->addRecord($this->recordFactory->create(['data' => $row])); } $this->destination->saveRecords($destinationName, $records, true); } }
/** * @return bool */ public function perform() { $this->helper->init(); $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); $document = $this->helper->getDocumentList(); $sourceDocumentName = $document['source']; $destinationDocumentName = $document['destination']; $destinationDocument = $this->destination->getDocument($destinationDocumentName); $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocumentName]); $this->progress->start($this->source->getRecordsCount($sourceDocumentName), LogManager::LOG_LEVEL_DEBUG); /** @var \Magento\Framework\DB\Select $select */ $select = $this->getConfigurablePrice(); while (!empty($bulk = $this->getRecords($sourceDocumentName, $select, $pageNumber))) { $pageNumber++; $destinationCollection = $destinationDocument->getRecords(); foreach ($bulk 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, 'data' => $recordData]); $destinationCollection->addRecord($destinationRecord); } $this->destination->saveRecords($destinationDocumentName, $destinationCollection, true); $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * @return void */ protected function collectCmsPageRewrites() { $this->progress->advance(); /** @var \Magento\Framework\Db\Select $select */ $select = $this->source->getAdapter()->getSelect(); $select->distinct()->from(['cp' => $this->source->addDocumentPrefix($this->cmsPageTableName)], [new \Zend_Db_Expr('"cms-page" as `entity_type`'), 'entity_id' => 'cp.page_id', 'request_path' => 'cp.identifier', 'target_path' => 'CONCAT("cms/page/view/page_id/", cp.page_id)', 'store_id' => 'IF(cps.store_id = 0, 1, cps.store_id)', new \Zend_Db_Expr('1 as `is_autogenerated`')])->joinLeft(['cps' => $this->source->addDocumentPrefix($this->cmsPageStoreTableName)], 'cps.page_id = cp.page_id', [])->group(['request_path', 'cps.store_id']); $urlRewrites = $this->source->getAdapter()->loadDataFromSelect($select); $this->destination->saveRecords(self::DESTINATION, $urlRewrites); }
/** * @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; }
/** * @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; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * Saves the records * @return void */ public function saveRecords() { $this->destination->saveRecords($this->entityName, $this->records); }
/** * @param Document $document * @param Record\Collection $recordsToSave * @return void */ protected function saveRecords(Document $document, Record\Collection $recordsToSave) { $this->destination->saveRecords($document->getName(), $recordsToSave); }