Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * @return bool
  */
 public function perform()
 {
     $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO);
     foreach ($this->getDocumentList() as $methodToExecute => $document) {
         $destinationDocumentName = $document['destination'];
         $this->destination->clearDocument($destinationDocumentName);
         $this->progress->start(1, LogManager::LOG_LEVEL_DEBUG);
         $sourceGridDocument = array_flip($this->helper->getDocumentList())[$destinationDocumentName];
         $entityIds = $this->getEntityIdsFromSourceGrid($sourceGridDocument);
         if ($entityIds) {
             $this->destination->getAdapter()->insertFromSelect($this->{$methodToExecute}($document['columns'], $entityIds), $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
         }
         $this->progress->finish(LogManager::LOG_LEVEL_DEBUG);
     }
     $this->progress->finish(LogManager::LOG_LEVEL_INFO);
     return true;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * {@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;
 }
Ejemplo n.º 5
0
 /**
  * @throws \Zend_Db_Adapter_Exception
  * @return void
  */
 public function updateEavAttributes()
 {
     /** @var Mysql $adapter */
     $adapter = $this->destination->getAdapter();
     $query = $adapter->getSelect()->from($this->destination->addDocumentPrefix('eav_entity_type'), ['entity_type_id', 'entity_type_code']);
     $entityTypes = $query->getAdapter()->fetchAll($query);
     $entityTypesByCode = [];
     foreach ($entityTypes as $entityType) {
         $entityTypesByCode[$entityType['entity_type_code']] = $entityType['entity_type_id'];
     }
     $entities = array_keys($this->readerGroups->getGroup('eav_entities'));
     foreach ($entities as $entity) {
         $documents = $this->readerGroups->getGroup($entity);
         foreach ($documents as $document => $key) {
             if ($key != 'entity_id') {
                 continue;
             }
             $codes = implode("','", array_keys($this->readerAttributes->getGroup($document)));
             $where = [sprintf("attribute_code IN ('%s')", $codes), sprintf("entity_type_id = '%s'", $entityTypesByCode[$entity])];
             $adapter->getSelect()->getAdapter()->update($this->destination->addDocumentPrefix('eav_attribute'), ['backend_type' => 'static'], $where);
         }
     }
 }
Ejemplo n.º 6
0
 public function testGetAdapter()
 {
     $this->assertSame($this->adapter, $this->resourceDestination->getAdapter());
 }