/** * @param Record $recordToHandle * @param Record $oppositeRecord * @return mixed */ public function handle(Record $recordToHandle, Record $oppositeRecord) { $this->validate($recordToHandle); $sourcePatterns = []; $destinationPatters = []; foreach ($this->source->getDocumentList() as $document) { $destDocumentName = $this->getDestDocumentName($document); if ($destDocumentName === false) { continue; } $sourcePatterns[] = sprintf('`%s`', $this->source->addDocumentPrefix($document)); $destinationPatters[] = sprintf('`%s`', $this->destination->addDocumentPrefix($destDocumentName)); } $newValue = str_replace($sourcePatterns, $destinationPatters, $recordToHandle->getValue($this->field)); $recordToHandle->setValue($this->field, $newValue); }
/** * {@inheritdoc} */ public function perform() { $this->progress->start(1); $this->progress->advance(); $documents = $this->source->getDocumentList(); if (!in_array(self::CONFIG_TABLE_NAME_SOURCE, $documents)) { $this->logger->error(sprintf('Integrity check failed due to "%s" document does not exist in the source resource', self::CONFIG_TABLE_NAME_SOURCE)); return false; } $documents = $this->destination->getDocumentList(); if (!in_array(self::CONFIG_TABLE_NAME_DESTINATION, $documents)) { $this->logger->error(sprintf('Integrity check failed due to "%s" document does not exist in the destination resource', self::CONFIG_TABLE_NAME_DESTINATION)); return false; } $this->progress->finish(); return true; }
/** * @return bool */ public function perform() { $sourceDocuments = $this->source->getDocumentList(); $this->progressBar->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceDocName) { $this->progressBar->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $sourceCount = $this->source->getRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progressBar->finish(); return $this->checkForErrors(); }
/** * @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 * @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; }