/** * @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; }
/** * @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; }
/** * {@inheritdoc} */ public function perform() { $updateData = $this->helper->getUpdateData(); $selectData = $this->helper->getSelectData(); $sourceDocuments = $this->readerGroups->getGroup('source_documents'); foreach ($sourceDocuments as $sourceDocName => $idKey) { if ($this->source->getRecordsCount($this->source->getDeltaLogName($sourceDocName)) == 0) { continue; } $items = $this->source->getChangedRecords($sourceDocName, $idKey, 0, true); if (empty($items)) { continue; } $this->logger->debug(sprintf('%s has changes', $sourceDocName)); if (!$this->eolOnce) { $this->eolOnce = true; echo PHP_EOL; } $gridIdKey = $updateData[$sourceDocName]['idKey']; $page = 1; do { $ids = []; foreach ($items as $data) { echo '.'; $ids[] = $data[$gridIdKey]; } foreach ($updateData[$sourceDocName]['methods'] as $method) { echo '.'; $destinationDocumentName = $selectData[$method]['destination']; $select = call_user_func_array([$this->data, $method], [$selectData[$method]['columns'], $ids]); $this->destination->getAdapter()->insertFromSelect($select, $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE); } $documentNameDelta = $this->source->getDeltaLogName($sourceDocName); $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta); $this->markRecordsProcessed($documentNameDelta, $idKey, $ids); } while (!empty($items = $this->source->getChangedRecords($sourceDocName, $idKey, $page++))); } return true; }
/** * @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; }
/** * @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; }
/** * 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; }
/** * Run step * * @return bool */ public function perform() { /** @var \Migration\ResourceModel\Adapter\Mysql $sourceAdapter */ $sourceAdapter = $this->source->getAdapter(); /** @var \Migration\ResourceModel\Adapter\Mysql $destinationAdapter */ $destinationAdapter = $this->destination->getAdapter(); $sourceDocuments = array_keys($this->groups->getGroup('source_documents')); $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); foreach ($sourceDocuments as $sourceDocumentName) { $destinationDocumentName = $this->map->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE); $sourceTable = $sourceAdapter->getTableDdlCopy($this->source->addDocumentPrefix($sourceDocumentName), $this->destination->addDocumentPrefix($destinationDocumentName)); $destinationTable = $destinationAdapter->getTableDdlCopy($this->destination->addDocumentPrefix($destinationDocumentName), $this->destination->addDocumentPrefix($destinationDocumentName)); foreach ($sourceTable->getColumns() as $columnData) { $destinationTable->setColumn($columnData); } $destinationAdapter->createTableByDdl($destinationTable); $destinationDocument = $this->destination->getDocument($destinationDocumentName); $this->logger->debug('migrating', ['table' => $sourceDocumentName]); $pageNumber = 0; $this->progress->start($this->source->getRecordsCount($sourceDocumentName), LogManager::LOG_LEVEL_DEBUG); while (!empty($sourceRecords = $this->source->getRecords($sourceDocumentName, $pageNumber))) { $pageNumber++; $recordsToSave = $destinationDocument->getRecords(); foreach ($sourceRecords 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]); $destinationRecord->setData($recordData); $recordsToSave->addRecord($destinationRecord); } $this->destination->saveRecords($destinationDocument->getName(), $recordsToSave); } $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * @return bool * @throws \Migration\Exception */ public function perform() { $sourceDocuments = array_flip($this->source->getDocumentList()); foreach ($this->deltaDocuments as $documentName => $idKey) { if (!$this->source->getDocument($documentName)) { continue; } $deltaLogName = $this->source->getDeltaLogName($documentName); if (!isset($sourceDocuments[$deltaLogName])) { throw new \Migration\Exception(sprintf('Deltalog for %s is not installed', $documentName)); } $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } if ($this->source->getRecordsCount($deltaLogName) == 0) { continue; } $this->logger->debug(sprintf('%s has changes', $documentName)); $this->processDeletedRecords($documentName, $idKey, $destinationName); $this->processChangedRecords($documentName, $idKey); } return true; }
/** * @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); $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocName]); $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG); $sourceDocumentName = $sourceDocument->getName(); /** @var \Magento\Framework\DB\Select $select */ $select = $this->getLogDataSelect(); while (!empty($bulk = $this->getRecords($sourceDocumentName, $select, $pageNumber))) { $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($bulk as $recordData) { $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->clearLog(array_keys($this->readerGroups->getGroup('destination_documents_to_clear'))); $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }