Exemple #1
1
 /**
  * Assert that session data writes to DB in base64 encoding
  */
 public function testWriteEncoded()
 {
     $data = serialize($this->_sessionData[self::SESSION_NEW]);
     $this->_model->write(self::SESSION_ID, $data);
     $select = $this->_connection->select()->from($this->_sessionTable)->where(self::COLUMN_SESSION_ID . ' = :' . self::COLUMN_SESSION_ID);
     $bind = [self::COLUMN_SESSION_ID => self::SESSION_ID];
     $session = $this->_connection->fetchRow($select, $bind);
     $this->assertEquals(self::SESSION_ID, $session[self::COLUMN_SESSION_ID]);
     $this->assertTrue(ctype_digit((string) $session[self::COLUMN_SESSION_EXPIRES]), 'Value of session expire field must have integer type');
     $this->assertEquals($data, base64_decode($session[self::COLUMN_SESSION_DATA]));
 }
Exemple #2
0
 /**
  * @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
  */
 public function testAggregate()
 {
     $rating = $this->reviewCollection->getFirstItem();
     $this->reviewResource->aggregate($rating);
     $select = $this->adapter->select()->from($this->resource->getTableName('review_entity_summary'));
     $result = $this->adapter->fetchRow($select);
     $this->assertEquals(1, $result['reviews_count']);
     $this->assertEquals(40, $result['rating_summary']);
 }
 /**
  * {@inheritdoc}
  */
 public function getAggregations(\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
 {
     $aggregation = ['count' => 'count(DISTINCT main_table.entity_id)', 'max' => 'MAX(min_price)', 'min' => 'MIN(min_price)', 'std' => 'STDDEV_SAMP(min_price)'];
     $select = $this->getSelect();
     $tableName = $this->resource->getTableName('catalog_product_index_price');
     /** @var Table $table */
     $table = $entityStorage->getSource();
     $select->from(['main_table' => $tableName], [])->joinInner(['entities' => $table->getName()], 'main_table.entity_id  = entities.entity_id', [])->columns($aggregation);
     $select = $this->setCustomerGroupId($select);
     $result = $this->connection->fetchRow($select);
     return $result;
 }
 /** @inheritdoc */
 public function getByOdooId($odooId)
 {
     /** @var  $result AggWarehouse */
     $result = null;
     $query = $this->_factorySelect->getQueryToSelect();
     $query->where(static::AS_ODOO . '.' . EntityWarehouse::ATTR_ODOO_REF . '=:id');
     $data = $this->_conn->fetchRow($query, ['id' => $odooId]);
     if ($data) {
         $result = $this->_manObj->create(AggWarehouse::class);
         $result->setData($data);
     }
     return $result;
 }
 /**
  * @dataProvider insertDataProvider
  */
 public function testInsertForce($data)
 {
     $this->assertEquals(1, $this->_connection->insertForce($this->_tableName, $data));
     $select = $this->_connection->select()->from($this->_tableName);
     $result = $this->_connection->fetchRow($select);
     $this->assertEquals($data, $result);
 }
Exemple #6
0
 /**
  * @param mixed $nodeId
  * @return Node
  */
 public function loadNode($nodeId)
 {
     $select = clone $this->_select;
     $condition = $this->_conn->quoteInto("{$this->_table}.{$this->_idField}=?", $nodeId);
     $select->where($condition);
     $node = new Node($this->_conn->fetchRow($select), $this->_idField, $this);
     $this->addNode($node);
     return $node;
 }
Exemple #7
0
 /**
  * @param string|int $nodeId
  * @return Node
  */
 public function getNode($nodeId)
 {
     $dbSelect = new Select($this->_db);
     $dbSelect->from($this->_table)->where($this->_table . '.' . $this->_id . ' >= :id');
     $this->_addExtTablesToSelect($dbSelect);
     $data = [];
     $data['id'] = $nodeId;
     $data = $this->_db->fetchRow($dbSelect, $data);
     return new Node($data, $this->getKeys());
 }
Exemple #8
0
 /**
  * Load node
  *
  * @param int|string $nodeId
  * @return Node
  */
 public function loadNode($nodeId)
 {
     $select = clone $this->_select;
     if (is_numeric($nodeId)) {
         $condField = $this->_conn->quoteIdentifier([$this->_table, $this->_idField]);
     } else {
         $condField = $this->_conn->quoteIdentifier([$this->_table, $this->_pathField]);
     }
     $select->where("{$condField} = ?", $nodeId);
     $node = new Node($this->_conn->fetchRow($select), $this->_idField, $this);
     $this->addNode($node);
     return $node;
 }
 /**
  * Get maximum version_id from changelog
  *
  * @return int
  * @throws \Exception
  */
 public function getVersion()
 {
     $changelogTableName = $this->resource->getTableName($this->getName());
     if (!$this->connection->isTableExists($changelogTableName)) {
         throw new \Exception("Table {$changelogTableName} does not exist");
     }
     $row = $this->connection->fetchRow('SHOW TABLE STATUS LIKE ?', [$changelogTableName]);
     if (isset($row['Auto_increment'])) {
         return (int) $row['Auto_increment'] - 1;
     } else {
         throw new \Exception("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id.");
     }
 }
 /**
  * @inheritdoc
  *
  * @SuppressWarnings(PHPMD.ShortVariable)
  */
 public function getById($id)
 {
     /** @var  $result AggWarehouse */
     $result = null;
     $query = $this->_factorySelect->getQueryToSelect();
     $query->where(static::AS_STOCK . '.' . Cfg::E_CATINV_STOCK_A_STOCK_ID . '=:id');
     $data = $this->_conn->fetchRow($query, ['id' => $id]);
     if ($data) {
         $result = $this->_manObj->create(AggLot::class);
         $result->setData($data);
     }
     return $result;
 }
 /**
  * Load subscriber by customer
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @return array
  */
 public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id');
     $result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]);
     if ($result) {
         return $result;
     }
     $select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
     $result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);
     if ($result) {
         return $result;
     }
     return [];
 }
Exemple #12
0
 /**
  * Retrieve table status
  *
  * @param string $tableName
  * @return \Magento\Framework\DataObject|bool
  */
 public function getTableStatus($tableName)
 {
     $row = $this->connection->showTableStatus($tableName);
     if ($row) {
         $statusObject = new \Magento\Framework\DataObject();
         foreach ($row as $field => $value) {
             $statusObject->setData(strtolower($field), $value);
         }
         $cntRow = $this->connection->fetchRow($this->connection->select()->from($tableName, 'COUNT(1) as rows'));
         $statusObject->setRows($cntRow['rows']);
         return $statusObject;
     }
     return false;
 }
 /** @inheritdoc */
 public function getByOdooId($id)
 {
     $result = null;
     if (is_null($id)) {
         $this->_checkNullLot();
     }
     $query = $this->_factorySelect->getQueryToSelect();
     $where = static::AS_ODOO . '.' . EntityLot::ATTR_ODOO_REF . '=:id';
     $query->where($where);
     $data = $this->_conn->fetchRow($query, ['id' => $id]);
     if ($data) {
         /** @var  $result AggLot */
         $result = $this->_manObj->create(AggLot::class);
         $result->setData($data);
     }
     return $result;
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 protected function doFindByFilter($filter)
 {
     return $this->connection->fetchRow($this->prepareSelect($filter));
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  */
 protected function doFindOneByData($data)
 {
     return $this->connection->fetchRow($this->prepareSelect($data));
 }