/**
  * @return void
  */
 public function testPerform()
 {
     $recordsData = ['record_1' => ['field_name' => []], 'record_2' => ['field_name' => []], 'record_3' => ['field_name' => []]];
     $this->progress->expects($this->once())->method('start')->with('3');
     $this->progress->expects($this->any())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $fields = ['field_name' => []];
     $differentFields = ['field_different' => []];
     $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock();
     $structure->expects($this->at(0))->method('getFields')->willReturn($differentFields);
     $structure->expects($this->any())->method('getFields')->willReturn($fields);
     $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getName', 'getRecords', 'getStructure'])->getMock();
     $document->expects($this->any())->method('getStructure')->willReturn($structure);
     $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock();
     $document->expects($this->any())->method('getRecords')->willReturn($recordsCollection);
     $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['getFields', 'setValue'])->getMock();
     $record->expects($this->once())->method('getFields')->willReturn(array_keys($fields));
     $record->expects($this->once())->method('setValue')->willReturnSelf();
     $this->recordFactory->expects($this->any())->method('create')->with(['document' => $document])->will($this->returnValue($record));
     $recordsCollection->expects($this->any())->method('addRecord')->with($record);
     $this->source->expects($this->any())->method('getDocument')->willReturn($document);
     $this->source->expects($this->any())->method('getRecords')->willReturnMap([['core_store', 0, null, $recordsData], ['core_store_group', 0, null, $recordsData], ['core_website', 0, null, $recordsData]]);
     $this->destination->expects($this->any())->method('getDocument')->willReturn($document);
     $this->destination->expects($this->any())->method('clearDocument')->willReturnSelf();
     $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']);
     $this->data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper);
     $this->data->perform();
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $destinationDocument = $this->destination->getDocument(self::CONFIG_TABLE_NAME_DESTINATION);
     $recordsCountSource = $this->source->getRecordsCount(self::CONFIG_TABLE_NAME_SOURCE);
     $recordsCountDestination = $this->destination->getRecordsCount(self::CONFIG_TABLE_NAME_DESTINATION);
     $this->progress->start($recordsCountSource);
     $sourceRecords = $this->source->getRecords(self::CONFIG_TABLE_NAME_SOURCE, 0, $recordsCountSource);
     $destinationRecords = $this->destination->getRecords(self::CONFIG_TABLE_NAME_DESTINATION, 0, $recordsCountDestination);
     foreach ($sourceRecords as $sourceRecord) {
         $this->progress->advance();
         if (!$this->readerSettings->isNodeIgnored($sourceRecord[self::CONFIG_FIELD_PATH])) {
             $sourceRecordPathMapped = $this->readerSettings->getNodeMap($sourceRecord[self::CONFIG_FIELD_PATH]);
             foreach ($destinationRecords as &$destinationRecord) {
                 if ($destinationRecord[self::CONFIG_FIELD_SCOPE] == $sourceRecord[self::CONFIG_FIELD_SCOPE] && $destinationRecord[self::CONFIG_FIELD_SCOPE_ID] == $sourceRecord[self::CONFIG_FIELD_SCOPE_ID] && $destinationRecord[self::CONFIG_FIELD_PATH] == $sourceRecordPathMapped) {
                     $record = $this->applyHandler($destinationDocument, $sourceRecord, $destinationRecord);
                     $destinationRecord[self::CONFIG_FIELD_VALUE] = $record->getValue(self::CONFIG_FIELD_VALUE);
                     continue 2;
                 }
             }
             $record = $this->applyHandler($destinationDocument, $sourceRecord, []);
             $record->setValue(self::CONFIG_FIELD_PATH, $sourceRecordPathMapped);
             $destinationRecords[] = $record->getData();
         }
     }
     foreach ($destinationRecords as &$destinationRecord) {
         unset($destinationRecord[self::CONFIG_FIELD_CONFIG_ID]);
     }
     $this->destination->clearDocument(self::CONFIG_TABLE_NAME_DESTINATION);
     $this->destination->saveRecords(self::CONFIG_TABLE_NAME_DESTINATION, $destinationRecords);
     $this->progress->finish();
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(count($this->helper->getDocumentList()));
     $documents = $this->helper->getDocumentList();
     foreach ($documents as $sourceDocName => $destDocName) {
         $this->progress->advance();
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationDocument = $this->destination->getDocument($destDocName);
         $this->destination->clearDocument($destDocName);
         $pageNumber = 0;
         while (!empty($sourceRecords = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $recordsToSave = $destinationDocument->getRecords();
             foreach ($sourceRecords as $recordData) {
                 /** @var ResourceModel\Record $destinationRecord */
                 $destinationRecord = $this->recordFactory->create(['document' => $destinationDocument]);
                 if ($this->haveEqualStructure($sourceDocument, $destinationDocument)) {
                     $destinationRecord->setData($recordData);
                 } else {
                     $destinationRecord = $this->transformRecord($destinationRecord, $recordData);
                 }
                 $recordsToSave->addRecord($destinationRecord);
             }
             $this->destination->saveRecords($destinationDocument->getName(), $recordsToSave);
         }
     }
     $this->progress->finish();
     return true;
 }
 /**
  * @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();
 }
 /**
  * @return bool
  */
 public function perform()
 {
     // catalog_product_entity_tier_price should be migrated first to save same value_id as into magento1
     $sourceDocuments = array_keys($this->helper->getSourceDocumentFields());
     $this->progress->start(count($sourceDocuments), LogManager::LOG_LEVEL_INFO);
     $destinationName = $this->helper->getDestinationName();
     $this->destination->clearDocument($destinationName);
     $destDocument = $this->destination->getDocument($destinationName);
     foreach ($sourceDocuments as $sourceDocName) {
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($items as $recordData) {
                 unset($recordData['value_id']);
                 $this->progress->advance(LogManager::LOG_LEVEL_INFO);
                 $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $recordData]);
                 $destinationRecords->addRecord($destRecord);
             }
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
 /**
  * @return array
  */
 public function getStoreIds()
 {
     /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $query = $adapter->getSelect()->from($this->source->addDocumentPrefix($this->storeTable), ['store_id']);
     return $query->getAdapter()->fetchCol($query);
 }
 /**
  * {@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;
 }
 /**
  * @param int $valueId
  * @return int
  */
 protected function getEntityId($valueId)
 {
     /** @var Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $query = $adapter->getSelect()->from(['mg' => $this->source->addDocumentPrefix($this->mediaGalleryDocument)], [$this->field])->where("mg.{$this->valueIdField} = ?", $valueId);
     return (int) $query->getAdapter()->fetchOne($query);
 }
 /**
  * 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;
 }
 /**
  * @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->assertFalse($this->volume->perform());
 }
 /**
  * @return void
  */
 public function testPerform()
 {
     $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $this->progress->expects($this->once())->method('start')->with('3');
     $this->progress->expects($this->any())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $this->source->expects($this->any())->method('getDocument', 'getRecords')->willReturn($document);
     $this->destination->expects($this->any())->method('getDocument')->willReturn($document);
     $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']);
     $this->integrity = new Integrity($this->progress, $this->source, $this->destination, $this->helper);
     $this->assertTrue($this->integrity->perform());
 }
 /**
  * @param string $eavAttribute
  * @return \Magento\Framework\DB\Select
  */
 protected function getEavAttributeSelect($eavAttribute)
 {
     /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $select = $adapter->getSelect();
     $tables = [];
     foreach (array_keys($this->getDocumentList()) as $sourceDocument) {
         $tables[] = $this->source->addDocumentPrefix($sourceDocument);
     }
     $select->from($tables)->where($eavAttribute . ' is not null');
     return $select;
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $result = true;
     $this->progress->start(count($this->helper->getDocumentList()));
     foreach ($this->helper->getDocumentList() as $sourceName => $destinationName) {
         $this->progress->advance();
         $result &= (bool) $this->source->getDocument($sourceName);
         $result &= (bool) $this->destination->getDocument($destinationName);
     }
     $this->progress->finish();
     return (bool) $result;
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(count($this->helper->getDocumentList()));
     foreach ($this->helper->getDocumentList() as $sourceName => $destinationName) {
         $this->progress->advance();
         if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) {
             $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName;
         }
     }
     $this->progress->finish();
     return $this->checkForErrors(Logger::ERROR);
 }
 /**
  * @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 void
  */
 public function testGetSourceAttributes()
 {
     $entity = [0 => ['entity_id' => 1, 'value' => 'entity_value']];
     $mySqlAdapter = $this->getMock('\\Migration\\ResourceModel\\Adapter\\Mysql', ['getSelect', 'loadDataFromSelect'], [], '', false);
     $dbSelect = $this->getMock('\\Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $mySqlAdapter->expects($this->any())->method('getSelect')->willReturn($dbSelect);
     $this->source->expects($this->any())->method('getAdapter')->willReturn($mySqlAdapter);
     $this->source->expects($this->any())->method('addDocumentPrefix')->willReturnArgument(0);
     $dbSelect->expects($this->any())->method('from')->willReturnSelf();
     $dbSelect->expects($this->any())->method('where')->willReturnSelf();
     $mySqlAdapter->expects($this->once())->method('loadDataFromSelect')->willReturn($entity);
     $this->assertEquals($entity, $this->helper->getSourceAttributes('eav_attribute'));
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progressBar->start($this->getIterationsCount());
     foreach ($this->helper->getDocumentList() as $sourceDocumentName => $destinationDocumentName) {
         $this->progressBar->advance();
         $sourceRecordsCount = $this->source->getRecordsCount($sourceDocumentName);
         $destinationRecordsCount = $this->destination->getRecordsCount($destinationDocumentName);
         if ($sourceRecordsCount != $destinationRecordsCount) {
             $this->errors[] = 'Mismatch of entities in the document: ' . $destinationDocumentName;
         }
     }
     $this->progressBar->finish();
     return $this->checkForErrors();
 }
 /**
  * @return void
  */
 public function testPerform()
 {
     $fields = ['field1' => []];
     $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields));
     $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure));
     $this->map->expects($this->once())->method('getDocumentMap')->with('document1')->willReturn('document2');
     $this->source->expects($this->once())->method('getRecordsCount')->willReturn(3);
     $this->source->expects($this->once())->method('getDocument')->with('document1')->willReturn($document);
     $this->destination->expects($this->once())->method('getDocument')->with('document2')->willReturn($document);
     $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([['document2', true, [], 3]]);
     $this->assertTrue($this->volume->perform());
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(count($this->helper->getSourceDocumentFields()));
     $sourceTotal = 0;
     $destinationTotal = $this->destination->getRecordsCount($this->helper->getDestinationName());
     foreach (array_keys($this->helper->getSourceDocumentFields()) as $sourceName) {
         $sourceTotal += $this->source->getRecordsCount($sourceName);
         $this->progress->advance();
     }
     if ($sourceTotal != $destinationTotal) {
         $this->errors[] = 'Mismatch of amount of entities in documents';
     }
     $this->progress->finish();
     return $this->checkForErrors(Logger::ERROR);
 }
 /**
  * @return 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;
 }
 /**
  * @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());
 }
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testData()
 {
     $countCmsPageRewrites = 1;
     $recordsAmount = 123;
     $progressRecordsAmount = $recordsAmount + $countCmsPageRewrites;
     $this->source->expects($this->once())->method('getRecordsCount')->willReturn($recordsAmount);
     $this->progress->expects($this->at(0))->method('start')->with($this->equalTo($progressRecordsAmount));
     $sourceDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $this->source->expects($this->once())->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE))->willReturn($sourceDocument);
     $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $this->destination->expects($this->at(0))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION))->willReturn($destinationDocument);
     $destinationProductCategory = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->setMethods(['setValue', 'getRecords'])->disableOriginalConstructor()->getMock();
     $this->destination->expects($this->at(1))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY))->willReturn($destinationProductCategory);
     $this->destination->expects($this->exactly(2))->method('clearDocument')->withConsecutive([\Migration\Step\UrlRewrite\Version191to2000::DESTINATION], [\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY]);
     $this->source->expects($this->at(2))->method('getRecords')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE), $this->equalTo(0))->willReturn(['RecordData1']);
     $sourceRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock();
     $this->recordFactory->expects($this->at(0))->method('create')->with($this->equalTo(['document' => $sourceDocument, 'data' => 'RecordData1']))->willReturn($sourceRecord);
     $destinationRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock();
     $this->recordFactory->expects($this->at(1))->method('create')->with($this->equalTo(['document' => $destinationDocument]))->willReturn($destinationRecord);
     $destinationCategoryRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock();
     $this->recordFactory->expects($this->at(2))->method('create')->with($this->equalTo(['document' => $destinationProductCategory]))->willReturn($destinationCategoryRecord);
     $this->mockSourceRecordGetters($sourceRecord);
     $this->mockDestinationRecordSetters($destinationRecord);
     $this->mockDestinationCategorySetters($destinationCategoryRecord);
     $destinationProductCategory->expects($this->once())->method('getRecords')->willReturn($this->recordCollection);
     $destinationDocument->expects($this->once())->method('getRecords')->willReturn($this->recordCollection);
     $version = new \Migration\Step\UrlRewrite\Version191to2000($this->config, $this->source, $this->destination, $this->progress, $this->recordFactory, $this->logger, 'data');
     $this->assertTrue($version->perform());
 }
 /**
  * @param int $storeId
  * @return string
  */
 protected function getIncrementPrefix($storeId)
 {
     /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $select = $adapter->getSelect()->from(['cs' => $this->source->addDocumentPrefix($this->storeTable)], ['store_id' => 'csg.default_store_id'])->join(['csg' => $this->source->addDocumentPrefix($this->storeGroupTable)], 'csg.group_id = cs.group_id', [])->where('cs.store_id = ?', $storeId);
     return $select->getAdapter()->fetchOne($select);
 }
 /**
  * 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 ResourceModel\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->getDestDocumentName($document);
         if ($destDocumentName === false) {
             continue;
         }
         $sourcePatterns[] = sprintf('`%s`', $this->source->addDocumentPrefix($document));
         $destinationPatters[] = sprintf('`%s`', $this->destination->addDocumentPrefix($destDocumentName));
     }
     $newValue = str_replace($sourcePatterns, $destinationPatters, $recordToHandle->getValue($this->field));
     $recordToHandle->setValue($this->field, $newValue);
 }
 /**
  * @param string $documentName
  * @param string $idKey
  * @return void
  */
 protected function processChangedRecords($documentName, $idKey)
 {
     $items = $this->source->getChangedRecords($documentName, $idKey);
     if (empty($items)) {
         return;
     }
     if (!$this->eolOnce) {
         $this->eolOnce = true;
         echo PHP_EOL;
     }
     $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE);
     $sourceDocument = $this->source->getDocument($documentName);
     $destDocument = $this->destination->getDocument($destinationName);
     $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
     do {
         $destinationRecords = $destDocument->getRecords();
         $ids = [];
         foreach ($items as $data) {
             echo '.';
             $ids[] = $data[$idKey];
             $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords);
         }
         $this->destination->updateChangedRecords($destinationName, $destinationRecords);
         $documentNameDelta = $this->source->getDeltaLogName($documentName);
         $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta);
         $this->markRecordsProcessed($documentNameDelta, $idKey, $ids);
     } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey)));
 }
 /**
  * @return void
  */
 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'));
 }
 /**
  * @covers \Migration\Step\Log\Integrity::getIterationsCount
  * @return void
  */
 public function testPerformMainFlow()
 {
     $fields = ['field1' => ['DATA_TYPE' => 'int']];
     $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields));
     $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document1']));
     $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document2', 'document_to_clear']));
     $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure));
     $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['document1', MapInterface::TYPE_SOURCE, 'document2'], ['document2', MapInterface::TYPE_DEST, 'document1']]);
     $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($document));
     $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($document));
     $this->map->expects($this->any())->method('getFieldMap')->will($this->returnValue('field1'));
     $this->logger->expects($this->never())->method('error');
     $this->assertTrue($this->log->perform());
 }
 /**
  * @return void
  */
 public function testPerformJustCopy()
 {
     $sourceDocName = 'core_config_data';
     $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName]));
     $this->source->expects($this->any())->method('getRecordsCount')->will($this->returnValue(2));
     $dstDocName = 'config_data';
     $this->progress->expects($this->once())->method('getProcessedEntities')->will($this->returnValue([]));
     $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName));
     $this->map->expects($this->any())->method('getHandlerConfig')->willReturn([]);
     $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords', 'getStructure'], [], '', false);
     $bulk = [['id' => 4, 'name' => 'john']];
     $this->source->expects($this->any())->method('getRecords')->willReturnOnConsecutiveCalls($bulk, []);
     $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument);
     $this->source->expects($this->any())->method('getPageSize')->willReturn(100);
     $this->source->expects($this->any())->method('setLastLoadedRecord')->withConsecutive([$sourceDocName, $bulk[0]], [$sourceDocName, []]);
     $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getStructure', 'getRecords'])->getMock();
     $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument));
     $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock();
     $structure->expects($this->any())->method('getFields')->willReturn(['field' => []]);
     $sourceDocument->expects($this->any())->method('getStructure')->willReturn($structure);
     $destinationDocument->expects($this->any())->method('getStructure')->willReturn($structure);
     $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false);
     $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords));
     $dstRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false);
     $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($dstRecord));
     $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords);
     $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName);
     $this->data->perform();
 }
 /**
  * @return void
  */
 public function testHandle()
 {
     /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
     $recordToHandle = $this->getMockBuilder('Migration\\ResourceModel\\Record')->setMethods(['getValue', 'setValue', 'getFields'])->disableOriginalConstructor()->getMock();
     /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */
     $oppositeRecord = $this->getMockBuilder('Migration\\ResourceModel\\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);
 }