/** * {@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; }
/** * {@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; }
/** * @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 */ 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(); }
/** * {@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]); }
/** * @covers \Migration\Step\SalesOrder\Integrity::checkEavEntities * @covers \Migration\Step\SalesOrder\Integrity::getEavEntities * @covers \Migration\Step\SalesOrder\Integrity::getIterationsCount * @return void */ public function testPerform() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $destinationRecord = ['attribute_code' => 'eav_entity']; $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['source_doc' => 'dest_doc']); $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn('eav_entity_int'); $this->helper->expects($this->once())->method('getEavAttributes')->willReturn(['eav_entity']); $this->progress->expects($this->once())->method('start')->with(3); $this->progress->expects($this->any())->method('advance'); $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->willReturn($fields); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->willReturn($structure); $this->source->expects($this->any())->method('getDocumentList')->willReturn(['source_doc']); $this->destination->expects($this->once())->method('getDocumentList')->willReturn(['dest_doc']); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->at(3))->method('getRecords')->willReturn([0 => $destinationRecord]); $this->destination->expects($this->at(4))->method('getRecords')->willReturn(null); $this->map->expects($this->any())->method('isDocumentIgnored')->willReturn(false); $this->map->expects($this->at(1))->method('getDocumentMap')->willReturn('dest_doc'); $this->map->expects($this->at(4))->method('getDocumentMap')->willReturn('source_doc'); $this->map->expects($this->any())->method('getFieldMap')->willReturn('field1'); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->logger->expects($this->never())->method('error'); $this->salesOrder->perform(); }
/** * @covers \Migration\Step\SalesOrder\InitialData::initDestAttributes * @covers \Migration\Step\SalesOrder\InitialData::getDestEavAttributesCount * @return void */ public function testInit() { $eavEntityDocument = 'eav_entity_int'; $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn($eavEntityDocument); $this->destination->expects($this->once())->method('getRecordsCount')->willReturn(2); $this->initialData->init(); $this->assertEquals($this->initialData->getDestEavAttributesCount($eavEntityDocument), 2); }
/** * @return void */ public function testPerform() { $data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper); $this->assertTrue($data->perform()); foreach ($this->destinationDocuments as $documentName => $recordsCount) { $this->assertEquals($recordsCount, count($this->destination->getRecords($documentName, 0))); } }
/** * @return void */ public function testPerform() { $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->source->expects($this->any())->method('getDocument', 'getRecords')->willReturn($document); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->integrity = new Integrity($this->progress, $this->source, $this->destination, $this->helper); $this->assertTrue($this->integrity->perform()); }
/** * {@inheritdoc} */ public function perform() { $result = true; $this->progress->start(count($this->helper->getDocumentList())); foreach ($this->helper->getDocumentList() as $sourceName => $destinationName) { $this->progress->advance(); $result &= (bool) $this->source->getDocument($sourceName); $result &= (bool) $this->destination->getDocument($destinationName); } $this->progress->finish(); return (bool) $result; }
/** * {@inheritdoc} */ public function perform() { $this->progress->start(count($this->helper->getDocumentList())); foreach ($this->helper->getDocumentList() as $sourceName => $destinationName) { $this->progress->advance(); if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progress->finish(); return $this->checkForErrors(Logger::ERROR); }
/** * @return bool */ public function perform() { $documents = $this->helper->getDocumentList(); $this->progressBar->start(1); $oldDestinationRecordsCount = $this->helper->getDestinationRecordsCount(); $newDestinationRecordsCount = $this->destination->getRecordsCount($documents[MapInterface::TYPE_DEST]) - $oldDestinationRecordsCount; if ($newDestinationRecordsCount != 0) { $this->errors[] = 'Mismatch of entities in the document: ' . $documents[MapInterface::TYPE_DEST]; } $this->progressBar->finish(); return $this->checkForErrors(Logger::ERROR); }
/** * @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); } }
/** * @return void */ public function testPerform() { $this->data = new Data($this->destination, $this->progress); $this->progress->expects($this->once())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter); $this->adapter->expects($this->once())->method('getSelect')->willReturn($this->select); $this->select->expects($this->once())->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf()); $this->select->expects($this->once())->method('where')->with('store_id > 0')->will($this->returnSelf()); $this->adapter->expects($this->once())->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]); $this->adapter->expects($this->once())->method('updateDocument')->with('rating', ['is_active' => 1], 'rating_id IN (1)'); $this->data->perform(); }
/** * @return bool */ public function perform() { $this->progressBar->start($this->getIterationsCount()); foreach ($this->helper->getDocumentList() as $sourceDocumentName => $destinationDocumentName) { $this->progressBar->advance(); $sourceRecordsCount = $this->source->getRecordsCount($sourceDocumentName); $destinationRecordsCount = $this->destination->getRecordsCount($destinationDocumentName); if ($sourceRecordsCount != $destinationRecordsCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationDocumentName; } } $this->progressBar->finish(); return $this->checkForErrors(); }
/** * @return void */ public function testPerform() { $fields = ['field1' => []]; $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->map->expects($this->once())->method('getDocumentMap')->with('document1')->willReturn('document2'); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->source->expects($this->once())->method('getDocument')->with('document1')->willReturn($document); $this->destination->expects($this->once())->method('getDocument')->with('document2')->willReturn($document); $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([['document2', true, [], 3]]); $this->assertTrue($this->volume->perform()); }
/** * {@inheritdoc} */ public function perform() { $this->progress->start($this->getIterationsCount()); foreach ($this->helper->getDocumentList() as $documentName) { $this->progress->advance(); $documentColumns = $this->helper->getDocumentColumns($documentName); $destinationDocumentStructure = array_keys($this->destination->getStructure($documentName)->getFields()); foreach (array_diff($documentColumns, $destinationDocumentStructure) as $columnDiff) { $message = sprintf('%s table does not contain field: %s', $documentName, $columnDiff); $this->logger->error($message); } } $this->progress->finish(); return $this->checkForErrors(); }
/** * {@inheritdoc} */ public function perform() { $this->progress->start(count($this->helper->getSourceDocumentFields())); $sourceTotal = 0; $destinationTotal = $this->destination->getRecordsCount($this->helper->getDestinationName()); foreach (array_keys($this->helper->getSourceDocumentFields()) as $sourceName) { $sourceTotal += $this->source->getRecordsCount($sourceName); $this->progress->advance(); } if ($sourceTotal != $destinationTotal) { $this->errors[] = 'Mismatch of amount of entities in documents'; } $this->progress->finish(); return $this->checkForErrors(Logger::ERROR); }
/** * @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 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->getDestDocumentName($document); 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); }
/** * @param string $documentName * @param string $idKey * @return void */ protected function processChangedRecords($documentName, $idKey) { $items = $this->source->getChangedRecords($documentName, $idKey); if (empty($items)) { return; } if (!$this->eolOnce) { $this->eolOnce = true; echo PHP_EOL; } $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); $sourceDocument = $this->source->getDocument($documentName); $destDocument = $this->destination->getDocument($destinationName); $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument); do { $destinationRecords = $destDocument->getRecords(); $ids = []; foreach ($items as $data) { echo '.'; $ids[] = $data[$idKey]; $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords); } $this->destination->updateChangedRecords($destinationName, $destinationRecords); $documentNameDelta = $this->source->getDeltaLogName($documentName); $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta); $this->markRecordsProcessed($documentNameDelta, $idKey, $ids); } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey))); }
/** * @throws \Zend_Db_Adapter_Exception * @return void */ public function updateEavAttributes() { /** @var Mysql $adapter */ $adapter = $this->destination->getAdapter(); $query = $adapter->getSelect()->from($this->destination->addDocumentPrefix('eav_entity_type'), ['entity_type_id', 'entity_type_code']); $entityTypes = $query->getAdapter()->fetchAll($query); $entityTypesByCode = []; foreach ($entityTypes as $entityType) { $entityTypesByCode[$entityType['entity_type_code']] = $entityType['entity_type_id']; } $where = []; $entities = array_keys($this->readerGroups->getGroup('eav_entities')); foreach ($entities as $entity) { $documents = $this->readerGroups->getGroup($entity); $codes = []; foreach ($documents as $document => $key) { if ($key != 'entity_id') { continue; } $codes = implode("','", array_keys($this->readerAttributes->getGroup($document))); } $where += [sprintf("attribute_code IN ('%s')", $codes), sprintf("entity_type_id = '%s'", $entityTypesByCode[$entity])]; } $adapter->getSelect()->getAdapter()->update($this->destination->addDocumentPrefix('eav_attribute'), ['backend_type' => 'static'], $where); }
/** * @covers \Migration\Step\Log\Integrity::getIterationsCount * @return void */ public function testPerformMainFlow() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document1'])); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document2', 'document_to_clear'])); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['document1', MapInterface::TYPE_SOURCE, 'document2'], ['document2', MapInterface::TYPE_DEST, 'document1']]); $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->map->expects($this->any())->method('getFieldMap')->will($this->returnValue('field1')); $this->logger->expects($this->never())->method('error'); $this->assertTrue($this->log->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()); }
/** * @param array $documents * @return void */ protected function clearLog($documents) { foreach ($documents as $documentName) { $this->progress->advance(); $this->destination->clearDocument($documentName); } }
/** * @return void */ public function testDeleteDocumentBackup() { $docName = 'somename'; $this->adapter->expects($this->once())->method('deleteBackup')->with('pfx_' . $docName); $this->config->expects($this->once())->method('getOption')->with('dest_prefix')->will($this->returnValue('pfx_')); $this->resourceDestination->deleteDocumentBackup($docName); }
/** * @return void */ public function testDeleteBackups() { $this->readerGroups->expects($this->once())->method('getGroup')->with('documents')->willReturn(['some_document' => 0]); $this->map->expects($this->once())->method('getDocumentMap')->with('some_document', MapInterface::TYPE_SOURCE)->will($this->returnValue('some_dest_document')); $this->destination->expects($this->once())->method('deleteDocumentBackup')->with('some_dest_document'); $this->helper->deleteBackups(); }
/** * @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]); }