/** * {@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; }
/** * @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; }
/** * @return void */ public function testPerform() { $recordsData = ['record_1' => ['field_name' => []], 'record_2' => ['field_name' => []], 'record_3' => ['field_name' => []]]; $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $fields = ['field_name' => []]; $differentFields = ['field_different' => []]; $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->at(0))->method('getFields')->willReturn($differentFields); $structure->expects($this->any())->method('getFields')->willReturn($fields); $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getName', 'getRecords', 'getStructure'])->getMock(); $document->expects($this->any())->method('getStructure')->willReturn($structure); $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock(); $document->expects($this->any())->method('getRecords')->willReturn($recordsCollection); $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['getFields', 'setValue'])->getMock(); $record->expects($this->once())->method('getFields')->willReturn(array_keys($fields)); $record->expects($this->once())->method('setValue')->willReturnSelf(); $this->recordFactory->expects($this->any())->method('create')->with(['document' => $document])->will($this->returnValue($record)); $recordsCollection->expects($this->any())->method('addRecord')->with($record); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->source->expects($this->any())->method('getRecords')->willReturnMap([['core_store', 0, null, $recordsData], ['core_store_group', 0, null, $recordsData], ['core_website', 0, null, $recordsData]]); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->any())->method('clearDocument')->willReturnSelf(); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper); $this->data->perform(); }
/** * @return void */ public function testPerformJustCopy() { $sourceDocName = 'core_config_data'; $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName])); $this->source->expects($this->any())->method('getRecordsCount')->will($this->returnValue(2)); $dstDocName = 'config_data'; $this->progress->expects($this->once())->method('getProcessedEntities')->will($this->returnValue([])); $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName)); $this->map->expects($this->any())->method('getHandlerConfig')->willReturn([]); $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords', 'getStructure'], [], '', false); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->any())->method('getRecords')->willReturnOnConsecutiveCalls($bulk, []); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $this->source->expects($this->any())->method('getPageSize')->willReturn(100); $this->source->expects($this->any())->method('setLastLoadedRecord')->withConsecutive([$sourceDocName, $bulk[0]], [$sourceDocName, []]); $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getStructure', 'getRecords'])->getMock(); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->any())->method('getFields')->willReturn(['field' => []]); $sourceDocument->expects($this->any())->method('getStructure')->willReturn($structure); $destinationDocument->expects($this->any())->method('getStructure')->willReturn($structure); $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $dstRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($dstRecord)); $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName); $this->data->perform(); }
/** * @throws \Migration\Exception * @return void */ public function testData() { $countCmsPageRewrites = 1; $recordsAmount = 123; $progressRecordsAmount = $recordsAmount + $countCmsPageRewrites; $this->source->expects($this->once())->method('getRecordsCount')->willReturn($recordsAmount); $this->progress->expects($this->at(0))->method('start')->with($this->equalTo($progressRecordsAmount)); $sourceDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->source->expects($this->once())->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE))->willReturn($sourceDocument); $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->destination->expects($this->at(0))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION))->willReturn($destinationDocument); $destinationProductCategory = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->setMethods(['setValue', 'getRecords'])->disableOriginalConstructor()->getMock(); $this->destination->expects($this->at(1))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY))->willReturn($destinationProductCategory); $this->destination->expects($this->exactly(2))->method('clearDocument')->withConsecutive([\Migration\Step\UrlRewrite\Version191to2000::DESTINATION], [\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY]); $this->source->expects($this->at(2))->method('getRecords')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE), $this->equalTo(0))->willReturn(['RecordData1']); $sourceRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(0))->method('create')->with($this->equalTo(['document' => $sourceDocument, 'data' => 'RecordData1']))->willReturn($sourceRecord); $destinationRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(1))->method('create')->with($this->equalTo(['document' => $destinationDocument]))->willReturn($destinationRecord); $destinationCategoryRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(2))->method('create')->with($this->equalTo(['document' => $destinationProductCategory]))->willReturn($destinationCategoryRecord); $this->mockSourceRecordGetters($sourceRecord); $this->mockDestinationRecordSetters($destinationRecord); $this->mockDestinationCategorySetters($destinationCategoryRecord); $destinationProductCategory->expects($this->once())->method('getRecords')->willReturn($this->recordCollection); $destinationDocument->expects($this->once())->method('getRecords')->willReturn($this->recordCollection); $version = new \Migration\Step\UrlRewrite\Version191to2000($this->config, $this->source, $this->destination, $this->progress, $this->recordFactory, $this->logger, 'data'); $this->assertTrue($version->perform()); }
/** * @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; }
/** * @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 void */ public function testPerform() { $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['source_document_1', MapInterface::TYPE_SOURCE, 'destination_document_1']]); $sourceTable = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->setMethods(['getColumns'])->getMock(); $sourceTable->expects($this->any())->method('getColumns')->will($this->returnValue([['asdf']])); $sourceAdapter = $this->getMockBuilder('\\Migration\\ResourceModel\\Adapter\\Mysql')->disableOriginalConstructor()->setMethods(['getTableDdlCopy'])->getMock(); $sourceAdapter->expects($this->any())->method('getTableDdlCopy')->with('source_suffix_source_document_1', 'destination_suffix_destination_document_1')->will($this->returnValue($sourceTable)); $destinationTable = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->setMethods(['setColumn'])->getMock(); $destinationTable->expects($this->any())->method('setColumn')->with(['asdf']); $destAdapter = $this->getMockBuilder('\\Migration\\ResourceModel\\Adapter\\Mysql')->disableOriginalConstructor()->setMethods(['createTableByDdl', 'getTableDdlCopy'])->getMock(); $destAdapter->expects($this->any())->method('getTableDdlCopy')->with('destination_suffix_destination_document_1', 'destination_suffix_destination_document_1')->will($this->returnValue($destinationTable)); $destAdapter->expects($this->any())->method('createTableByDdl')->with($destinationTable); $this->source->expects($this->once())->method('getAdapter')->will($this->returnValue($sourceAdapter)); $this->destination->expects($this->once())->method('getAdapter')->will($this->returnValue($destAdapter)); $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock(); $destDocument = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getRecords', 'getName'])->getMock(); $destDocument->expects($this->any())->method('getName')->will($this->returnValue('some_name')); $destDocument->expects($this->any())->method('getRecords')->will($this->returnValue($recordsCollection)); $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['setData'])->getMock(); $record->expects($this->once())->method('setData')->with(['field_1' => 1, 'field_2' => 2]); $this->recordFactory->expects($this->any())->method('create')->with(['document' => $destDocument])->will($this->returnValue($record)); $recordsCollection->expects($this->any())->method('addRecord')->with($record); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($destDocument)); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => 'source_document_1'])->willReturn(true); $this->source->expects($this->any())->method('getRecords')->will($this->returnValueMap([['source_document_1', 0, null, [['field_1' => 1, 'field_2' => 2]]]])); $this->assertTrue($this->step->perform()); }
/** * @param array $data * @param ResourceModel\Document $sourceDocument * @param Record\Collection $destEavCollection * @return void */ public function migrateAdditionalOrderData($data, $sourceDocument, $destEavCollection) { foreach ($this->helper->getEavAttributes() as $orderEavAttribute) { $eavAttributeData = $this->prepareEavEntityData($orderEavAttribute, $data); if ($eavAttributeData) { $attributeRecord = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $eavAttributeData]); $destEavCollection->addRecord($attributeRecord); } } }
/** * @param array $data * @param ResourceModel\Document $sourceDocument * @param ResourceModel\Document $destDocument * @param \Migration\RecordTransformer $recordTransformer * @param ResourceModel\Record\Collection $destinationRecords * @return void */ protected function transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords) { if ($recordTransformer) { $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]); $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($record, $destRecord); } else { $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]); } $destinationRecords->addRecord($destRecord); }
/** * @param Document $document * @param array $sourceData * @param array $destinationData * @return Record */ protected function applyHandler(\Migration\ResourceModel\Document $document, array $sourceData, array $destinationData) { /** @var Record $sourceRecord */ $sourceRecord = $this->recordFactory->create(['document' => $document, 'data' => $sourceData]); /** @var Record $destinationData */ $destinationRecord = $this->recordFactory->create(['document' => $document, 'data' => $destinationData]); $handler = $this->getHandler($sourceData[self::CONFIG_FIELD_PATH]); if ($handler) { $handler->handle($sourceRecord, $destinationRecord); } return $sourceRecord; }
/** * @param array $recordData * @return void */ public function updateAttributeData($recordData) { $attributeCodes = array_keys($this->readerAttributes->getGroup($this->entityName)); $sourceData['attribute_id'] = $this->eavAttributes['catalog_category']['automatic_sorting']['attribute_id']; $sourceData['entity_id'] = $recordData['category_id']; $sourceData['store_id'] = self::DEFAULT_STORE_ID; $sourceData['value'] = array_key_exists($recordData['automatic_sort'], $this->attributeMapping) ? $this->attributeMapping[$recordData['automatic_sort']] : '0'; $data = array_merge(array_fill_keys($attributeCodes, null), $sourceData); $destDocument = $this->destination->getDocument($this->entityName); $destRecord = $this->recordFactory->create(['document' => $destDocument]); $destRecord->setData($data); $this->records[] = $destRecord; }
/** * @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; }
/** * 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); } }
/** * @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; }
/** * @covers \Migration\Step\SalesOrder\Data::prepareEavEntityData * @covers \Migration\Step\SalesOrder\Data::getAttributeData * @covers \Migration\Step\SalesOrder\Data::getAttributeValue * @covers \Migration\Step\SalesOrder\Data::getDestEavDocument * @return void */ public function testGetMap() { $sourceDocumentName = 'source_document'; $destinationDocumentName = 'destination_document'; $eavAttributes = ['eav_attr_1', 'eav_attr_2']; $eavAttributeData = ['entity_type_id' => 1, 'attribute_id' => 2, 'attribute_code' => 'eav_attr_1']; $this->helper->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocumentName => $destinationDocumentName]); $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn('eav_document'); $this->helper->expects($this->at(3))->method('getEavAttributes')->willReturn($eavAttributes); $this->map->expects($this->once())->method('getDocumentMap')->willReturn($destinationDocumentName); $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $this->source->expects($this->any())->method('getRecordsCount')->willReturn(2); $destinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $eavDestinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $dstDocName = 'destination_document'; $eavDstDocName = 'eav_document'; $this->destination->expects($this->any())->method('getDocument')->willReturnMap([[$dstDocName, $destinationDocument], [$eavDstDocName, $eavDestinationDocument]]); $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['init', 'transform'], [], '', false); $this->recordTransformerFactory->expects($this->once())->method('create')->willReturn($recordTransformer); $recordTransformer->expects($this->once())->method('init'); $bulk = [['eav_attr_1' => 'attribute_value', 'store_id' => '1', 'entity_id' => '2']]; $this->source->expects($this->at(3))->method('getRecords')->willReturn($bulk); $this->source->expects($this->at(4))->method('getRecords')->willReturn([]); $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $eavDestinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->willReturn($destinationRecords); $srcRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $dstRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->willReturn($srcRecord); $this->recordFactory->expects($this->at(1))->method('create')->willReturn($dstRecord); $recordTransformer->expects($this->once())->method('transform')->with($srcRecord, $dstRecord); $eavDestinationDocument->expects($this->once())->method('getRecords')->willReturn($eavDestinationRecords); $eavDestinationRecords->expects($this->once())->method('addRecord'); $this->destination->expects($this->at(5))->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->at(6))->method('saveRecords')->with($eavDstDocName, $eavDestinationRecords); $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName); $this->destination->expects($this->at(3))->method('getRecords')->willReturn([0 => $eavAttributeData]); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => $sourceDocumentName])->willReturn(true); $this->salesOrder->perform(); }
/** * @return void */ public function testPerform() { $sourceDocName = 'core_config_data'; $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName])); $dstDocName = 'config_data'; $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName)); $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($sourceDocument)); $destinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $this->sourceAdapter->expects($this->at(1))->method('loadDataFromSelect')->willReturn([['visitor_id' => 1, 'session_id' => 'dvak7ir3t9p3sicksr0t9thqc7', 'first_visit_at' => '2015-10-25 11:22:40', 'last_visit_at' => '2015-10-25 11:22:40', 'last_url_id' => 1, 'store_id' => 1]]); $this->sourceAdapter->expects($this->at(2))->method('loadDataFromSelect')->willReturn([]); $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $srcRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($srcRecord)); $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->exactly(2))->method('clearDocument'); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => 'source_document'])->willReturn(true); $this->data->perform(); }
/** * @return void */ public function testPerform() { $count = 2; $sourceRecords = [['config_id' => 1, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value4'], ['config_id' => 2, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path3', 'value' => 'some value3']]; $destinationRecords = [['config_id' => 1, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value1'], ['config_id' => 2, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path2', 'value' => 'some value2']]; $destinationRecordsFinal = [['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value1'], ['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path2', 'value' => 'some value2'], ['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path3', 'value' => 'some value3']]; $pathMapped = [['some/path1', 'some/path1'], ['some/path3', 'some/path3']]; $handlerParams = [['some/path1', ['class' => 'Some\\Class', 'params' => []]], ['some/path3', []]]; $document = $this->getMock('Migration\\ResourceModel\\Document', [], [], '', false); $destinationRecord = $this->getMock('Migration\\ResourceModel\\Record', [], [], '', false); $sourceRecord = $this->getMock('Migration\\ResourceModel\\Record', ['getData', 'getValue', 'setValue'], [], '', false); $sourceRecord->expects($this->any())->method('getValue')->with('value')->willReturn($destinationRecords[0]['value']); $sourceRecord->expects($this->any())->method('setValue')->with('path', $pathMapped[1][0]); $sourceRecord->expects($this->any())->method('getData')->willReturn($sourceRecords[1]); $handler = $this->getMockBuilder('\\Migration\\Handler\\HandlerInterface')->getMock(); $handler->expects($this->any())->method('handle')->with($sourceRecord, $destinationRecord); $handlerManager = $this->getMock('Migration\\Handler\\Manager', ['initHandler', 'getHandler'], [], '', false); $handlerManager->expects($this->once())->method('initHandler')->with('value', $handlerParams[0][1], 'some/path1'); $handlerManager->expects($this->once())->method('getHandler')->willReturn($handler); $this->progress->expects($this->once())->method('start')->with($count); $this->progress->expects($this->exactly($count))->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->source->expects($this->once())->method('getRecordsCount')->with('core_config_data')->willReturn($count); $this->source->expects($this->once())->method('getRecords')->with('core_config_data', 0, $count)->willReturn($sourceRecords); $this->destination->expects($this->once())->method('getRecordsCount')->with('core_config_data')->willReturn($count); $this->destination->expects($this->once())->method('getDocument')->with('core_config_data')->willReturn($document); $this->destination->expects($this->once())->method('clearDocument')->with('core_config_data'); $this->destination->expects($this->once())->method('saveRecords')->with('core_config_data', $destinationRecordsFinal); $this->destination->expects($this->once())->method('getRecords')->with('core_config_data', 0, $count)->willReturn($destinationRecords); $this->readerSettings->expects($this->any())->method('isNodeIgnored')->willReturn(false); $this->readerSettings->expects($this->any())->method('getNodeMap')->willReturnMap($pathMapped); $this->readerSettings->expects($this->any())->method('getValueHandler')->willReturnMap($handlerParams); $this->recordFactory->expects($this->at(0))->method('create')->with(['document' => $document, 'data' => $sourceRecords[0]])->willReturn($sourceRecord); $this->recordFactory->expects($this->at(1))->method('create')->with(['document' => $document, 'data' => $destinationRecords[0]])->willReturn($destinationRecord); $this->recordFactory->expects($this->at(2))->method('create')->with(['document' => $document, 'data' => $sourceRecords[1]])->willReturn($sourceRecord); $this->recordFactory->expects($this->at(3))->method('create')->with(['document' => $document, 'data' => []])->willReturn($destinationRecord); $this->handlerManagerFactory->expects($this->once())->method('create')->willReturn($handlerManager); $this->data = new Data($this->destination, $this->source, $this->logger, $this->progress, $this->recordFactory, $this->readerSettings, $this->handlerManagerFactory); $this->assertTrue($this->data->perform()); }
/** * 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; }
/** * Run step * * @return bool */ protected function data() { $this->progress->start($this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites()); $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->collectCmsPageRewrites(); $this->progress->finish(); 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; }