Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
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();
 }
 /**
  * @return void
  */
 public function testGetRecordTransformer()
 {
     $sourceDocument = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $destinationDocument = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock();
     $recordTransformer = $this->getMockBuilder('Migration\\RecordTransformer')->disableOriginalConstructor()->setMethods(['init'])->getMock();
     $this->factory->expects($this->once())->method('create')->with(['sourceDocument' => $sourceDocument, 'destDocument' => $destinationDocument, 'mapReader' => $this->map])->will($this->returnValue($recordTransformer));
     $recordTransformer->expects($this->once())->method('init')->will($this->returnSelf());
     $this->assertSame($recordTransformer, $this->helper->getRecordTransformer($sourceDocument, $destinationDocument));
 }
Ejemplo n.º 4
0
 /**
  * @param Document $sourceDocument
  * @param Document $destDocument
  * @return \Migration\RecordTransformer
  */
 public function getRecordTransformer(Document $sourceDocument, Document $destDocument)
 {
     if ($this->canJustCopy($sourceDocument, $destDocument)) {
         return null;
     }
     /** @var \Migration\RecordTransformer $recordTransformer */
     $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
     $recordTransformer->init();
     return $recordTransformer;
 }
Ejemplo n.º 5
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents'));
     foreach ($sourceDocuments as $sourceDocName) {
         $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);
         /** @var \Migration\RecordTransformer $recordTransformer */
         $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
         $recordTransformer->init();
         $attributeType = $this->helper->getAttributeType($sourceDocName);
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationRecords = $destDocument->getRecords();
             foreach ($bulk as $recordData) {
                 $this->source->setLastLoadedRecord($sourceDocName, $recordData);
                 if ($this->helper->isSkipRecord($attributeType, $sourceDocName, $recordData)) {
                     continue;
                 }
                 /** @var Record $record */
                 $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                 $recordTransformer->transform($record, $destRecord);
                 $destinationRecords->addRecord($destRecord);
             }
             $this->progress->advance(LogManager::LOG_LEVEL_INFO);
             $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
             $this->helper->updateAttributeData($attributeType, $sourceDocName, $destinationRecords);
             $this->destination->saveRecords($destinationName, $destinationRecords);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->helper->updateEavAttributes();
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Entry point. Run migration of SalesOrder structure.
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = array_keys($this->helper->getDocumentList());
     foreach ($sourceDocuments as $sourceDocName) {
         $sourceDocument = $this->source->getDocument($sourceDocName);
         $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE);
         if (!$destinationDocumentName) {
             continue;
         }
         $destDocument = $this->destination->getDocument($destinationDocumentName);
         $this->destination->clearDocument($destinationDocumentName);
         $eavDocumentName = $this->helper->getDestEavDocument();
         $eavDocumentResource = $this->destination->getDocument($eavDocumentName);
         /** @var \Migration\RecordTransformer $recordTransformer */
         $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]);
         $recordTransformer->init();
         $pageNumber = 0;
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG);
         while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) {
             $pageNumber++;
             $destinationCollection = $destDocument->getRecords();
             $destEavCollection = $eavDocumentResource->getRecords();
             foreach ($bulk as $recordData) {
                 $this->progress->advance(LogManager::LOG_LEVEL_INFO);
                 $this->progress->advance(LogManager::LOG_LEVEL_DEBUG);
                 /** @var Record $sourceRecord */
                 $sourceRecord = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]);
                 /** @var Record $destRecord */
                 $destRecord = $this->recordFactory->create(['document' => $destDocument]);
                 $recordTransformer->transform($sourceRecord, $destRecord);
                 $destinationCollection->addRecord($destRecord);
                 $this->migrateAdditionalOrderData($recordData, $sourceDocument, $destEavCollection);
             }
             $this->destination->saveRecords($destinationDocumentName, $destinationCollection);
             $this->destination->saveRecords($eavDocumentName, $destEavCollection);
             $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
         }
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Ejemplo n.º 7
0
 /**
  * @covers \Migration\Step\SalesOrder\Data::prepareEavEntityData
  * @covers \Migration\Step\SalesOrder\Data::getAttributeData
  * @covers \Migration\Step\SalesOrder\Data::getAttributeValue
  * @covers \Migration\Step\SalesOrder\Data::getDestEavDocument
  * @return void
  */
 public function testGetMap()
 {
     $sourceDocumentName = 'source_document';
     $destinationDocumentName = 'destination_document';
     $eavAttributes = ['eav_attr_1', 'eav_attr_2'];
     $eavAttributeData = ['entity_type_id' => 1, 'attribute_id' => 2, 'attribute_code' => 'eav_attr_1'];
     $this->helper->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocumentName => $destinationDocumentName]);
     $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn('eav_document');
     $this->helper->expects($this->at(3))->method('getEavAttributes')->willReturn($eavAttributes);
     $this->map->expects($this->once())->method('getDocumentMap')->willReturn($destinationDocumentName);
     $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords'], [], '', false);
     $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument);
     $this->source->expects($this->any())->method('getRecordsCount')->willReturn(2);
     $destinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false);
     $eavDestinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false);
     $dstDocName = 'destination_document';
     $eavDstDocName = 'eav_document';
     $this->destination->expects($this->any())->method('getDocument')->willReturnMap([[$dstDocName, $destinationDocument], [$eavDstDocName, $eavDestinationDocument]]);
     $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['init', 'transform'], [], '', false);
     $this->recordTransformerFactory->expects($this->once())->method('create')->willReturn($recordTransformer);
     $recordTransformer->expects($this->once())->method('init');
     $bulk = [['eav_attr_1' => 'attribute_value', 'store_id' => '1', 'entity_id' => '2']];
     $this->source->expects($this->at(3))->method('getRecords')->willReturn($bulk);
     $this->source->expects($this->at(4))->method('getRecords')->willReturn([]);
     $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false);
     $eavDestinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false);
     $destinationDocument->expects($this->once())->method('getRecords')->willReturn($destinationRecords);
     $srcRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false);
     $dstRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false);
     $this->recordFactory->expects($this->at(0))->method('create')->willReturn($srcRecord);
     $this->recordFactory->expects($this->at(1))->method('create')->willReturn($dstRecord);
     $recordTransformer->expects($this->once())->method('transform')->with($srcRecord, $dstRecord);
     $eavDestinationDocument->expects($this->once())->method('getRecords')->willReturn($eavDestinationRecords);
     $eavDestinationRecords->expects($this->once())->method('addRecord');
     $this->destination->expects($this->at(5))->method('saveRecords')->with($dstDocName, $destinationRecords);
     $this->destination->expects($this->at(6))->method('saveRecords')->with($eavDstDocName, $eavDestinationRecords);
     $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName);
     $this->destination->expects($this->at(3))->method('getRecords')->willReturn([0 => $eavAttributeData]);
     $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => $sourceDocumentName])->willReturn(true);
     $this->salesOrder->perform();
 }
Ejemplo n.º 8
0
 /**
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destinationDocument
  * @return \Migration\RecordTransformer
  */
 protected function getRecordTransformer($sourceDocument, $destinationDocument)
 {
     $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destinationDocument, 'mapReader' => $this->mapReader]);
     $recordTransformer->init();
     return $recordTransformer;
 }
Ejemplo n.º 9
0
 /**
  * @param Document $sourceDocument
  * @param Document $destinationDocument
  * @return RecordTransformer
  */
 public function getRecordTransformer($sourceDocument, $destinationDocument)
 {
     return $this->factory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destinationDocument, 'mapReader' => $this->map])->init();
 }