/**
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Migration\\Config')->disableOriginalConstructor()->setMethods(['getSource'])->getMock();
     $this->config->expects($this->any())->method('getSource')->will($this->returnValue(['type' => DatabaseStage::SOURCE_TYPE]));
     $this->source = $this->getMockBuilder('Migration\\ResourceModel\\Source')->disableOriginalConstructor()->setMethods(['getDocument', 'getRecordsCount', 'getAdapter', 'addDocumentPrefix', 'getRecords'])->getMock();
     $this->source->expects($this->any())->method('addDocumentPrefix')->willReturnCallback(function ($name) {
         return 'source_suffix_' . $name;
     });
     $this->destination = $this->getMockBuilder('Migration\\ResourceModel\\Destination')->disableOriginalConstructor()->setMethods(['getDocument', 'getRecordsCount', 'getAdapter', 'addDocumentPrefix', 'saveRecords'])->getMock();
     $this->destination->expects($this->any())->method('addDocumentPrefix')->willReturnCallback(function ($name) {
         return 'destination_suffix_' . $name;
     });
     $this->progress = $this->getMockBuilder('Migration\\App\\ProgressBar\\LogLevelProcessor')->disableOriginalConstructor()->setMethods(['start', 'finish', 'advance'])->getMock();
     $this->progress->expects($this->any())->method('start');
     $this->progress->expects($this->any())->method('finish');
     $this->progress->expects($this->any())->method('advance');
     $this->recordFactory = $this->getMockBuilder('Migration\\ResourceModel\\RecordFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->logger = $this->getMockBuilder('Migration\\Logger\\Logger')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->map = $this->getMockBuilder('Migration\\Reader\\Map')->disableOriginalConstructor()->setMethods(['getDocumentMap', 'init', 'getDocumentList', 'getDestDocumentsToClear'])->getMock();
     /** @var \Migration\Reader\MapFactory|\PHPUnit_Framework_MockObject_MockObject $mapFactory */
     $mapFactory = $this->getMockBuilder('Migration\\Reader\\MapFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $mapFactory->expects($this->any())->method('create')->with('customer_attr_map_file')->willReturn($this->map);
     $this->groups = $this->getMockBuilder('Migration\\Reader\\Groups')->disableOriginalConstructor()->getMock();
     $this->groups->expects($this->any())->method('getGroup')->with('source_documents')->willReturn(['source_document_1' => 'entity_id']);
     /** @var \Migration\Reader\GroupsFactory|\PHPUnit_Framework_MockObject_MockObject $groupsFactory */
     $groupsFactory = $this->getMockBuilder('Migration\\Reader\\GroupsFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $groupsFactory->expects($this->any())->method('create')->with('customer_attr_document_groups_file')->willReturn($this->groups);
     $this->logger = $this->getMockBuilder('Migration\\Logger\\Logger')->disableOriginalConstructor()->setMethods(['debug'])->getMock();
     $this->step = new Data($this->config, $this->source, $this->destination, $this->progress, $this->recordFactory, $mapFactory, $groupsFactory, $this->logger);
 }
 /**
  * @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;
 }
 /**
  * {@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();
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progress->start(1);
     $this->progress->advance();
     $ratingsShouldBeActive = [];
     $ratingsIsActive = [];
     /** @var \Migration\ResourceModel\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->errors[] = sprintf('Mismatch of entities in the documents: %s, %s', self::RATING_TABLE_NAME, self::RATING_STORE_TABLE_NAME);
     }
     $this->progress->finish();
     return $this->checkForErrors(Logger::ERROR);
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $this->helper->init();
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     $document = $this->helper->getDocumentList();
     $sourceDocumentName = $document['source'];
     $destinationDocumentName = $document['destination'];
     $destinationDocument = $this->destination->getDocument($destinationDocumentName);
     $pageNumber = 0;
     $this->logger->debug('migrating', ['table' => $sourceDocumentName]);
     $this->progress->start($this->source->getRecordsCount($sourceDocumentName), LogManager::LOG_LEVEL_DEBUG);
     /** @var \Magento\Framework\DB\Select $select */
     $select = $this->getConfigurablePrice();
     while (!empty($bulk = $this->getRecords($sourceDocumentName, $select, $pageNumber))) {
         $pageNumber++;
         $destinationCollection = $destinationDocument->getRecords();
         foreach ($bulk as $recordData) {
             $this->progress->advance(LogManager::LOG_LEVEL_INFO);
             $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
             /** @var Record $destinationRecord */
             $destinationRecord = $this->recordFactory->create(['document' => $destinationDocument, 'data' => $recordData]);
             $destinationCollection->addRecord($destinationRecord);
         }
         $this->destination->saveRecords($destinationDocumentName, $destinationCollection, true);
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
 /**
  * @return void
  */
 public function testPerform()
 {
     $recordsData = ['record_1' => ['field_name' => []], 'record_2' => ['field_name' => []], 'record_3' => ['field_name' => []]];
     $this->progress->expects($this->once())->method('start')->with('3');
     $this->progress->expects($this->any())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $fields = ['field_name' => []];
     $differentFields = ['field_different' => []];
     $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock();
     $structure->expects($this->at(0))->method('getFields')->willReturn($differentFields);
     $structure->expects($this->any())->method('getFields')->willReturn($fields);
     $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getName', 'getRecords', 'getStructure'])->getMock();
     $document->expects($this->any())->method('getStructure')->willReturn($structure);
     $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock();
     $document->expects($this->any())->method('getRecords')->willReturn($recordsCollection);
     $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['getFields', 'setValue'])->getMock();
     $record->expects($this->once())->method('getFields')->willReturn(array_keys($fields));
     $record->expects($this->once())->method('setValue')->willReturnSelf();
     $this->recordFactory->expects($this->any())->method('create')->with(['document' => $document])->will($this->returnValue($record));
     $recordsCollection->expects($this->any())->method('addRecord')->with($record);
     $this->source->expects($this->any())->method('getDocument')->willReturn($document);
     $this->source->expects($this->any())->method('getRecords')->willReturnMap([['core_store', 0, null, $recordsData], ['core_store_group', 0, null, $recordsData], ['core_website', 0, null, $recordsData]]);
     $this->destination->expects($this->any())->method('getDocument')->willReturn($document);
     $this->destination->expects($this->any())->method('clearDocument')->willReturnSelf();
     $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']);
     $this->data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper);
     $this->data->perform();
 }
 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());
 }
