/** * @param int $valueId * @return int */ protected function getEntityId($valueId) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from(['mg' => $this->source->addDocumentPrefix($this->mediaGalleryDocument)], [$this->field])->where("mg.{$this->valueIdField} = ?", $valueId); return (int) $query->getAdapter()->fetchOne($query); }
/** * {@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; }
/** * @return array */ public function getStoreIds() { /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from($this->source->addDocumentPrefix($this->storeTable), ['store_id']); return $query->getAdapter()->fetchCol($query); }
/** * @param ProgressBar\LogLevelProcessor $progress * @param ResourceModel\Source $source * @param ResourceModel\Destination $destination * @param ResourceModel\RecordFactory $recordFactory * @param Logger $logger * @param Helper $helper */ public function __construct(ProgressBar\LogLevelProcessor $progress, ResourceModel\Source $source, ResourceModel\Destination $destination, ResourceModel\RecordFactory $recordFactory, Logger $logger, \Migration\Step\ConfigurablePrices\Helper $helper) { $this->source = $source; $this->sourceAdapter = $this->source->getAdapter(); $this->destination = $destination; $this->progress = $progress; $this->recordFactory = $recordFactory; $this->logger = $logger; $this->helper = $helper; }
/** * Get attribute set IDs for entity type 'catalog_product' * @return array */ protected function getProductAttributeSets() { if (empty($this->productAttributeSets)) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from(['as' => $this->source->addDocumentPrefix('eav_attribute_set')], ['attribute_set_id'])->join(['et' => $this->source->addDocumentPrefix('eav_entity_type')], 'et.entity_type_id = as.entity_type_id', [])->where('et.entity_type_code = ?', 'catalog_product'); $this->productAttributeSets = array_flip($query->getAdapter()->fetchCol($query)); } return $this->productAttributeSets; }
/** * @param ProgressBar\LogLevelProcessor $progress * @param ResourceModel\Source $source * @param ResourceModel\Destination $destination * @param ResourceModel\RecordFactory $recordFactory * @param \Migration\RecordTransformerFactory $recordTransformerFactory * @param MapFactory $mapFactory * @param GroupsFactory $groupsFactory * @param Logger $logger */ public function __construct(ProgressBar\LogLevelProcessor $progress, ResourceModel\Source $source, ResourceModel\Destination $destination, ResourceModel\RecordFactory $recordFactory, \Migration\RecordTransformerFactory $recordTransformerFactory, MapFactory $mapFactory, GroupsFactory $groupsFactory, Logger $logger) { $this->source = $source; $this->destination = $destination; $this->recordFactory = $recordFactory; $this->recordTransformerFactory = $recordTransformerFactory; $this->map = $mapFactory->create('log_map_file'); $this->progress = $progress; $this->readerGroups = $groupsFactory->create('log_document_groups_file'); $this->logger = $logger; $this->sourceAdapter = $this->source->getAdapter(); }
/** * @param string $eavAttribute * @return \Magento\Framework\DB\Select */ protected function getEavAttributeSelect($eavAttribute) { /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $select = $adapter->getSelect(); $tables = []; foreach (array_keys($this->getDocumentList()) as $sourceDocument) { $tables[] = $this->source->addDocumentPrefix($sourceDocument); } $select->from($tables)->where($eavAttribute . ' is not null'); return $select; }
/** * Mark processed records for deletion * * @param string $documentName * @param string $idKey * @param [] $ids * @return void */ protected function markRecordsProcessed($documentName, $idKey, $ids) { $ids = implode("','", $ids); /** @var ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $adapter->updateDocument($documentName, ['processed' => 1], "`{$idKey}` in ('{$ids}')"); }
/** * @param int $storeId * @return string */ protected function getIncrementPrefix($storeId) { /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $select = $adapter->getSelect()->from(['cs' => $this->source->addDocumentPrefix($this->storeTable)], ['store_id' => 'csg.default_store_id'])->join(['csg' => $this->source->addDocumentPrefix($this->storeGroupTable)], 'csg.group_id = cs.group_id', [])->where('cs.store_id = ?', $storeId); return $select->getAdapter()->fetchOne($select); }
/** * @param bool $countVolume * @return int */ protected function countCmsPageRewrites($countVolume = false) { if (!$countVolume) { return 1; } /** @var \Magento\Framework\Db\Select $select */ $select = $this->source->getAdapter()->getSelect(); $select->from(['cp' => $this->source->addDocumentPrefix($this->cmsPageTableName)], [new \Zend_Db_Expr('COUNT(*)')])->joinLeft(['cps' => $this->source->addDocumentPrefix($this->cmsPageStoreTableName)], 'cps.page_id = cp.page_id', []); return $select->getAdapter()->fetchOne($select); }
/** * @param string $sourceGridDocumentName * @return \Magento\Framework\DB\Select */ protected function getEntityIdsSelect($sourceGridDocumentName) { /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); /** @var \Magento\Framework\DB\Select $select */ $select = $adapter->getSelect(); $schema = $this->config->getSource()['database']['name']; $select->from($this->source->addDocumentPrefix($sourceGridDocumentName), 'entity_id', $schema); return $select; }
/** * @return array */ protected function getAttributeIds() { if (empty($this->attributeIds)) { /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from($this->source->addDocumentPrefix('eav_attribute'), ['attribute_id'])->where('attribute_code = ?', $this->attributeCode); $this->attributeIds = array_flip($query->getAdapter()->fetchCol($query)); } return $this->attributeIds; }
/** * Initialize temporary table and insert UrlRewrite data * * @codeCoverageIgnore * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return void */ protected function initTemporaryTable() { /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */ $adapter = $this->source->getAdapter(); $this->createTemporaryTable($adapter); $this->collectRedirects($adapter); $this->collectProductRewrites($adapter); $this->collectCategoryRewrites($adapter); $this->collectCmsPageRewrites($adapter); self::$dataInitialized = true; }
/** * @param string $attributeType * @return void */ protected function initEavAttributes($attributeType) { if (isset($this->eavAttributes[$attributeType])) { return; } /** @var Mysql $adapter */ $adapter = $this->source->getAdapter(); $query = $adapter->getSelect()->from(['et' => $this->source->addDocumentPrefix('eav_entity_type')], [])->join(['ea' => $this->source->addDocumentPrefix('eav_attribute')], 'et.entity_type_id = ea.entity_type_id', ['attribute_id', 'backend_type', 'attribute_code', 'entity_type_id'])->where('et.entity_type_code = ?', $attributeType); $attributes = $query->getAdapter()->fetchAll($query); foreach ($attributes as $attribute) { $this->eavAttributes[$attributeType][$attribute['attribute_code']] = $attribute; $this->eavAttributes[$attributeType][$attribute['attribute_id']] = $attribute; } }
/** * @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; }
/** * 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; }