Пример #1
0
 /**
  * @return void
  */
 protected function optionReset()
 {
     if ($this->getArg('reset') === true) {
         $this->logger->info('Reset the current position of migration to start from the beginning');
         $this->progress->reset();
     }
 }
Пример #2
0
 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\\Resource\\Document', ['getRecords', 'getStructure'], [], '', false);
     $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([]));
     $this->source->expects($this->once())->method('getDocument')->willReturn($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);
     $destinationRecords = $this->getMock('\\Migration\\Resource\\Record\\Collection', [], [], '', false);
     $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords));
     $dstRecord = $this->getMock('\\Migration\\Resource\\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();
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $config = $input->getArgument(self::INPUT_KEY_CONFIG);
     $this->config->init($config);
     //@todo: interactively ask for config file
     $reset = $input->getOption(self::INPUT_KEY_RESET);
     if ($reset) {
         $output->writeln('Reset the current position of migration to start from the beginning');
         $this->progress->reset();
     }
     if ($output->getVerbosity() > 1) {
         $this->logManager->process($this->verbosityLevels[$output->getVerbosity()]);
     } else {
         $this->logManager->process();
     }
 }
 /**
  * @return void
  */
 public function testSaveDataNoFile()
 {
     $this->file->expects($this->any())->method('isExists')->will($this->returnValue(false));
     $this->file->expects($this->once())->method('saveData');
     $step = $this->getMock('\\Migration\\Step\\Map', [], [], '', false);
     $this->progress->saveResult($step, 'integrity', 'true');
 }
Пример #5
0
 /**
  * @param StageInterface $object
  * @param string $step
  * @param string $stage
  * @return bool
  */
 protected function runStage($object, $step, $stage)
 {
     $this->logger->info('started', ['step' => $step, 'stage' => $stage, 'mode' => $this->mode]);
     if ($this->progress->isCompleted($object, $stage)) {
         return true;
     }
     try {
         $result = $object->perform();
     } catch (\Migration\Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
     if ($result && $this->canBeCompleted) {
         $this->progress->saveResult($object, $stage, $result);
     }
     return $result;
 }
Пример #6
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progressBar->start(count($this->source->getDocumentList()), LogManager::LOG_LEVEL_INFO);
     $sourceDocuments = $this->source->getDocumentList();
     $stage = 'run';
     $processedDocuments = $this->progress->getProcessedEntities($this, $stage);
     foreach (array_diff($sourceDocuments, $processedDocuments) as $sourceDocName) {
         $this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
         $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);
         $this->logger->debug('migrating', ['table' => $sourceDocName]);
         $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
         $doCopy = $recordTransformer === null && $this->copyDirectly;
         if ($doCopy && $this->isCopiedDirectly($sourceDocument, $destDocument)) {
             $this->progressBar->start(1, LogManager::LOG_LEVEL_DEBUG);
         } else {
             $pageNumber = 0;
             $this->progressBar->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG);
             while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) {
                 $pageNumber++;
                 $destinationRecords = $destDocument->getRecords();
                 foreach ($items as $data) {
                     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->source->setLastLoadedRecord($sourceDocName, end($items));
                 $this->progressBar->advance(LogManager::LOG_LEVEL_DEBUG);
                 $fieldsUpdateOnDuplicate = $this->helper->getFieldsUpdateOnDuplicate($destinationName);
                 $this->destination->saveRecords($destinationName, $destinationRecords, $fieldsUpdateOnDuplicate);
             }
         }
         $this->source->setLastLoadedRecord($sourceDocName, []);
         $this->progress->addProcessedEntity($this, $stage, $sourceDocName);
         $this->progressBar->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progressBar->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Пример #7
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;
 }
 public function testRunStepsWithSuccessProgress()
 {
     $stepIntegrity = $this->getMockBuilder('\\Migration\\App\\Step\\StageInterface')->getMock();
     $stepIntegrity->expects($this->never())->method('perform');
     $stepData = $this->getMockBuilder('\\Migration\\App\\Step\\StageInterface')->getMock();
     $stepData->expects($this->never())->method('perform');
     $stepVolume = $this->getMockBuilder('\\Migration\\App\\Step\\StageInterface')->getMock();
     $stepVolume->expects($this->never())->method('perform');
     $this->progress->expects($this->never())->method('saveResult');
     $this->progress->expects($this->any())->method('isCompleted')->willReturn(true);
     $this->logger->expects($this->at(0))->method('info')->with("started");
     $this->logger->expects($this->at(1))->method('info')->with("started");
     $this->logger->expects($this->at(2))->method('info')->with("started");
     $this->logger->expects($this->at(3))->method('info')->with("Migration completed");
     $this->stepList->expects($this->any())->method('getSteps')->willReturn(['Title' => ['integrity' => $stepIntegrity, 'data' => $stepData, 'volume' => $stepVolume]]);
     $this->assertTrue($this->settings->run());
 }