Example #9
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start(count($this->groups->getGroup('documents')));
     $this->validateAttributes();
     $this->validateAttributeSetsAndGroups();
     $this->progress->finish();
     return $this->checkForErrors();
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start(count($this->groups->getGroup('documents')));
     $this->validateAttributes();
     $this->validateAttributeSetsAndGroups();
     $this->progress->finish();
     $result = $this->checkForErrors(Logger::ERROR);
     if ($result) {
         $this->helper->deleteBackups();
     }
     return $result;
 }
 /**
  * {@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;
 }
 /**
  * @return void
  */
 public function testPerform()
 {
     $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $this->progress->expects($this->once())->method('start')->with('3');
     $this->progress->expects($this->any())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $this->source->expects($this->any())->method('getDocument', 'getRecords')->willReturn($document);
     $this->destination->expects($this->any())->method('getDocument')->willReturn($document);
     $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']);
     $this->integrity = new Integrity($this->progress, $this->source, $this->destination, $this->helper);
     $this->assertTrue($this->integrity->perform());
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $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 array $fieldsData
  * @param string $sourceType
  * @return void
  */
 protected function checkFields($fieldsData, $sourceType)
 {
     $resourceModel = $this->getResourceModel($sourceType);
     foreach ($fieldsData as $field => $documentName) {
         $this->progress->advance();
         $document = $resourceModel->getDocument($documentName);
         $structure = array_keys($document->getStructure()->getFields());
         if (!in_array($field, $structure)) {
             $this->missingDocumentFields[$sourceType][$documentName][] = $field;
         }
     }
 }
Example #15
0
 /**
  * @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();
 }
Example #16
0
 /**
  * @param array $fieldsData
  * @param string $sourceType
  * @return void
  */
 protected function check($fieldsData, $sourceType)
 {
     $source = $this->getResource($sourceType);
     foreach ($fieldsData as $field => $documentName) {
         $this->progress->advance();
         $document = $source->getDocument($documentName);
         $structure = array_keys($document->getStructure()->getFields());
         if (!in_array($field, $structure)) {
             $message = sprintf('%s table does not contain field: %s', $document, $field);
             $this->logger->error($message);
         }
     }
 }
Example #17
0
 /**
  * @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()
 {
     $this->data = new Data($this->destination, $this->progress);
     $this->progress->expects($this->once())->method('start')->with(1);
     $this->progress->expects($this->once())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter);
     $this->adapter->expects($this->once())->method('getSelect')->willReturn($this->select);
     $this->select->expects($this->once())->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf());
     $this->select->expects($this->once())->method('where')->with('store_id > 0')->will($this->returnSelf());
     $this->adapter->expects($this->once())->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]);
     $this->adapter->expects($this->once())->method('updateDocument')->with('rating', ['is_active' => 1], 'rating_id IN (1)');
     $this->data->perform();
 }
 /**
  * {@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);
 }
Example #20
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();
 }
Example #21
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());
 }
 /**
  * @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;
 }
 /**
  * {@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;
 }
 /**
  * Check if source and destination resources have equal document names and fields
  *
  * @param array $documents
  * @param string $type - allowed values: MapInterface::TYPE_SOURCE, MapInterface::TYPE_DEST
  * @param bool $verifyFields
  * @return $this
  */
 protected function check($documents, $type, $verifyFields = true)
 {
     $documents = $this->filterIgnoredDocuments($documents, $type);
     if (!empty($documents)) {
         $this->hasMappedDocuments = false;
         $source = $type == MapInterface::TYPE_SOURCE ? $this->source : $this->destination;
         $destination = $type == MapInterface::TYPE_SOURCE ? $this->destination : $this->source;
         $destDocuments = array_flip($destination->getDocumentList());
         foreach ($documents as $sourceDocumentName) {
             $this->progress->advance();
             $destinationDocumentName = $this->map->getDocumentMap($sourceDocumentName, $type);
             $sourceDocument = $source->getDocument($sourceDocumentName);
             $destinationDocument = $destination->getDocument($destinationDocumentName);
             if (!isset($destDocuments[$destinationDocumentName]) || !$sourceDocument || !$destinationDocument) {
                 $this->missingDocuments[$type][$sourceDocumentName] = true;
             } else {
                 $this->hasMappedDocuments = true;
                 if ($verifyFields) {
                     $this->verifyFields($sourceDocument, $destinationDocument, $type);
                 }
             }
         }
     }
     return $this;
 }
 /**
  * @return bool
  */
 public function perform()
 {
     $sourceDocuments = array_keys($this->helper->getDocumentList());
     $this->progress->start(count($sourceDocuments));
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progress->advance();
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $this->checkMapEntities($sourceDocName, $destinationName);
         $this->checkEavEntities();
     }
     $this->progress->finish();
     return $this->checkForErrors();
 }
 /**
  * {@inheritdoc}
  */
 public function perform()
 {
     $this->progressBar->start(1, LogManager::LOG_LEVEL_INFO);
     $this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
     $this->destination->clearDocument($this->helper->getSequenceMetaTable());
     $this->destination->clearDocument($this->helper->getSequenceProfileTable());
     foreach ($this->helper->getEntityTypeTablesMap() as $entityType) {
         foreach ($this->helper->getStoreIds() as $storeId) {
             $this->createSequenceTable($entityType, $storeId);
             $metaId = $this->addDataMetaTable($entityType, $storeId);
             $this->addDataProfileTable($storeId, $metaId);
         }
     }
     $this->progressBar->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Example #27
0
 /**
  * @param array $documents
  * @return void
  */
 protected function clearLog($documents)
 {
     foreach ($documents as $documentName) {
         $this->progress->advance();
         $this->destination->clearDocument($documentName);
     }
 }
Example #28
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progressBar->start(count($this->source->getDocumentList()), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = $this->source->getDocumentList();
     // TODO: during steps refactoring MAGETWO-35749 stage will be removed
     $stage = 'run';
     $processedDocuments = $this->progress->getProcessedEntities($this, $stage);
     foreach ($sourceDocuments as $sourceDocName) {
         $this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
         if (in_array($sourceDocName, $processedDocuments)) {
             continue;
         }
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationName) {
             continue;
         }
         $destDocument = $this->destination->getDocument($destinationName);
         $this->destination->clearDocument($destinationName);
         $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progressBar->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($items as $data) {
                 $this->progressBar->advance(LogManager::LOG_LEVEL_DEBUG);
                 if ($recordTransformer) {
                     /** @var Record $record */
                     $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]);
                     /** @var Record $destRecord */
                     $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                     $recordTransformer->transform($record, $destRecord);
                 } else {
                     $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]);
                 }
                 $destinationRecords->addRecord($destRecord);
             }
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->addProcessedEntity($this, $stage, $sourceDocName);
         $this->progressBar->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progressBar->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Example #29
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     foreach ($this->getDocumentList() as $methodToExecute => $document) {
         $destinationDocumentName = $document['destination'];
         $this->destination->clearDocument($destinationDocumentName);
         $this->progress->start(1, LogManager::LOG_LEVEL_DEBUG);
         $sourceGridDocument = array_flip($this->helper->getDocumentList())[$destinationDocumentName];
         $entityIds = $this->getEntityIdsFromSourceGrid($sourceGridDocument);
         if ($entityIds) {
             $this->destination->getAdapter()->insertFromSelect($this->{$methodToExecute}($document['columns'], $entityIds), $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
 /**
  * {@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;
 }