Пример #1
0
 /**
  * Populates temporary table
  *
  * @param Table $table
  * @param array $data
  * @return Table
  * @throws \Zend_Db_Exception
  */
 private function populateTemporaryTable(Table $table, $data)
 {
     if (count($data)) {
         $this->getConnection()->insertArray($table->getName(), [self::FIELD_ENTITY_ID, self::FIELD_SCORE], $data);
     }
     return $table;
 }
Пример #2
0
 /**
  * Executes query and return raw response
  *
  * @param Table $table
  * @return array
  * @throws \Zend_Db_Exception
  */
 private function getDocuments(Table $table)
 {
     $connection = $this->getConnection();
     $select = $connection->select();
     $select->from($table->getName(), ['entity_id', 'score']);
     return $connection->fetchAssoc($select);
 }
Пример #3
0
 /**
  * @param \Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject
  * @param callable|\Closure $proceed
  * @param BucketInterface $bucket
  * @param Dimension[] $dimensions
  *
  * @param Table $entityIdsTable
  * @return Select
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetDataSet(\Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider $subject, \Closure $proceed, BucketInterface $bucket, array $dimensions, Table $entityIdsTable)
 {
     if ($bucket->getField() == 'category_ids') {
         $currentScopeId = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
         $currentCategory = $this->layer->getCurrentCategory();
         $derivedTable = $this->resource->getConnection()->select();
         $derivedTable->from(['main_table' => $this->resource->getTableName('catalog_category_product_index')], ['value' => 'category_id'])->where('main_table.store_id = ?', $currentScopeId);
         $derivedTable->joinInner(['entities' => $entityIdsTable->getName()], 'main_table.product_id  = entities.entity_id', []);
         if (!empty($currentCategory)) {
             $derivedTable->join(['category' => $this->resource->getTableName('catalog_category_entity')], 'main_table.category_id = category.entity_id', [])->where('`category`.`path` LIKE ?', $currentCategory->getPath() . '%')->where('`category`.`level` > ?', $currentCategory->getLevel());
         }
         $select = $this->resource->getConnection()->select();
         $select->from(['main_table' => $derivedTable]);
         return $select;
     }
     return $proceed($bucket, $dimensions, $entityIdsTable);
 }
Пример #4
0
 public function testBuildWithoutPassedDocuments()
 {
     $documentIds = [1, 2];
     $tableName = 'table_name';
     $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
     $select->expects($this->once())->method('from')->with($tableName, TemporaryStorage::FIELD_ENTITY_ID)->willReturnSelf();
     $this->table->expects($this->once())->method('getName')->willReturn($tableName);
     $this->connectionMock->expects($this->once())->method('select')->willReturn($select);
     $this->connectionMock->expects($this->once())->method('fetchCol')->willReturn($documentIds);
     $this->aggregationResolver->expects($this->once())->method('resolve')->with($this->request, $documentIds)->willReturn([]);
     $this->builder->build($this->request, $this->table);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function getDataSet(BucketInterface $bucket, array $dimensions, Table $entityIdsTable)
 {
     $currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
     $attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());
     $select = $this->getSelect();
     if ($attribute->getAttributeCode() == 'price') {
         /** @var \Magento\Store\Model\Store $store */
         $store = $this->scopeResolver->getScope($currentScope);
         if (!$store instanceof \Magento\Store\Model\Store) {
             throw new \RuntimeException('Illegal scope resolved');
         }
         $table = $this->resource->getTableName('catalog_product_index_price');
         $select->from(['main_table' => $table], null)->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price'])->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('main_table.website_id = ?', $store->getWebsiteId());
     } else {
         $currentScopeId = $this->scopeResolver->getScope($currentScope)->getId();
         $table = $this->resource->getTableName('catalog_product_index_eav' . ($attribute->getBackendType() == 'decimal' ? '_decimal' : ''));
         $select->from(['main_table' => $table], ['value'])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ? ', $currentScopeId);
     }
     $select->joinInner(['entities' => $entityIdsTable->getName()], 'main_table.entity_id  = entities.entity_id', []);
     return $select;
 }
Пример #6
0
 /**
  * @param \Magento\Framework\DB\Ddl\Table $table
  * @return $this
  */
 public function prepareTemporaryTable($table)
 {
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     /** @var \Mirasvit\Search\Model\IndexFactory $indexFactory */
     $indexFactory = $objectManager->get('Mirasvit\\Search\\Model\\IndexFactory');
     $index = $indexFactory->create()->load('catalogsearch_fulltext');
     if (!$index->hasProperty('only_active_categories')) {
         return $this;
     }
     /** @var \Magento\Catalog\Model\Category\Tree $tree */
     $tree = $objectManager->get('Magento\\Catalog\\Model\\Category\\Tree');
     $root = $tree->getTree($tree->getRootNode())->getChildrenData();
     $ids = $this->getActiveCategories($root);
     /** @var \Magento\Framework\App\ResourceConnection $resource */
     $resource = $objectManager->get('Magento\\Framework\\App\\ResourceConnection');
     $connection = $resource->getConnection();
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $prods */
     $prods = $objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection');
     $prods->addCategoriesFilter(['eq' => $ids]);
     $select = $prods->getSelect()->reset('columns')->columns(['entity_id']);
     $connection->delete($table->getName(), ['entity_id NOT IN(' . new \Zend_Db_Expr($select) . ')']);
     return $this;
 }
