/** * Load changelog by metadata * * @param null|int $currentVersion * @return array */ public function loadByMetadata($currentVersion = null) { $select = $this->_connection->select()->from(array('changelog' => $this->_metadata->getChangelogName()), array())->where('version_id >= ?', $this->_metadata->getVersionId())->columns(array($this->_metadata->getKeyColumn())); if ($currentVersion) { $select->where('version_id < ?', $currentVersion); } return $this->_connection->fetchCol($select); }
/** * Returns select object with changed Ids * * @param int|null $maxVersion * @return Varien_Db_Select */ protected function _getChangedIdsSelect($maxVersion = null) { if (empty($maxVersion)) { $maxVersion = $this->_getCurrentVersionId(); } return $this->_connection->select()->from($this->_metadata->getChangelogName(), array())->where('version_id > ?', $this->_metadata->getVersionId())->where('version_id <= ?', $maxVersion)->columns(array($this->_metadata->getKeyColumn()))->distinct(); }
/** * Returns column definition for column provided in key_column parameter. * * @return array * @throws Enterprise_Mview_Exception */ protected function _getKeyColumnConfig() { $describe = $this->_table->describe(); if (!array_key_exists($this->_metadata->getKeyColumn(), $describe)) { throw new Enterprise_Mview_Exception(sprintf("Column '%s' does not exist in the '%s' table", $this->_metadata->getKeyColumn(), $this->_table->getObjectName())); } return $this->_connection->getColumnCreateByDescribe($describe[$this->_metadata->getKeyColumn()]); }
/** * Clean duplicate entity data from changelog tables before running the indexing * * @param Enterprise_Mview_Model_Metadata $metadata * @return Enterprise_Mview_Model_Client */ protected function _cleanChangelogTablesBeforeIndexing(Enterprise_Mview_Model_Metadata $metadata) { $_connection = $this->_getDefaultConnection(); $subSelect = $_connection->select()->from(array('cl' => $metadata->getChangelogName()), array('version_id' => 'MAX(cl.version_id)'))->where('cl.version_id > ?', $metadata->getVersionId())->group('cl.' . $metadata->getKeyColumn()); $select = $_connection->select()->from($subSelect, array('*')); $whereCondition = array($_connection->quoteInto('version_id > ?', $metadata->getVersionId()), 'version_id NOT IN (' . $select . ')'); $_connection->delete($metadata->getChangelogName(), implode(' AND ', $whereCondition)); return $this; }
/** * Refresh rows by ids from changelog * * @return Enterprise_Mview_Model_Action_Mview_Refresh_Changelog * @throws Enterprise_Mview_Exception */ public function execute() { $this->_validate(); $this->_connection->beginTransaction(); try { $this->_connection->delete($this->_metadata->getTableName(), array($this->_metadata->getKeyColumn() . ' IN ( ' . $this->_selectChangedIds() . ' )')); $this->_connection->query($this->_connection->insertFromSelect($this->_selectChangedRows(), $this->_metadata->getTableName())); $this->_metadata->setVersionId($this->_selectLastVersionId()); $this->_metadata->save(); $this->_connection->commit(); } catch (Exception $e) { $this->_connection->rollBack(); $this->_metadata->setOutOfDateStatus()->save(); throw new Enterprise_Mview_Exception($e->getMessage(), $e->getCode()); } return $this; }
/** * Returns select sql * * @return Varien_Db_Select */ protected function _getSelectSql() { return $this->_connection->select()->from($this->_metadata->getViewName())->where($this->_metadata->getKeyColumn() . ' = ?', $this->_keyColumnIdValue); }