Beispiel #1
0
 /**
  * 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 Resource\Source $source
  * @param Resource\Destination $destination
  * @param Resource\RecordFactory $recordFactory
  * @param Logger $logger
  * @param Helper $helper
  */
 public function __construct(ProgressBar\LogLevelProcessor $progress, Resource\Source $source, Resource\Destination $destination, Resource\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;
 }
Beispiel #3
0
 /**
  * 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 Resource\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $adapter->updateDocument($documentName, ['processed' => 1], "`{$idKey}` in ('{$ids}')");
 }
Beispiel #4
0
 /**
  * {@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;
 }
Beispiel #5
0
 /**
  * @param string $sourceGridDocumentName
  * @return array
  */
 protected function getEntityIdsFromSourceGrid($sourceGridDocumentName)
 {
     /** @var \Migration\Resource\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     /** @var \Magento\Framework\DB\Select $select */
     $select = $adapter->getSelect();
     $select->from($this->source->addDocumentPrefix($sourceGridDocumentName), 'entity_id');
     $ids = $select->getAdapter()->fetchCol($select);
     return $ids;
 }
 /**
  * Initialize temporary table and insert UrlRewrite data
  *
  * @codeCoverageIgnore
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @return void
  */
 protected function initTemporaryTable()
 {
     /** @var \Migration\Resource\Adapter\Mysql $adapter */
     $adapter = $this->source->getAdapter();
     $this->createTemporaryTable($adapter);
     $this->collectProductRewrites($adapter);
     $this->collectCategoryRewrites($adapter);
     $this->collectRedirects($adapter);
     $this->dataInitialized = true;
 }
Beispiel #7
0
 /**
  * @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;
 }
 /**
  * @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;
     }
 }
Beispiel #9
0
 /**
  * @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;
 }