Пример #7
0
 /**
  * Get document ids
  *
  * @param Table $documentsTable
  * @return array
  * @deprecated Added for backward compatibility
  */
 private function getDocumentIds(Table $documentsTable)
 {
     $select = $this->getConnection()->select()->from($documentsTable->getName(), TemporaryStorage::FIELD_ENTITY_ID);
     return $this->getConnection()->fetchCol($select);
 }
Пример #8
0
 /**
  * Retrieve table options definition array for create table
  *
  * @param Table $table
  * @return string[]
  * @throws ErrorException
  */
 protected function _getOptionsDefinition(Table $table)
 {
     $definition = array();
     $comment = $table->getComment();
     if (empty($comment)) {
         throw new ErrorException('Comment for table is required and must be defined');
     }
     $definition[] = $this->quoteInto('COMMENT=?', $comment);
     $tableProps = array('type' => 'ENGINE=%s', 'checksum' => 'CHECKSUM=%d', 'auto_increment' => 'AUTO_INCREMENT=%d', 'avg_row_length' => 'AVG_ROW_LENGTH=%d', 'max_rows' => 'MAX_ROWS=%d', 'min_rows' => 'MIN_ROWS=%d', 'delay_key_write' => 'DELAY_KEY_WRITE=%d', 'row_format' => 'row_format=%s', 'charset' => 'charset=%s', 'collate' => 'COLLATE=%s');
     foreach ($tableProps as $key => $mask) {
         $v = $table->getOption($key);
         if ($v !== null) {
             $definition[] = sprintf($mask, $v);
         }
     }
     return $definition;
 }
 /**
  * @param Table $table
  * @return Table
  */
 protected function configureFulltextTable(Table $table)
 {
     $table->addColumn('entity_id', Table::TYPE_INTEGER, 10, ['unsigned' => true, 'nullable' => false], 'Entity ID')->addColumn('attribute_id', Table::TYPE_TEXT, 255, ['unsigned' => true, 'nullable' => true])->addColumn('data_index', Table::TYPE_TEXT, '4g', ['nullable' => true], 'Data index')->addIndex('idx_primary', ['entity_id', 'attribute_id'], ['type' => AdapterInterface::INDEX_TYPE_PRIMARY])->addIndex('FTI_FULLTEXT_DATA_INDEX', ['data_index'], ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]);
     return $table;
 }
Пример #10
0
 /**
  * @param Table $tableDdl
  * @return void
  */
 public function createTableByDdl($tableDdl)
 {
     $this->resourceAdapter->dropTable($tableDdl->getName());
     $this->resourceAdapter->createTable($tableDdl);
     $this->resourceAdapter->resetDdlCache($tableDdl->getName());
 }
Пример #11
0
 /**
  * @param Select $query
  * @param Table $previousResultTable
  * @param ScoreBuilder $scoreBuilder
  * @return Select
  * @throws \Zend_Db_Exception
  */
 private function joinPreviousResultToSelect(Select $query, Table $previousResultTable, ScoreBuilder $scoreBuilder)
 {
     $query->joinInner(['previous_results' => $previousResultTable->getName()], 'previous_results.entity_id = search_index.entity_id', []);
     $scoreBuilder->addCondition('previous_results.score', false);
     $query->columns($scoreBuilder->build());
     $query = $this->createAroundSelect($query, $scoreBuilder);
     return $query;
 }
 /**
  * @param string $mode
  * @param Table $table
  * @param array|int $modifyColumns
  * @throws \Zend_Db_Exception
  */
 private function migrateTable($mode, Table $table, $modifyColumns)
 {
     if ($mode === 'remove' && is_array($modifyColumns)) {
         $describedTable = $this->describeTable($table->getName());
         foreach ($modifyColumns as $column) {
             if (isset($describedTable[$column])) {
                 $cd = $this->getColumnCreateByDescribe($describedTable[$column]);
                 $this->changeColumn($table->getName(), $column, 'z_' . $column, $cd);
             }
         }
         return;
     }
     $modifyColumns = array_flip($modifyColumns);
     // values are now keys
     $modifyColumns = array_change_key_case($modifyColumns, CASE_UPPER);
     $position = '';
     foreach ($table->getColumns() as $name => $column) {
         if (isset($modifyColumns[$name])) {
             $column['AFTER'] = $position;
             switch ($mode) {
                 case 'add':
                     $this->addColumn($table->getName(), $column['COLUMN_NAME'], $column);
                     break;
                 case 'change':
                     $this->changeColumn($table->getName(), $column['COLUMN_NAME'], $column['COLUMN_NAME'], $column);
                     break;
                 default:
                     throw new \InvalidArgumentException('Not implemented in migrateColumn method');
             }
         }
         $position = $column['COLUMN_NAME'];
     }
     return;
 }
 protected function createMemoryTable()
 {
     $this->memoryTable = $this->createTable([['COLUMN_NAME' => 'entity_id', 'DATA_TYPE' => 'int', 'DEFAULT' => null, 'NULLABLE' => false, 'LENGTH' => null, 'SCALE' => null, 'PRECISION' => null, 'UNSIGNED' => true, 'PRIMARY' => true, 'PRIMARY_POSITION' => 0, 'IDENTITY' => false]]);
     return $this->memoryTable->getName();
 }