public function testData() { $this->source->expects($this->once())->method('getRecordsCount')->willReturn(123); $this->progress->expects($this->at(0))->method('start')->with($this->equalTo(123)); $sourceDocument = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock(); $this->source->expects($this->once())->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE))->willReturn($sourceDocument); $destinationDocument = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\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\\Resource\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(0))->method('create')->with($this->equalTo(['document' => $sourceDocument, 'data' => 'RecordData1']))->willReturn($sourceRecord); $destinationRecord = $this->getMockBuilder('\\Migration\\Resource\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(1))->method('create')->with($this->equalTo(['document' => $destinationDocument]))->willReturn($destinationRecord); $destinationCategoryRecord = $this->getMockBuilder('\\Migration\\Resource\\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()); }
public function testGetSourceRecordsNoKey() { $row = ['key' => 'key_value', 'field' => 'field_value']; $this->source->expects($this->once())->method('getRecordsCount')->will($this->returnValue(1)); $this->source->expects($this->once())->method('getRecords')->with('test_source_document', 0, 1)->will($this->returnValue([$row])); $this->assertEquals([$row], $this->helper->getSourceRecords('test_source_document')); }
/** * Get attribute set IDs for entity type 'catalog_product' * @return array */ protected function getProductAttributeSets() { if (empty($this->productAttributeSets)) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from(['as' => $this->source->addDocumentPrefix('eav_attribute_set')], ['attribute_set_id'])->join(['et' => $this->source->addDocumentPrefix('eav_entity_type')], 'et.entity_type_id = as.entity_type_id', [])->where('et.entity_type_code = ?', 'catalog_product'); $this->productAttributeSets = array_flip($query->getAdapter()->fetchCol($query)); } return $this->productAttributeSets; }
public function testPerformFailed() { $sourceDocName = 'core_config_data'; $dstDocName = 'config_data'; $this->source->expects($this->once())->method('getDocumentList')->willReturn([$sourceDocName]); $this->map->expects($this->once())->method('getDocumentMap')->willReturn($dstDocName); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(2); $this->destination->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->logger->expects($this->once())->method('warning')->with('Mismatch of entities in the document: ' . $dstDocName); $this->assertFalse($this->volume->perform()); }
/** * @param Record $recordToHandle * @param Record $oppositeRecord * @return void */ public function handle(Record $recordToHandle, Record $oppositeRecord) { if (empty($this->defaultWebsiteId)) { $this->validate($recordToHandle); foreach ($this->source->getRecords('core_website', 0) as $websiteData) { if ($websiteData['is_default'] == '1') { $this->defaultWebsiteId = $websiteData[$this->field]; break; } } } $recordToHandle->setValue($this->field, $this->defaultWebsiteId); }
/** * @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 bool */ public function perform() { $documents = $this->helper->getDocumentList(); $this->progressBar->start(1); $sourceRecordsCount = $this->source->getRecordsCount($documents[MapInterface::TYPE_SOURCE]); $oldDestinationRecordsCount = $this->helper->getDestinationRecordsCount(); $newDestinationRecordsCount = $this->destination->getRecordsCount($documents[MapInterface::TYPE_DEST]) - $oldDestinationRecordsCount; if ($sourceRecordsCount != $newDestinationRecordsCount) { $message = 'Mismatch of entities in the document: ' . $documents[MapInterface::TYPE_DEST]; $this->logger->error($message); } $this->progressBar->finish(); return $this->checkForErrors(); }
public function testDelta() { $sourceDocName = 'orders'; $sourceDeltaName = 'm2_cl_orders'; $this->source->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocName, $sourceDeltaName]); $this->source->expects($this->atLeastOnce())->method('getDeltaLogName')->with('orders')->willReturn($sourceDeltaName); $this->source->expects($this->any())->method('getRecordsCount')->with($sourceDeltaName)->willReturn(1); /** @var \Migration\Resource\Document|\PHPUnit_Framework_MockObject_MockObject $source */ $document = $this->getMock('\\Migration\\Resource\\Document', [], [], '', false); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->map->expects($this->any())->method('getDeltaDocuments')->willReturn([$sourceDocName => 'order_id']); $this->map->expects($this->any())->method('getDocumentMap')->with($sourceDocName, MapInterface::TYPE_SOURCE)->willReturn($sourceDocName); $this->logger->expects($this->any())->method('debug')->with($sourceDocName . ' has changes'); $this->assertTrue($this->delta->perform()); }
/** * @return bool */ public function perform() { $deltaLogs = $this->groupsReader->getGroups(); $this->progress->start(count($deltaLogs, 1) - count($deltaLogs)); foreach ($deltaLogs as $deltaDocuments) { foreach ($deltaDocuments as $documentName => $idKey) { $this->progress->advance(); if ($this->source->getDocument($documentName)) { $this->source->createDelta($documentName, $idKey); } } } $this->progress->finish(); return true; }
public function testPerformWithError() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $this->map->expects($this->atLeastOnce())->method('getDocumentMap')->willReturnMap([['source_document', MapInterface::TYPE_SOURCE, 'source_document'], ['common_document', MapInterface::TYPE_SOURCE, 'common_document'], ['source_document', MapInterface::TYPE_DEST, 'source_document'], ['common_document', MapInterface::TYPE_DEST, 'common_document']]); $structure = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['source_document', 'common_document'])); $this->source->expects($this->atLeastOnce())->method('getDocument')->willReturn($document); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['common_document'])); $this->destination->expects($this->atLeastOnce())->method('getDocument')->willReturn($document); $this->logger->expects($this->once())->method('error')->with('Source documents not mapped: source_document'); $this->readerGroups->expects($this->any())->method('getGroup')->with('documents')->willReturn(['source_document' => 0, 'common_document' => 1]); $this->assertFalse($this->integrity->perform()); }
/** * @covers \Migration\Step\Log\Integrity::getIterationsCount */ public function testPerformMainFlow() { $fields = ['field1' => []]; $structure = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\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()); }
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\\Resource\\Document', ['getRecords', 'getStructure'], [], '', false); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->at(4))->method('getRecords')->will($this->returnValue($bulk)); $this->source->expects($this->at(5))->method('getRecords')->will($this->returnValue([])); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $destinationDocument = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->setMethods(['getStructure', 'getRecords'])->getMock(); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $structure = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $dstRecord = $this->getMock('\\Migration\\Resource\\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(); }
/** * {@inheritdoc} */ public function run() { do { /** @var StepList $steps */ $steps = $this->stepListFactory->create(['mode' => 'delta']); /** * @var string $stepName * @var StageInterface[] $step */ foreach ($steps->getSteps() as $stepName => $step) { if (empty($step['delta'])) { continue; } $this->runDelta($step, $stepName); if (!empty($step['volume'])) { $this->runVolume($step, $stepName); } } $deltaLogs = $this->groupsReader->getGroups(); foreach ($deltaLogs as $deltaDocuments) { foreach (array_keys($deltaDocuments) as $documentName) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $adapter->deleteProcessedRecords($this->source->addDocumentPrefix($this->source->getDeltaLogName($documentName))); } } $this->logger->info('Migration completed successfully'); if ($this->autoRestart) { $this->logger->info("Automatic restart in {$this->autoRestart} sec. Use CTRL-C to abort"); sleep($this->autoRestart); } } while ($this->autoRestart); return true; }
public function testHandle() { /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMockBuilder('Migration\\Resource\\Record')->setMethods(['getValue', 'setValue', 'getFields'])->disableOriginalConstructor()->getMock(); /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */ $oppositeRecord = $this->getMockBuilder('Migration\\Resource\\Record')->disableOriginalConstructor()->getMock(); $fieldName = 'fieldname'; $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName])); $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->will($this->returnValue('SELECT * FROM `source_some_document` LEFT JOIN `source_other_document`')); $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 'SELECT * FROM `pfx_dest_some_document` LEFT JOIN `pfx_dest_other_document`'); $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['source_some_document', MapInterface::TYPE_SOURCE, 'dest_some_document'], ['source_other_document', MapInterface::TYPE_SOURCE, 'dest_other_document'], ['source_ignored_document', MapInterface::TYPE_SOURCE, false]]); $this->source->expects($this->once())->method('getDocumentList')->will($this->returnValue(['source_some_document', 'source_other_document', 'source_ignored_document'])); $this->source->expects($this->any())->method('addDocumentPrefix')->will($this->returnArgument(0)); $this->handler->setField($fieldName); $this->handler->handle($recordToHandle, $oppositeRecord); }
/** * @return bool * @throws \Migration\Exception */ protected function data() { $destinationDocument = $this->destination->getDocument(self::CONFIG_TABLE_NAME_DESTINATION); $recordsCountSource = $this->source->getRecordsCount(self::CONFIG_TABLE_NAME_SOURCE); $recordsCountDestination = $this->destination->getRecordsCount(self::CONFIG_TABLE_NAME_DESTINATION); $this->progress->start($recordsCountSource); $sourceRecords = $this->source->getRecords(self::CONFIG_TABLE_NAME_SOURCE, 0, $recordsCountSource); $destinationRecords = $this->destination->getRecords(self::CONFIG_TABLE_NAME_DESTINATION, 0, $recordsCountDestination); foreach ($sourceRecords as $sourceRecord) { $this->progress->advance(); if (!$this->readerSettings->isNodeIgnored($sourceRecord[self::CONFIG_FIELD_PATH])) { $sourceRecordPathMapped = $this->readerSettings->getNodeMap($sourceRecord[self::CONFIG_FIELD_PATH]); foreach ($destinationRecords as &$destinationRecord) { if ($destinationRecord[self::CONFIG_FIELD_SCOPE] == $sourceRecord[self::CONFIG_FIELD_SCOPE] && $destinationRecord[self::CONFIG_FIELD_SCOPE_ID] == $sourceRecord[self::CONFIG_FIELD_SCOPE_ID] && $destinationRecord[self::CONFIG_FIELD_PATH] == $sourceRecordPathMapped) { $record = $this->applyHandler($destinationDocument, $sourceRecord, $destinationRecord); $destinationRecord[self::CONFIG_FIELD_VALUE] = $record->getValue(self::CONFIG_FIELD_VALUE); continue 2; } } $record = $this->applyHandler($destinationDocument, $sourceRecord, []); $record->setValue(self::CONFIG_FIELD_PATH, $sourceRecordPathMapped); $destinationRecords[] = $record->getData(); } } foreach ($destinationRecords as &$destinationRecord) { unset($destinationRecord[self::CONFIG_FIELD_CONFIG_ID]); } $this->destination->clearDocument(self::CONFIG_TABLE_NAME_DESTINATION); $this->destination->saveRecords(self::CONFIG_TABLE_NAME_DESTINATION, $destinationRecords); $this->progress->finish(); return true; }
/** * @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))); }
/** * Mark processed records for deletion * * @param string $documentName * @param string $idKey * @param [] $ids * @return void */ protected function markRecordsProcessed($documentName, $idKey, $ids) { $ids = implode("','", $ids); /** @var Resource\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $adapter->updateDocument($documentName, ['processed' => 1], "`{$idKey}` in ('{$ids}')"); }
/** * @param Record $recordToHandle * @param Record $oppositeRecord * @return mixed */ public function handle(Record $recordToHandle, Record $oppositeRecord) { $this->validate($recordToHandle); $sourcePatterns = []; $destinationPatters = []; foreach ($this->source->getDocumentList() as $document) { $destDocumentName = $this->map->getDocumentMap($document, MapInterface::TYPE_SOURCE); if ($destDocumentName === false) { continue; } $sourcePatterns[] = sprintf('`%s`', $this->source->addDocumentPrefix($document)); $destinationPatters[] = sprintf('`%s`', $this->destination->addDocumentPrefix($destDocumentName)); } $newValue = str_replace($sourcePatterns, $destinationPatters, $recordToHandle->getValue($this->field)); $recordToHandle->setValue($this->field, $newValue); }
/** * @return bool */ public function perform() { $this->progressBar->start(count($this->source->getDocumentList()), LogManager::LOG_LEVEL_INFO); $sourceDocuments = $this->source->getDocumentList(); // TODO: during steps refactoring MAGETWO-35749 stage will be removed $stage = 'run'; $processedDocuments = $this->progress->getProcessedEntities($this, $stage); foreach ($sourceDocuments as $sourceDocName) { $this->progressBar->advance(LogManager::LOG_LEVEL_INFO); if (in_array($sourceDocName, $processedDocuments)) { continue; } $sourceDocument = $this->source->getDocument($sourceDocName); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $destDocument = $this->destination->getDocument($destinationName); $this->destination->clearDocument($destinationName); $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument); $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocName]); $this->progressBar->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG); while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) { $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($items as $data) { $this->progressBar->advance(LogManager::LOG_LEVEL_DEBUG); if ($recordTransformer) { /** @var Record $record */ $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]); /** @var Record $destRecord */ $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($record, $destRecord); } else { $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]); } $destinationRecords->addRecord($destRecord); } $this->destination->saveRecords($destinationName, $destinationRecords); } $this->progress->addProcessedEntity($this, $stage, $sourceDocName); $this->progressBar->finish(LogManager::LOG_LEVEL_DEBUG); } $this->progressBar->finish(LogManager::LOG_LEVEL_INFO); return true; }
public function testGetMapEmptyDestinationDocumentName() { $sourceDocument = $this->getMock('\\Migration\\Resource\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($sourceDocument)); $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['transform'], [], '', false); $recordTransformer->expects($this->never())->method('transform'); $this->data->perform(); }
/** * Get iterations count for step * * @return int */ protected function getIterationsCount() { $iterations = 0; foreach (array_keys($this->readerGroups->getGroup('source_documents')) as $document) { $iterations += $this->source->getRecordsCount($document); } return $iterations; }
/** * @param string $sourceDocument * @return \Magento\Framework\DB\Select */ protected function getConfigurablePrice($sourceDocument) { $sourceDocumentName = $this->source->addDocumentPrefix($sourceDocument); $fields = ['store_id' => 'website_id', 'value' => 'pricing_value', 'entity_id' => 'l.product_id', 'attribute_id' => 'cpsa.attribute_id']; /** @var \Magento\Framework\DB\Select $select */ $select = $this->sourceAdapter->getSelect(); $select->from($sourceDocumentName, $fields)->joinInner(['cpsa' => $this->source->addDocumentPrefix('catalog_product_super_attribute')], 'cpsa.product_super_attribute_id = ' . $sourceDocumentName . '.product_super_attribute_id', [])->joinInner(['l' => $this->source->addDocumentPrefix('catalog_product_super_link')], 'cpsa.product_id = l.parent_id', [])->joinInner(['a' => $this->source->addDocumentPrefix('catalog_product_super_attribute')], 'l.parent_id = a.product_id', [])->joinInner(['cp' => $this->source->addDocumentPrefix('catalog_product_entity_int')], 'l.product_id = cp.entity_id AND cp.attribute_id = a.attribute_id AND cp.store_id = ' . $sourceDocumentName . '.website_id', [])->joinInner(['apd' => $this->source->addDocumentPrefix('catalog_product_super_attribute_pricing')], 'a.product_super_attribute_id = apd.product_super_attribute_id AND apd.pricing_value = ' . $sourceDocumentName . '.pricing_value AND cp.value = apd.value_index', [])->joinInner(['le' => $this->source->addDocumentPrefix('catalog_product_entity')], 'le.entity_id = l.product_id', []); return $select; }
public function testPerformCheckLogsClearFailed() { $dstDocName = 'config_data'; $this->map->expects($this->once())->method('getDocumentMap')->willReturn($dstDocName); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([['config_data', true, 3], ['document_to_clear', true, 1]]); $this->logger->expects($this->once())->method('warning')->with('Log documents in the destination resource are not cleared'); $this->assertFalse($this->volume->perform()); }
/** * Fulfill temporary table with redirects * * @param \Migration\Resource\Adapter\Mysql $adapter * @return void */ protected function collectRedirects(\Migration\Resource\Adapter\Mysql $adapter) { $select = $adapter->getSelect(); $select->from(['r' => $this->source->addDocumentPrefix('enterprise_url_rewrite')], ['id' => 'IFNULL(NULL, NULL)', 'request_path' => 'r.request_path', 'target_path' => 'r.target_path', 'is_system' => 'r.is_system', 'store_id' => "s.store_id", 'entity_type' => "trim('custom')", 'redirect_type' => "(SELECT CASE eurr.options WHEN 'RP' THEN 301 WHEN 'R' THEN 302 ELSE 0 END)", 'product_id' => "trim('0')", 'category_id' => "trim('0')", 'priority' => "trim('2')"]); $select->join(['eurrr' => $this->source->addDocumentPrefix('enterprise_url_rewrite_redirect_rewrite')], 'eurrr.url_rewrite_id = r.url_rewrite_id', []); $select->join(['eurr' => $this->source->addDocumentPrefix('enterprise_url_rewrite_redirect')], 'eurrr.redirect_id = eurr.redirect_id', []); $select->join(['s' => $this->source->addDocumentPrefix('core_store')], 's.store_id > 0', []); $query = $select->insertFromSelect($this->source->addDocumentPrefix($this->tableName)); $select->getAdapter()->query($query); }
/** * @param string $sourceGridDocumentName * @return array */ protected function getEntityIdsFromSourceGrid($sourceGridDocumentName) { /** @var \Migration\Resource\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); /** @var \Magento\Framework\DB\Select $select */ $select = $adapter->getSelect(); $select->from($this->source->addDocumentPrefix($sourceGridDocumentName), 'entity_id'); $ids = $select->getAdapter()->fetchCol($select); return $ids; }
/** * @return bool */ public function perform() { $sourceDocuments = $this->source->getDocumentList(); $this->progressBar->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceDocName) { $this->progressBar->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $sourceCount = $this->source->getRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progressBar->finish(); return $this->checkForErrors(); }
/** * @return array */ protected function getAttributeIds() { if (empty($this->attributeIds)) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from($this->source->addDocumentPrefix('eav_attribute'), ['attribute_id'])->where('attribute_code = ?', $this->attributeCode); $this->attributeIds = array_flip($query->getAdapter()->fetchCol($query)); } return $this->attributeIds; }
protected function setupFieldsValidation() { $fields = ['field1' => []]; $structure = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($document)); }
/** * Volume check * * @return bool */ protected function volume() { $result = true; $this->progress->start(1); $result &= $this->source->getRecordsCount(self::SOURCE) == $this->destination->getRecordsCount(self::DESTINATION); if (!$result) { $this->logger->warning('Mismatch of entities in the document: url_rewrite'); } $this->progress->advance(); $this->progress->finish(); return (bool) $result; }
/** * @return bool */ public function perform() { $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); $this->progress->start($this->getIterationsCount()); foreach ($sourceDocuments as $sourceDocName) { $this->progress->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $sourceCount = $this->source->getRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } if (!$this->checkCleared(array_keys($this->readerGroups->getGroup('destination_documents_to_clear')))) { $this->errors[] = 'Log documents in the destination resource are not cleared'; } $this->progress->finish(); return $this->checkForErrors(); }