/** * {@inheritdoc} */ public function run() { try { $modeName = $this->getMode(); if ($this->_showHelp()) { if (!empty($modeName) && $modeName != 'help') { $mode = $this->createMode($modeName); echo $mode->getUsageHelp(); } return $this; } if (empty($modeName)) { echo $this->getUsageHelp(); return $this; } if (!$this->optionConfig()) { echo $this->getUsageHelp(); return $this; } $this->processGeneralOptions(); $mode = $this->createMode($modeName); $mode->run(); } catch (Exception $e) { $this->logger->error('Migration tool exception: ' . $e->getMessage()); } catch (\Exception $e) { $this->logger->error('Application failed with exception: ' . $e->getMessage()); $this->logger->error($e->getTraceAsString()); } return $this; }
/** * Process errors * * @return bool */ protected function checkForErrors() { foreach ($this->errors as $error) { $this->logger->error($error); } return empty($this->errors); }
/** * {@inheritdoc} */ public function perform() { $this->progress->start($this->getIterationsCount()); foreach ($this->helper->getDocumentList() as $documentName) { $this->progress->advance(); $documentColumns = $this->helper->getDocumentColumns($documentName); $destinationDocumentStructure = array_keys($this->destination->getStructure($documentName)->getFields()); foreach (array_diff($documentColumns, $destinationDocumentStructure) as $columnDiff) { $message = sprintf('%s table does not contain field: %s', $documentName, $columnDiff); $this->logger->error($message); } } $this->progress->finish(); return $this->checkForErrors(); }
/** * Process missing entities and log them in to the file * * @return bool */ protected function checkForErrors() { $isSuccess = true; if (!$this->hasMappedDocuments) { $this->logger->error('Mapped documents not found. Check your configuration.'); return false; } if (isset($this->missingDocuments[MapInterface::TYPE_SOURCE])) { $isSuccess = false; $this->logger->error(sprintf('Source documents not mapped: %s', implode(',', array_keys($this->missingDocuments[MapInterface::TYPE_SOURCE])))); } if (isset($this->missingDocuments[MapInterface::TYPE_DEST])) { $isSuccess = false; $this->logger->error(sprintf('Destination documents not mapped: %s', implode(',', array_keys($this->missingDocuments[MapInterface::TYPE_DEST])))); } if (isset($this->missingDocumentFields[MapInterface::TYPE_SOURCE])) { $isSuccess = false; foreach ($this->missingDocumentFields[MapInterface::TYPE_SOURCE] as $document => $fields) { $this->logger->error(sprintf('Source fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields))); } } if (isset($this->missingDocumentFields[MapInterface::TYPE_DEST])) { $isSuccess = false; foreach ($this->missingDocumentFields[MapInterface::TYPE_DEST] as $document => $fields) { $this->logger->error(sprintf('Destination fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields))); } } return $isSuccess; }
/** * @return bool */ protected function volume() { $result = true; $this->progress->start(1); $this->progress->advance(); $ratingsShouldBeActive = []; $ratingsIsActive = []; /** @var \Migration\Resource\Adapter\Mysql $adapter */ $adapter = $this->destination->getAdapter(); /** @var \Magento\Framework\DB\Select $select */ $select = $adapter->getSelect()->from($this->getRatingStoreDocument(), ['rating_id'])->where('store_id > 0'); $ratingsStore = $adapter->loadDataFromSelect($select); foreach ($ratingsStore as $rating) { $ratingsShouldBeActive[] = $rating['rating_id']; } $ratingsShouldBeActive = array_unique($ratingsShouldBeActive); /** @var \Magento\Framework\DB\Select $select */ $select = $adapter->getSelect()->from($this->getRatingDocument(), ['rating_id'])->where('is_active = ?', 1); $ratings = $adapter->loadDataFromSelect($select); foreach ($ratings as $rating) { $ratingsIsActive[] = $rating['rating_id']; } if (count(array_intersect($ratingsShouldBeActive, $ratingsIsActive)) != count($ratingsShouldBeActive)) { $this->logger->error(sprintf('Mismatch of entities in the documents: %s, %s', self::RATING_TABLE_NAME, self::RATING_STORE_TABLE_NAME)); $result = false; } $this->progress->finish(); return $result; }
/** * @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; }
/** * {@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; }
/** * {@inheritdoc} */ public function perform() { $this->progress->start(1); $this->progress->advance(); $documents = $this->destination->getDocumentList(); if (!in_array(self::RATING_TABLE_NAME, $documents) || !in_array(self::RATING_STORE_TABLE_NAME, $documents)) { $this->logger->error(sprintf('"%s" or "%s" documents do not exist in the destination resource', self::RATING_TABLE_NAME, self::RATING_STORE_TABLE_NAME)); return false; } $structureRating = $this->destination->getDocument(self::RATING_TABLE_NAME)->getStructure()->getFields(); if (!array_key_exists('is_active', $structureRating)) { $this->logger->error(sprintf('"is_active" field does not exist in "%s" document of' . ' the destination resource', self::RATING_TABLE_NAME)); return false; } $this->progress->finish(); return true; }
/** * {@inheritdoc} */ protected function volume() { $this->progress->start(1); $this->getRewritesSelect(); $this->progress->advance(); $result = $this->source->getRecordsCount($this->tableName) == $this->destination->getRecordsCount('url_rewrite'); if (!$result) { $this->logger->error('Mismatch of entities in the document: url_rewrite'); } $this->progress->finish(); return $result; }
/** * Volume check * * @return bool */ protected function volume() { $result = true; $this->progress->start(1); $result &= $this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites(true) == $this->destination->getRecordsCount(self::DESTINATION); if (!$result) { $this->logger->error('Mismatch of entities in the document: url_rewrite'); } $this->progress->advance(); $this->progress->finish(); return (bool) $result; }
/** * @param array $fieldsData * @param string $sourceType * @return void */ protected function check($fieldsData, $sourceType) { $source = $this->getResource($sourceType); foreach ($fieldsData as $field => $documentName) { $this->progress->advance(); $document = $source->getDocument($documentName); $structure = array_keys($document->getStructure()->getFields()); if (!in_array($field, $structure)) { $message = sprintf('%s table does not contain field: %s', $document, $field); $this->logger->error($message); } } }
/** * Volume check * * @return bool */ protected function volume() { $result = true; $this->progress->start(count($this->getDocumentList())); foreach ($this->getDocumentList() as $sourceName => $destinationName) { $this->progress->advance(); if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) { $this->logger->error('Mismatch of entities in the document: ' . $destinationName); $result = false; } } $this->progress->finish(); return $result; }
/** * Performance optimized way. In case when source has direct access to destination database * * @param string $methodToExecute * @param array $columns * @param string $destinationDocumentName * @param string $sourceGridDocument * @return bool|void */ protected function isCopiedDirectly($methodToExecute, array $columns, $destinationDocumentName, $sourceGridDocument) { if (!$this->copyDirectly) { return; } $result = true; try { $entityIdsSelect = $this->getEntityIdsSelect($sourceGridDocument); $this->destination->getAdapter()->insertFromSelect($this->{$methodToExecute}($columns, new \Zend_Db_Expr($entityIdsSelect)), $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE); } catch (\Exception $e) { $this->copyDirectly = false; $this->logger->error('Document ' . $sourceGridDocument . ' can not be copied directly because of error: ' . $e->getMessage()); $result = false; } return $result; }
/** * @return bool */ public function checkMissingDocumentFields() { $isSuccess = true; if (isset($this->missingDocumentFields[MapInterface::TYPE_SOURCE])) { $isSuccess = false; foreach ($this->missingDocumentFields[MapInterface::TYPE_SOURCE] as $document => $fields) { $this->logger->error(sprintf('Source fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields))); } } if (isset($this->missingDocumentFields[MapInterface::TYPE_DEST])) { $isSuccess = false; foreach ($this->missingDocumentFields[MapInterface::TYPE_DEST] as $document => $fields) { $this->logger->error(sprintf('Destination fields not mapped. Document: %s. Fields: %s', $document, implode(',', $fields))); } } return $isSuccess; }
/** * @return bool */ public function checkDocumentFields() { $check = function ($errors, $errorMessagePattern, $type) { $isSuccess = true; if (isset($errors[$type])) { $isSuccess = false; foreach ($errors[$type] as $document => $fields) { $this->logger->error(sprintf($errorMessagePattern, $document, implode(',', $fields))); } } return $isSuccess; }; $missingDocumentsSource = $check($this->missingDocumentFields, 'Source fields are missing. Document: %s. Fields: %s', MapInterface::TYPE_SOURCE); $missingDocumentsDestination = $check($this->missingDocumentFields, 'Destination fields are missing. Document: %s. Fields: %s', MapInterface::TYPE_DEST); $notMappedDocumentsSource = $check($this->notMappedDocumentFields, 'Source fields are not mapped. Document: %s. Fields: %s', MapInterface::TYPE_SOURCE); $notMappedDocumentsDestination = $check($this->notMappedDocumentFields, 'Destination fields are not mapped. Document: %s. Fields: %s', MapInterface::TYPE_DEST); return $missingDocumentsSource && $missingDocumentsDestination && $notMappedDocumentsSource && $notMappedDocumentsDestination; }
/** * @param Document $sourceDocument * @param Document $destinationDocument * @return bool */ protected function isCopiedDirectly(Document $sourceDocument, Document $destinationDocument) { if (!$this->copyDirectly) { return; } $result = true; $schema = $this->config->getSource()['database']['name']; /** @var \Magento\Framework\DB\Select $select */ $select = $this->source->getAdapter()->getSelect(); $select->from($this->source->addDocumentPrefix($sourceDocument->getName()), '*', $schema); try { $this->destination->getAdapter()->insertFromSelect($select, $this->destination->addDocumentPrefix($destinationDocument->getName()), array_keys($sourceDocument->getStructure()->getFields())); } catch (\Exception $e) { $this->copyDirectly = false; $this->logger->error('Document ' . $sourceDocument->getName() . ' can not be copied directly because of error: ' . $e->getMessage()); $result = false; } return $result; }