コード例 #1
0
ファイル: SetGroupCode.php プロジェクト: okite11/frames21
 /**
  * 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;
 }
コード例 #2
0
ファイル: AbstractDelta.php プロジェクト: okite11/frames21
 /**
  * @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)));
 }
コード例 #3
0
ファイル: Delta.php プロジェクト: okite11/frames21
 /**
  * {@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;
 }
コード例 #4
0
ファイル: ConditionSql.php プロジェクト: okite11/frames21
 /**
  * @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->map->getDocumentMap($document, MapInterface::TYPE_SOURCE);
         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);
 }
コード例 #5
0
 /**
  * @param string $sourceDocument
  * @return \Magento\Framework\DB\Select
  */
 protected function getConfigurablePrice($sourceDocument)
 {
     $sourceDocumentName = $this->source->addDocumentPrefix($sourceDocument);
     $fields = ['store_id' => 'website_id', 'value' => 'pricing_value', 'entity_id' => 'l.product_id', 'attribute_id' => 'cpsa.attribute_id'];
     /** @var \Magento\Framework\DB\Select $select */
     $select = $this->sourceAdapter->getSelect();
     $select->from($sourceDocumentName, $fields)->joinInner(['cpsa' => $this->source->addDocumentPrefix('catalog_product_super_attribute')], 'cpsa.product_super_attribute_id = ' . $sourceDocumentName . '.product_super_attribute_id', [])->joinInner(['l' => $this->source->addDocumentPrefix('catalog_product_super_link')], 'cpsa.product_id = l.parent_id', [])->joinInner(['a' => $this->source->addDocumentPrefix('catalog_product_super_attribute')], 'l.parent_id = a.product_id', [])->joinInner(['cp' => $this->source->addDocumentPrefix('catalog_product_entity_int')], 'l.product_id = cp.entity_id AND cp.attribute_id = a.attribute_id AND cp.store_id = ' . $sourceDocumentName . '.website_id', [])->joinInner(['apd' => $this->source->addDocumentPrefix('catalog_product_super_attribute_pricing')], 'a.product_super_attribute_id = apd.product_super_attribute_id AND apd.pricing_value = ' . $sourceDocumentName . '.pricing_value AND cp.value = apd.value_index', [])->joinInner(['le' => $this->source->addDocumentPrefix('catalog_product_entity')], 'le.entity_id = l.product_id', []);
     return $select;
 }
コード例 #6
0
ファイル: Data.php プロジェクト: okite11/frames21
 /**
  * @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;
 }
コード例 #7
0
 /**
  * Fulfill temporary table with redirects
  *
  * @param \Migration\Resource\Adapter\Mysql $adapter
  * @return void
  */
 protected function collectRedirects(\Migration\Resource\Adapter\Mysql $adapter)
 {
     $select = $adapter->getSelect();
     $select->from(['r' => $this->source->addDocumentPrefix('enterprise_url_rewrite')], ['id' => 'IFNULL(NULL, NULL)', 'request_path' => 'r.request_path', 'target_path' => 'r.target_path', 'is_system' => 'r.is_system', 'store_id' => "s.store_id", 'entity_type' => "trim('custom')", 'redirect_type' => "(SELECT CASE eurr.options WHEN 'RP' THEN 301 WHEN 'R' THEN 302 ELSE 0 END)", 'product_id' => "trim('0')", 'category_id' => "trim('0')", 'priority' => "trim('2')"]);
     $select->join(['eurrr' => $this->source->addDocumentPrefix('enterprise_url_rewrite_redirect_rewrite')], 'eurrr.url_rewrite_id = r.url_rewrite_id', []);
     $select->join(['eurr' => $this->source->addDocumentPrefix('enterprise_url_rewrite_redirect')], 'eurrr.redirect_id = eurr.redirect_id', []);
     $select->join(['s' => $this->source->addDocumentPrefix('core_store')], 's.store_id > 0', []);
     $query = $select->insertFromSelect($this->source->addDocumentPrefix($this->tableName));
     $select->getAdapter()->query($query);
 }
コード例 #8
0
ファイル: ConvertEavValue.php プロジェクト: okite11/frames21
 /**
  * @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;
 }
コード例 #9
0
 /**
  * @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;
     }
 }
コード例 #10
0
ファイル: Data.php プロジェクト: okite11/frames21
 /**
  * @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;
 }
コード例 #11
0
ファイル: Delta.php プロジェクト: okite11/frames21
 /**
  * {@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;
 }