Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
 /**
  * Process errors
  *
  * @param int $errorLevel
  * @return bool
  */
 protected function checkForErrors($errorLevel = Logger::WARNING)
 {
     foreach ($this->errors as $error) {
         $this->logger->addRecord($errorLevel, $error);
     }
     return empty($this->errors);
 }
 /**
  * Process errors
  *
  * @return bool
  */
 protected function checkForErrors()
 {
     foreach ($this->errors as $error) {
         $this->logger->error($error);
     }
     return empty($this->errors);
 }
Ejemplo n.º 5
0
 public function testIntegrityDestinationFail()
 {
     $this->progress->expects($this->once())->method('start')->with(1);
     $this->progress->expects($this->once())->method('advance');
     $this->progress->expects($this->never())->method('finish');
     $this->source->expects($this->once())->method('getDocumentList')->willReturn(['core_config_data']);
     $this->destination->expects($this->once())->method('getDocumentList')->willReturn([]);
     $this->logger->expects($this->once())->method('error')->with('Integrity check failed due to "core_config_data" document does not exist in the destination resource');
     $this->settings = new Settings($this->destination, $this->source, $this->logger, $this->progress, $this->recordFactory, $this->readerSettings, $this->handlerManagerFactory, 'integrity');
     $this->assertFalse($this->settings->perform());
 }
Ejemplo n.º 6
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());
 }
Ejemplo n.º 7
0
 /**
  * {@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();
 }
Ejemplo n.º 8
0
 public function testPerformWithError()
 {
     $eavAttributes = ['eav_attribute_1' => ['attribute_id' => '1', 'attribute_code' => 'attribute_code_1', 'attribute_model' => 1, 'backend_model' => 1, 'frontend_model' => 1, 'source_model' => 1, 'frontend_input_renderer' => 1, 'data_model' => 1], 'eav_attribute_2' => ['attribute_id' => '2', 'attribute_code' => 'attribute_code_2', 'attribute_model' => 1, 'backend_model' => 1, 'frontend_model' => 1, 'source_model' => 1, 'frontend_input_renderer' => 1, 'data_model' => 1]];
     $this->progress->expects($this->once())->method('start');
     $this->progress->expects($this->once())->method('finish');
     $this->progress->expects($this->any())->method('advance');
     $this->initialData->expects($this->atLeastOnce())->method('getAttributes')->willReturnMap([['source', $eavAttributes], ['destination', $eavAttributes]]);
     $this->helper->expects($this->any())->method('getDestinationRecords')->willReturn($eavAttributes);
     $this->helper->expects($this->any())->method('getSourceRecordsCount')->willReturnMap([['eav_attribute_set', 1], ['eav_attribute_group', 1], ['copy_document_1', 2], ['copy_document_2', 2]]);
     $this->initialData->expects($this->once())->method('getAttributeSets')->willReturn(1);
     $this->initialData->expects($this->once())->method('getAttributeGroups')->willReturn(1);
     $this->helper->expects($this->any())->method('getDestinationRecordsCount')->willReturn(1);
     $this->logger->expects($this->atLeastOnce())->method('warning');
     $this->assertFalse($this->volume->perform());
 }
Ejemplo n.º 9
0
 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());
 }
Ejemplo n.º 10
0
 /**
  * @return bool
  */
 protected function volume()
 {
     $result = true;
     $this->progress->start(1);
     $this->progress->advance();
     $ratingsShouldBeActive = [];
     $ratingsIsActive = [];
     /** @var \Migration\Resource\Adapter\Mysql $adapter */
     $adapter = $this->destination->getAdapter();
     /** @var \Magento\Framework\DB\Select $select */
     $select = $adapter->getSelect()->from($this->getRatingStoreDocument(), ['rating_id'])->where('store_id > 0');
     $ratingsStore = $adapter->loadDataFromSelect($select);
     foreach ($ratingsStore as $rating) {
         $ratingsShouldBeActive[] = $rating['rating_id'];
     }
     $ratingsShouldBeActive = array_unique($ratingsShouldBeActive);
     /** @var \Magento\Framework\DB\Select $select */
     $select = $adapter->getSelect()->from($this->getRatingDocument(), ['rating_id'])->where('is_active = ?', 1);
     $ratings = $adapter->loadDataFromSelect($select);
     foreach ($ratings as $rating) {
         $ratingsIsActive[] = $rating['rating_id'];
     }
     if (count(array_intersect($ratingsShouldBeActive, $ratingsIsActive)) != count($ratingsShouldBeActive)) {
         $this->logger->error(sprintf('Mismatch of entities in the documents: %s, %s', self::RATING_TABLE_NAME, self::RATING_STORE_TABLE_NAME));
         $result = false;
     }
     $this->progress->finish();
     return $result;
 }
