/** * * @param Zend_Db_Statement_Interface $statement * @return array */ public function getLoadedValues(Zend_Db_Statement_Interface $statement) { $returningData = array(); $currentIntervallValue1 = 0; $currentIntervallValue2 = 0; $currentTimestamp = 0; $currentValue = 0.0; // First call of row. $row = $statement->fetch(); $currentTimestamp = $row['manipulationtime']; $currentValue = (double) $row['value']; $this->_setCurrentIntervallByRow($row, $currentIntervallValue1, $currentIntervallValue2); while ($row = $statement->fetch()) { if ($this->_isRowOfNewIntervall($row, $currentIntervallValue1, $currentIntervallValue2)) { $currentTimestamp = $row['manipulationtime']; $returningData[] = array($currentTimestamp, $currentValue); $currentValue = (double) $row['value']; $this->_setCurrentIntervallByRow($row, $currentIntervallValue1, $currentIntervallValue2); } else { $currentValue += (double) $row['value']; } } // TODO Fill last entry with data; doesn\'t work quite well // TODO If the last measurement is made of a new intervall, the entry will be added twice into array. // TODO Handle it if neccessary. // $returningData[] = array($currentTimestamp, $currentValue); return $returningData; }
/** * * @param Zend_Db_Statement_Interface $statement * @return array */ public function getLoadedValues(Zend_Db_Statement_Interface $statement) { $returningData = array(); while ($row = $statement->fetch()) { $returningData[] = array($row['manipulationtime'], (double) $row['value']); } return $returningData; }
/** * Fetch Zend statement instance * * @param Zend_Db_Statement_Interface|Zend_Db_Select|string $query * @param Zend_Db_Adapter_Abstract $conn * @return Zend_Db_Statement_Interface * @throws Mage_Core_Exception */ protected function _getStatement($query, $conn = null) { if ($query instanceof Zend_Db_Statement_Interface) { return $query; } if ($query instanceof Zend_Db_Select) { return $query->query(); } if (is_string($query)) { if (!$conn instanceof Zend_Db_Adapter_Abstract) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('Invalid connection')); } return $conn->query($query); } Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('Invalid query')); }
/** * Fetch Zend statement instance * * @param \Zend_Db_Statement_Interface|Zend_Db_Select|string $query * @param \Zend_Db_Adapter_Abstract $conn * @return \Zend_Db_Statement_Interface * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getStatement($query, $conn = null) { if ($query instanceof \Zend_Db_Statement_Interface) { return $query; } if ($query instanceof \Zend_Db_Select) { return $query->query(); } if (is_string($query)) { if (!$conn instanceof \Zend_Db_Adapter_Abstract) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid connection')); } return $conn->query($query); } throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid query')); }
/** * Fetch Zend statement instance * * @param \Zend_Db_Statement_Interface|\Magento\Framework\DB\Select|string $query * @param AdapterInterface $connection * @return \Zend_Db_Statement_Interface * @throws LocalizedException */ protected function _getStatement($query, AdapterInterface $connection = null) { if ($query instanceof \Zend_Db_Statement_Interface) { return $query; } if ($query instanceof \Zend_Db_Select) { return $query->query(); } if (is_string($query)) { if (!$connection instanceof AdapterInterface) { throw new LocalizedException(new Phrase('Invalid connection')); } return $connection->query($query); } throw new LocalizedException(new Phrase('Invalid query')); }
/** * Move forward to next element */ public function next() { if (!$this->_statement instanceof \Zend_Db_Statement_Interface) { $this->_initStatement(); } $this->_row = $this->_statement->fetch(); $this->_i = $this->_i + 1; }
/** * Fetch Zend statement instance * * @param Zend_Db_Statement_Interface|Zend_Db_Select|string $query * @param Zend_Db_Adapter_Abstract $conn * @return Zend_Db_Statement_Interface */ protected function _getStatement($query, $conn = null) { if ($query instanceof Zend_Db_Statement_Interface) { return $query; } if ($query instanceof Zend_Db_Select) { return $query->query(); } $hlp = AO::helper('core'); if (is_string($query)) { if (!$conn instanceof Zend_Db_Adapter_Abstract) { AO::throwException($hlp->__('Invalid connection')); } return $conn->query($query); } AO::throwException($hlp->__('Invalid query')); }
public function testSyncCustomerGrid() { $gridTable = 'customer_grid_flat'; $customerLogTable = 'customer_log'; $this->indexerRegistry->expects($this->once())->method('get')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID)->willReturn($this->indexer); $this->resource->expects($this->once())->method('getConnection')->willReturn($this->connection); $this->flatScopeResolver->expects($this->once())->method('resolve')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID, [])->willReturn($gridTable); $this->resource->expects($this->exactly(2))->method('getTableName')->willReturnMap([[$gridTable], [$customerLogTable]]); $this->connection->expects($this->exactly(2))->method('select')->willReturn($this->select); $this->select->expects($this->exactly(2))->method('from')->willReturnSelf(); $this->select->expects($this->once())->method('order')->with('last_visit_at DESC')->willReturnSelf(); $this->select->expects($this->once())->method('limit')->with(1)->willReturnSelf(); $this->connection->expects($this->atLeastOnce())->method('query')->with($this->select)->willReturn($this->queryResult); $this->queryResult->expects($this->once())->method('fetchColumn')->willReturn('2015-08-13 10:36:44'); $this->select->expects($this->once())->method('where')->with('last_login_at > ?', '2015-08-13 10:36:44')->willReturnSelf(); $this->queryResult->expects($this->once())->method('fetchAll')->willReturn([['customer_id' => 23], ['customer_id' => 65]]); $this->indexer->expects($this->once())->method('reindexList')->with(['23', '65']); $this->observer->syncCustomerGrid(); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return void */ protected function setUp() { $this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock(); $this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]); $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock(); $this->selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->selectMock->expects($this->any())->method('where')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf(); $this->selectMock->expects($this->any())->method('having')->willReturnSelf(); $this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf(); $this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf(); $this->selectMock->expects($this->any())->method('__toString')->willReturn('string'); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock); $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) { return $arg; })); $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock); $dateTime = $this->getMockBuilder('DateTime')->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime); $this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock(); $this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock); $this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock(); $this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock); $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product')->disableOriginalConstructor()->getMock(); $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock); $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\ResourceModel\\Helper')->disableOriginalConstructor()->getMock(); $this->viewed = (new ObjectManager($this))->getObject('Magento\\Reports\\Model\\ResourceModel\\Report\\Product\\Viewed', ['context' => $this->contextMock, 'localeDate' => $this->timezoneMock, 'reportsFlagFactory' => $this->flagFactoryMock, 'productResource' => $this->productMock, 'resourceHelper' => $this->helperMock]); }
/** * @param Zend_Db_Statement_Interface $stmt * @param string $filename * @param string $title */ public function sendExcel($stmt, $filename, $title) { $this->Response()->setHeader('Content-Type', 'application/vnd.ms-excel;charset=UTF-8'); $this->Response()->setHeader('Content-Disposition', sprintf('attachment; filename="%s"', $filename)); $this->Response()->setHeader('Content-Transfer-Encoding', 'binary'); $excel = new Shopware_Components_Convert_Excel(); $excel->setTitle($title); $first = true; echo $excel->getHeader(); while ($row = $stmt->fetch()) { if ($first) { $first = false; echo $excel->encodeRow(array_keys($row)); } echo $excel->encodeRow($row); } echo $excel->getFooter(); }
/** * Migrate Entries of non-select/multiselect Entities to new Entity Table * * @param string $targetType Target Type as String * @param Zend_Db_Statement_Interface $sourceQuery Source Entity Table Query with old Entity Data to Transfer * @param string $sourceType Source Type as String * @param string $targetTable Target Entity Table * @param Varien_Db_Adapter_Interface $_dbConnection Database Connection * @param string $sourceTable Source Entity Table * @return void */ protected function _migrateNonSelect($targetType, $sourceQuery, $sourceType, $targetTable, $_dbConnection, $sourceTable) { while ($row = $sourceQuery->fetch()) { $currentValue = $row['value']; if (!is_null($currentValue)) { // Cast Value Type to new Type (e.g. decimal to text) $targetValue = $this->_typeCast($currentValue, $sourceType, $targetType); // Insert Value to target Entity $sql = 'INSERT' . ' INTO ' . $targetTable . ' (entity_type_id, attribute_id, store_id, entity_id, value) VALUES (?,?,?,?,?)'; try { $_dbConnection->query($sql, [$row['entity_type_id'], $row['attribute_id'], $row['store_id'], $row['entity_id'], $targetValue]); } catch (Exception $e) { $this->_getHelper()->log(sprintf('Exception occured while migrating Data. See exception log.'), $e); } } // Delete Value from source Entity $sql = 'DELETE' . ' FROM ' . $sourceTable . ' WHERE value_id = ?'; $_dbConnection->query($sql, $row['value_id']); } }