/** * {@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; }
/** * @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() { $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); }
/** * {@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()); }
/** * @return void */ public function testPerform() { $fields = ['field_name' => []]; $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getStructure'])->getMock(); $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $document->expects($this->any())->method('getStructure')->willReturn($structure); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->source->expects($this->any())->method('getRecordsCount')->with()->willReturn(1); $this->destination->expects($this->any())->method('getRecordsCount')->with()->willReturn(1); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->volume = new Volume($this->progress, $this->source, $this->destination, $this->helper, $this->logger); $this->assertTrue($this->volume->perform()); }