Ejemplo n.º 11
0
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testPerform()
 {
     $salesOrderToMigrate = [['entity_id' => '1', 'store_id' => '1'], ['entity_id' => '2', 'store_id' => '1'], ['entity_id' => '3', 'store_id' => '1']];
     $eavAttributesToMigrate = [['value_id' => '1', 'entity_type_id' => '1', 'attribute_id' => '1', 'store_id' => '1', 'entity_id' => '1', 'value' => '1'], ['value_id' => '2', 'entity_type_id' => '1', 'attribute_id' => '2', 'store_id' => '1', 'entity_id' => '1', 'value' => '2'], ['value_id' => '3', 'entity_type_id' => '1', 'attribute_id' => '1', 'store_id' => '1', 'entity_id' => '2', 'value' => '1'], ['value_id' => '4', 'entity_type_id' => '1', 'attribute_id' => '2', 'store_id' => '1', 'entity_id' => '3', 'value' => '2']];
     $objectManager = \Migration\TestFramework\Helper::getInstance()->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $config = $objectManager->get('\\Migration\\Config');
     $initialData = $objectManager->get('\\Migration\\Step\\SalesOrder\\InitialData');
     $destination = $objectManager->get('\\Migration\\ResourceModel\\Destination');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $data = $objectManager->create('\\Migration\\Step\\SalesOrder\\Data', ['logger' => $logger, 'config' => $config, 'initialData' => $initialData]);
     $volume = $objectManager->create('\\Migration\\Step\\SalesOrder\\Volume', ['logger' => $logger, 'config' => $config, 'initialData' => $initialData]);
     ob_start();
     $data->perform();
     $this->assertTrue($volume->perform());
     ob_end_clean();
     $this->assertEquals($eavAttributesToMigrate, $destination->getRecords('eav_entity_int', 0));
     $this->assertEquals($salesOrderToMigrate, $destination->getRecords('sales_order', 0));
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
 }
