/** * @param string $documentName * @param string $idKey * @return void */ protected function processChangedRecords($documentName, $idKey) { $items = $this->source->getChangedRecords($documentName, $idKey); if (empty($items)) { return; } if (!$this->eolOnce) { $this->eolOnce = true; echo PHP_EOL; } $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); $sourceDocument = $this->source->getDocument($documentName); $destDocument = $this->destination->getDocument($destinationName); $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument); do { $destinationRecords = $destDocument->getRecords(); $ids = []; foreach ($items as $data) { echo '.'; $ids[] = $data[$idKey]; $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords); } $this->destination->updateChangedRecords($destinationName, $destinationRecords); $documentNameDelta = $this->source->getDeltaLogName($documentName); $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta); $this->markRecordsProcessed($documentNameDelta, $idKey, $ids); } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey))); }
/** * {@inheritdoc} */ public function run() { do { /** @var StepList $steps */ $steps = $this->stepListFactory->create(['mode' => 'delta']); /** * @var string $stepName * @var StageInterface[] $step */ foreach ($steps->getSteps() as $stepName => $step) { if (empty($step['delta'])) { continue; } $this->runDelta($step, $stepName); if (!empty($step['volume'])) { $this->runVolume($step, $stepName); } } $deltaLogs = $this->groupsReader->getGroups(); foreach ($deltaLogs as $deltaDocuments) { foreach (array_keys($deltaDocuments) as $documentName) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $adapter->deleteProcessedRecords($this->source->addDocumentPrefix($this->source->getDeltaLogName($documentName))); } } $this->logger->info('Migration completed successfully'); if ($this->autoRestart) { $this->logger->info("Automatic restart in {$this->autoRestart} sec. Use CTRL-C to abort"); sleep($this->autoRestart); } } while ($this->autoRestart); 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; }
/** * @param string $dataTable * @param \Migration\Resource\Source $resource */ protected function checkDeltaLogTable($dataTable, $resource) { $deltaLogTableName = $resource->getDeltaLogName($dataTable); $deltaLogTable = $resource->getDocument($deltaLogTableName); $this->assertEquals($deltaLogTableName, $deltaLogTable->getName()); }