Beispiel #1
0
 public function testGetProcessedEntities()
 {
     $step = $this->getMock('\\Migration\\Step\\Map\\Migrate', [], [], '', false);
     $stage = 'run';
     $document = ['some_document'];
     $progress = [get_class($step) => [$stage => ['process' => $document]]];
     $this->file->expects($this->once())->method('getData')->will($this->returnValue($progress));
     $result = $this->progress->getProcessedEntities($step, $stage);
     $this->assertEquals($document, $result);
 }
 /**
  * @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;
 }
 /**
  * @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;
 }