/** * @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($sourceDocumentName); while (!empty($bulk = $this->getRecords($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); $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
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\\Resource\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($sourceDocument)); $destinationDocument = $this->getMock('\\Migration\\Resource\\Document', [], [], '', false); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['init', 'transform'], [], '', false); $this->recordTransformerFactory->expects($this->once())->method('create')->will($this->returnValue($recordTransformer)); $recordTransformer->expects($this->once())->method('init'); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->at(3))->method('getRecords')->will($this->returnValue($bulk)); $this->source->expects($this->at(4))->method('getRecords')->will($this->returnValue([])); $this->source->expects($this->any())->method('getRecordsCount')->will($this->returnValue(2)); $destinationRecords = $this->getMock('\\Migration\\Resource\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $srcRecord = $this->getMock('\\Migration\\Resource\\Record', [], [], '', false); $dstRecord = $this->getMock('\\Migration\\Resource\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($srcRecord)); $this->recordFactory->expects($this->at(1))->method('create')->will($this->returnValue($dstRecord)); $recordTransformer->expects($this->once())->method('transform')->with($srcRecord, $dstRecord); $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(); }
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 testData() { $stores = new Stores($this->progress, $this->logger, $this->source, $this->destination, $this->recordTransformerFactory, $this->recordFactory, 'data'); $this->assertTrue($stores->perform()); foreach ($this->destinationDocuments as $documentName => $recordsCount) { $this->assertEquals($recordsCount, count($this->destination->getRecords($documentName, 0))); } }
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()); }
/** * @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(); }
/** * @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 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(); }
/** * {@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(); }
/** * @param array $documents * @return void */ protected function clearLog($documents) { foreach ($documents as $documentName) { $this->progress->advance(); $this->destination->clearDocument($documentName); } }
/** * @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 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); }
/** * @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))); }
/** * @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; }
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(); }
/** * @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); }
public function testHandle() { $fieldNameRuleId = 'rule_id'; $fieldNameForNormalization = 'website_ids'; $idsForNormalization = '1,2,3'; $normalizedData = [[$fieldNameRuleId => 1, $this->normalizationField => 1], [$fieldNameRuleId => 1, $this->normalizationField => 2], [$fieldNameRuleId => 1, $this->normalizationField => 3]]; /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMockBuilder('Migration\\Resource\\Record')->setMethods(['getValue', 'getFields'])->disableOriginalConstructor()->getMock(); /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */ $oppositeRecord = $this->getMockBuilder('Migration\\Resource\\Record')->disableOriginalConstructor()->getMock(); $recordToHandle->expects($this->once())->method('getFields')->willReturn([$fieldNameRuleId, $fieldNameForNormalization]); $recordToHandle->expects($this->any())->method('getValue')->willReturnMap([[$fieldNameRuleId, 1], [$fieldNameForNormalization, $idsForNormalization]]); $this->destination->expects($this->once())->method('clearDocument')->with($this->normalizationDocument)->willReturnSelf(); $this->destination->expects($this->once())->method('saveRecords')->with($this->normalizationDocument, $normalizedData)->willReturnSelf(); $this->handler->setField($fieldNameForNormalization); $this->handler->handle($recordToHandle, $oppositeRecord); }
public function testGetDestinationRecordsNoKey() { $row = ['key' => 'key_value', 'field' => 'field_value']; $this->map->expects($this->once())->method('getDocumentMap')->with('test_source_document', MapInterface::TYPE_SOURCE)->will($this->returnValue('test_dest_document')); $this->destination->expects($this->once())->method('getRecordsCount')->will($this->returnValue(1)); $this->destination->expects($this->once())->method('getRecords')->with('test_dest_document', 0, 1)->will($this->returnValue([$row])); $this->assertEquals([$row], $this->helper->getDestinationRecords('test_source_document')); }
/** * Delete backed up documents * @return void */ public function deleteBackups() { foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) { $documentName = $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); if ($documentName) { $this->destination->deleteDocumentBackup($documentName); } } }
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()); }
/** * @param string $sourceDocName * @param array $keyFields * @return array */ public function getDestinationRecords($sourceDocName, $keyFields = []) { $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); $data = []; $count = $this->destination->getRecordsCount($destinationDocumentName); foreach ($this->destination->getRecords($destinationDocumentName, 0, $count) as $row) { if ($keyFields) { $key = []; foreach ($keyFields as $keyField) { $key[] = $row[$keyField]; } $data[implode('-', $key)] = $row; } else { $data[] = $row; } } return $data; }
/** * @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 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->helper->getSourceRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progress->finish(); return $this->checkForErrors(); }
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)); }
/** * @param array $columns * @param array $entityIds * @return \Magento\Framework\DB\Select */ public function getSelectSalesCreditmemoGrid(array $columns, $entityIds = []) { foreach ($columns as $key => $value) { $columns[$key] = new \Zend_Db_Expr($value); } /** @var \Magento\Framework\DB\Select $select */ $select = $this->destinationAdapter->getSelect(); $select->from(['sales_creditmemo' => $this->destination->addDocumentPrefix('sales_creditmemo')], [])->joinLeft(['sales_order' => $this->destination->addDocumentPrefix('sales_order')], 'sales_creditmemo.order_id = sales_order.entity_id', [])->joinLeft(['sales_shipping_address' => $this->destination->addDocumentPrefix('sales_order_address')], 'sales_creditmemo.shipping_address_id = sales_shipping_address.entity_id', [])->joinLeft(['sales_billing_address' => $this->destination->addDocumentPrefix('sales_order_address')], 'sales_creditmemo.billing_address_id = sales_billing_address.entity_id', [])->where('sales_creditmemo.entity_id in (?)', $entityIds); $select->columns($columns); return $select; }
/** * 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 array */ protected function getSalesCreditMemoColumnsGrid() { $paymentSelect = sprintf('(SELECT `sales_order_payment`.`method` FROM `%s` as sales_order_payment WHERE (`parent_id` = sales_order.entity_id) LIMIT 1)', $this->destination->addDocumentPrefix('sales_order_payment')); $fields = array_keys($this->destination->getStructure('sales_creditmemo_grid')->getFields()); $result = []; $fields = array_fill_keys($fields, null); $columns = ['entity_id' => 'sales_creditmemo.entity_id', 'increment_id' => 'sales_creditmemo.increment_id', 'created_at' => 'sales_creditmemo.created_at', 'updated_at' => 'sales_creditmemo.updated_at', 'order_id' => 'sales_order.entity_id', 'order_increment_id' => 'sales_order.increment_id', 'order_created_at' => 'sales_order.created_at', 'billing_name' => 'trim(concat(ifnull(sales_billing_address.firstname, \'\'), \' \' ' . ',ifnull(sales_billing_address.lastname, \'\')))', 'state' => 'sales_creditmemo.state', 'base_grand_total' => 'sales_creditmemo.base_grand_total', 'order_status' => 'sales_order.status', 'store_id' => 'sales_creditmemo.store_id', 'billing_address' => 'trim(concat(ifnull(sales_billing_address.street, \'\'), \', \' ' . ',ifnull(sales_billing_address.city, \'\'), \', \' ,ifnull(sales_billing_address.region,' . ' \'\'), \', \' ,ifnull(sales_billing_address.postcode, \'\')))', 'shipping_address' => 'trim(concat(ifnull(sales_shipping_address.street, \'\'), \', \' ' . ',ifnull(sales_shipping_address.city, \'\'), \', \' ,ifnull(sales_shipping_address.region,' . ' \'\'), \', \' ,ifnull(sales_shipping_address.postcode, \'\')))', 'customer_name' => 'trim(concat(ifnull(sales_order.customer_firstname, \'\'), \' \' ' . ',ifnull(sales_order.customer_lastname, \'\')))', 'customer_email' => 'sales_order.customer_email', 'customer_group_id' => 'sales_order.customer_group_id', 'payment_method' => $paymentSelect, 'shipping_information' => 'sales_order.shipping_description', 'subtotal' => 'sales_creditmemo.subtotal', 'shipping_and_handling' => 'sales_creditmemo.shipping_amount', 'adjustment_positive' => 'sales_creditmemo.adjustment_positive', 'adjustment_negative' => 'sales_creditmemo.adjustment_negative', 'order_base_grand_total' => 'sales_order.base_grand_total']; foreach (array_keys($fields) as $key) { $result[$key] = isset($columns[$key]) ? $columns[$key] : 'null'; } return $result; }
/** * @param array $documents * @return bool */ protected function checkCleared($documents) { $documentsAreEmpty = true; foreach ($documents as $documentName) { $this->progress->advance(); $destinationCount = $this->destination->getRecordsCount($documentName); if ($destinationCount > 0) { $documentsAreEmpty = false; break; } $destinationCount = null; } return $documentsAreEmpty; }
/** * Volume check * * @return bool */ protected function volume() { $result = true; $this->progress->start(count($this->getDocumentList())); foreach ($this->getDocumentList() as $sourceName => $destinationName) { $this->progress->advance(); if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) { $this->logger->error('Mismatch of entities in the document: ' . $destinationName); $result = false; } } $this->progress->finish(); return $result; }
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()); }