Ejemplo n.º 12
0
 /**
  * @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());
 }
 /**
  * Process missing entities and log them in to the file
  *
  * @return bool
  */
 protected function checkForErrors()
 {
     $isSuccess = true;
     if (!$this->hasMappedDocuments) {
         $this->logger->error('Mapped documents not found. Check your configuration.');
         return false;
     }
     if (isset($this->missingDocuments[MapInterface::TYPE_SOURCE])) {
         $isSuccess = false;
         $this->logger->error(sprintf('Source documents not mapped: %s', implode(',', array_keys($this->missingDocuments[MapInterface::TYPE_SOURCE]))));
     }
     if (isset($this->missingDocuments[MapInterface::TYPE_DEST])) {
         $isSuccess = false;
         $this->logger->error(sprintf('Destination documents not mapped: %s', implode(',', array_keys($this->missingDocuments[MapInterface::TYPE_DEST]))));
     }
     if (isset($this->missingDocumentFields[MapInterface::TYPE_SOURCE])) {
         $isSuccess = false;
         foreach ($this->missingDocumentFields[MapInterface::TYPE_SOURCE] as $document => $fields) {
             $this->logger->error(sprintf('Source fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields)));
         }
     }
     if (isset($this->missingDocumentFields[MapInterface::TYPE_DEST])) {
         $isSuccess = false;
         foreach ($this->missingDocumentFields[MapInterface::TYPE_DEST] as $document => $fields) {
             $this->logger->error(sprintf('Destination fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields)));
         }
     }
     return $isSuccess;
 }
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testPerform()
 {
     $helper = \Migration\TestFramework\Helper::getInstance();
     $objectManager = $helper->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $recordFactory = $objectManager->create('\\Migration\\ResourceModel\\RecordFactory');
     $progress = $objectManager->create('\\Migration\\App\\ProgressBar\\LogLevelProcessor');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $mapReader = $objectManager->create('\\Migration\\Reader\\Settings');
     $handlerManagerFactory = $objectManager->get('\\Migration\\Handler\\ManagerFactory');
     $destination = $objectManager->get('\\Migration\\ResourceModel\\Destination');
     $source = $objectManager->get('\\Migration\\ResourceModel\\Source');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $data = $objectManager->create('\\Migration\\Step\\Settings\\Data', ['destination' => $destination, 'source' => $source, 'logger' => $logger, 'progress' => $progress, 'recordFactory' => $recordFactory, 'mapReader' => $mapReader, 'handlerManagerFactory' => $handlerManagerFactory]);
     ob_start();
     $data->perform();
     ob_end_clean();
     $migratedData = $destination->getRecords('core_config_data', 0);
     $migratedDataExpected = [['config_id' => 1, 'scope' => 'default', 'scope_id' => 0, 'path' => 'web/seo/use_rewrites', 'value' => 1], ['config_id' => 2, 'scope' => 'default', 'scope_id' => 0, 'path' => 'web/unsecure/base_url', 'value' => 'http://magento2.dev/'], ['config_id' => 3, 'scope' => 'default', 'scope_id' => 0, 'path' => 'admin/security/session_lifetime', 'value' => 90], ['config_id' => 4, 'scope' => 'default', 'scope_id' => 0, 'path' => 'catalog/seo/product_url_suffix', 'value' => '.phtml'], ['config_id' => 5, 'scope' => 'default', 'scope_id' => 0, 'path' => 'my/extension/path', 'value' => 'value1']];
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
     $this->assertEquals($migratedDataExpected, $migratedData);
 }
 /**
  * @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();
 }
Ejemplo n.º 16
0
 public function testPerform()
 {
     $progress = $this->getMock('Migration\\App\\Progress', ['getProcessedEntities', 'addProcessedEntity'], [], '', false);
     $progress->expects($this->once())->method('getProcessedEntities')->will($this->returnValue([]));
     $progress->expects($this->any())->method('addProcessedEntity');
     $helper = \Migration\TestFramework\Helper::getInstance();
     $objectManager = $helper->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $logger->pushHandler($objectManager->create('\\Migration\\Logger\\ConsoleHandler'));
     $config = $objectManager->get('\\Migration\\Config');
     $destination = $objectManager->get('\\Migration\\Resource\\Destination');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $map = $objectManager->create('\\Migration\\Step\\Map\\Data', ['logger' => $logger, 'config' => $config, 'progress' => $progress]);
     ob_start();
     $map->perform();
     ob_end_clean();
     $migratedData = $destination->getRecords('table_without_data', 0);
     $migratedDataExpected = [['key' => 1, 'field1' => 1, 'field2' => 2, 'field3' => 3], ['key' => 2, 'field1' => 2, 'field2' => 3, 'field3' => 4], ['key' => 3, 'field1' => 3, 'field2' => 4, 'field3' => 5], ['key' => 4, 'field1' => 4, 'field2' => 5, 'field3' => 6], ['key' => 5, 'field1' => 5, 'field2' => 5, 'field3' => 5], ['key' => 6, 'field1' => 6, 'field2' => 6, 'field3' => 7], ['key' => 7, 'field1' => 7, 'field2' => 7, 'field3' => 7]];
     $migratedDataIgnored = $destination->getRecords('table_ignored', 0);
     $migratedDataIgnoredExpected = [];
     $migratedDataPresetValue = $destination->getRecords('common_table', 0);
     $migratedDataPresetValueExpected = [['key' => 1, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 2, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 3, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 4, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 5, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 6, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 7, 'dest_field_ignored' => 0, 'common_field' => 123]];
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
     $this->assertEquals($migratedDataExpected, $migratedData);
     $this->assertEquals($migratedDataIgnoredExpected, $migratedDataIgnored);
     $this->assertEquals($migratedDataPresetValueExpected, $migratedDataPresetValue);
 }
Ejemplo n.º 17
0
 public function testIntegrityWithoutMap()
 {
     $objectManager = \Migration\TestFramework\Helper::getInstance()->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/config-with-empty-map.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $logger->pushHandler($objectManager->create('\\Migration\\Logger\\ConsoleHandler'));
     $config = $objectManager->get('\\Migration\\Config');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     /** @var \Migration\Step\Map\Integrity $map */
     $map = $objectManager->create('\\Migration\\Step\\Map\\Integrity', ['logger' => $logger, 'config' => $config]);
     ob_start();
     $map->perform();
     ob_end_clean();
     $messages = [];
     $messages[] = 'Source documents not mapped: ';
     $messages[] = 'source_table_1,source_table_2,source_table_ignored,source_table_renamed,table_with_data';
     $messages[] = 'Destination documents not mapped: ';
     $messages[] = 'dest_table_1,dest_table_2,dest_table_ignored,dest_table_renamed,table_without_data';
     $messages[] = 'Source fields not mapped. ';
     $messages[] = 'Document: common_table. Fields: source_field_ignored';
     $messages[] = 'Destination fields not mapped. ';
     $messages[] = 'Document: common_table. Fields: dest_field_ignored';
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertTrue(isset($logOutput[\Monolog\Logger::ERROR]));
     $errors = implode("\n", $logOutput[\Monolog\Logger::ERROR]);
     foreach ($messages as $text) {
         $this->assertContains($text, $errors);
     }
 }
Ejemplo n.º 18
0
 /**
  * @return void
  */
 protected function optionReset()
 {
     if ($this->getArg('reset') === true) {
         $this->logger->info('Reset the current position of migration to start from the beginning');
         $this->progress->reset();
     }
 }
 /**
  * @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());
 }
Ejemplo n.º 20
0
 public function testPerform()
 {
     $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(['class' => 'Handler\\Class']);
     $sourceDocument = $this->getMock('\\Migration\\Resource\\Document', ['getRecords', 'getStructure'], [], '', false);
     $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($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);
     $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(4))->method('getRecords')->will($this->returnValue($bulk));
     $this->source->expects($this->at(5))->method('getRecords')->will($this->returnValue([]));
     $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->once())->method('clearDocument')->with($dstDocName);
     $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => $sourceDocName])->willReturn(true);
     $this->data->perform();
 }
Ejemplo n.º 21
0
 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();
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(1);
     $this->progress->advance();
     $documents = $this->destination->getDocumentList();
     if (!in_array(self::RATING_TABLE_NAME, $documents) || !in_array(self::RATING_STORE_TABLE_NAME, $documents)) {
         $this->logger->error(sprintf('"%s" or "%s" documents do not exist in the destination resource', self::RATING_TABLE_NAME, self::RATING_STORE_TABLE_NAME));
         return false;
     }
     $structureRating = $this->destination->getDocument(self::RATING_TABLE_NAME)->getStructure()->getFields();
     if (!array_key_exists('is_active', $structureRating)) {
         $this->logger->error(sprintf('"is_active" field does not exist in "%s" document of' . ' the destination resource', self::RATING_TABLE_NAME));
         return false;
     }
     $this->progress->finish();
     return true;
 }
Ejemplo n.º 23
0
 /**
  * @param StageInterface $object
  * @param string $step
  * @param string $stage
  * @return bool
  */
 protected function runStage($object, $step, $stage)
 {
     $this->logger->info('started', ['step' => $step, 'stage' => $stage, 'mode' => $this->mode]);
     if ($this->progress->isCompleted($object, $stage)) {
         return true;
     }
     try {
         $result = $object->perform();
     } catch (\Migration\Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
     if ($result && $this->canBeCompleted) {
         $this->progress->saveResult($object, $stage, $result);
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(1);
     $this->progress->advance();
     $documents = $this->source->getDocumentList();
     if (!in_array(self::CONFIG_TABLE_NAME_SOURCE, $documents)) {
         $this->logger->error(sprintf('Integrity check failed due to "%s" document does not exist in the source resource', self::CONFIG_TABLE_NAME_SOURCE));
         return false;
     }
     $documents = $this->destination->getDocumentList();
     if (!in_array(self::CONFIG_TABLE_NAME_DESTINATION, $documents)) {
         $this->logger->error(sprintf('Integrity check failed due to "%s" document does not exist in the destination resource', self::CONFIG_TABLE_NAME_DESTINATION));
         return false;
     }
     $this->progress->finish();
     return true;
 }
Ejemplo n.º 25
0
 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());
 }
Ejemplo n.º 26
0
 public function testRunWithException2()
 {
     $this->shell->setRawArgs(['data', '--config', 'file/to/config.xml']);
     $this->logManager->expects($this->once())->method('process');
     $mode = $this->getMock('\\Migration\\Mode\\Data', [], [], '', false);
     $mode->expects($this->any())->method('run')->willThrowException(new \Migration\Exception('test error message'));
     $this->modeFactory->expects($this->once())->method('create')->with('data')->willReturn($mode);
     $this->logger->expects($this->once())->method('error')->with($this->stringContains('test error message'));
     $this->shell->run();
 }
Ejemplo n.º 27
0
 /**
  * @return void
  */
 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('addRecord')->with(Logger::WARNING, 'Mismatch of entities in the document: ' . $dstDocName);
     $this->helper->expects($this->once())->method('getFieldsUpdateOnDuplicate')->with($dstDocName)->willReturn(false);
     $this->assertFalse($this->volume->perform());
 }
 /**
  * {@inheritdoc}
  */
 protected function volume()
 {
     $this->progress->start(1);
     $this->getRewritesSelect();
     $this->progress->advance();
     $result = $this->source->getRecordsCount($this->tableName) == $this->destination->getRecordsCount('url_rewrite');
     if (!$result) {
         $this->logger->error('Mismatch of entities in the document: url_rewrite');
     }
     $this->progress->finish();
     return $result;
 }
 /**
  * Volume check
  *
  * @return bool
  */
 protected function volume()
 {
     $result = true;
     $this->progress->start(1);
     $result &= $this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites(true) == $this->destination->getRecordsCount(self::DESTINATION);
     if (!$result) {
         $this->logger->error('Mismatch of entities in the document: url_rewrite');
     }
     $this->progress->advance();
     $this->progress->finish();
     return (bool) $result;
 }
Ejemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $updateData = $this->helper->getUpdateData();
     $selectData = $this->helper->getSelectData();
     $sourceDocuments = $this->readerGroups->getGroup('source_documents');
     foreach ($sourceDocuments as $sourceDocName => $idKey) {
         if ($this->source->getRecordsCount($this->source->getDeltaLogName($sourceDocName)) == 0) {
             continue;
         }
         $items = $this->source->getChangedRecords($sourceDocName, $idKey, 0, true);
         if (empty($items)) {
             continue;
         }
         $this->logger->debug(sprintf('%s has changes', $sourceDocName));
         if (!$this->eolOnce) {
             $this->eolOnce = true;
             echo PHP_EOL;
         }
         $gridIdKey = $updateData[$sourceDocName]['idKey'];
         $page = 1;
         do {
             $ids = [];
             foreach ($items as $data) {
                 echo '.';
                 $ids[] = $data[$gridIdKey];
             }
             foreach ($updateData[$sourceDocName]['methods'] as $method) {
                 echo '.';
                 $destinationDocumentName = $selectData[$method]['destination'];
                 $select = call_user_func_array([$this->data, $method], [$selectData[$method]['columns'], $ids]);
                 $this->destination->getAdapter()->insertFromSelect($select, $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
             }
             $documentNameDelta = $this->source->getDeltaLogName($sourceDocName);
             $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta);
             $this->markRecordsProcessed($documentNameDelta, $idKey, $ids);
         } while (!empty($items = $this->source->getChangedRecords($sourceDocName, $idKey, $page++)));
     }
     return true;
 }