/** * Constructor with parameters * Array of arguments with keys * - 'connection' Varien_Db_Adapter_Interface * - 'metadata' Enterprise_Mview_Model_Metadata * - 'factory' Enterprise_Mview_Model_Factory * * @param array $args */ public function __construct(array $args) { $this->_setConnection($args['connection']); $this->_setMetadata($args['metadata']); $this->_setFactory($args['factory']); $this->_changelog = $this->_factory->getMagentoDbObjectTable($this->_connection, $this->_metadata->getChangelogName()); }
/** * 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; }
/** * Validate metadata before execute * * @return Enterprise_Mview_Model_Action_Mview_Refresh_Changelog * @throws Enterprise_Mview_Exception */ protected function _validate() { if (!$this->_metadata->getId() || !$this->_metadata->getChangelogName()) { throw new Enterprise_Mview_Exception('Can\'t perform operation, incomplete metadata!'); } return $this; }
/** * Get current DB version * * @return int */ protected function _getCurrentVersionId() { if (empty($this->_currentVersionId)) { // zend select query permanently requires FROM statement, so executing raw query $this->_currentVersionId = $this->_connection->query($this->_connection->select()->from($this->_metadata->getChangelogName(), array())->columns(array('max' => 'MAX(version_id)')))->fetchColumn(); } return $this->_currentVersionId; }
/** * Returns last version_id from changelog table * * @return int */ protected function _selectLastVersionId() { $changelogName = $this->_metadata->getChangelogName(); if (empty($changelogName)) { return 0; } $select = $this->_connection->select()->from(array('changelog' => $changelogName), array('version_id'))->order('version_id DESC')->limit(1); return (int) $this->_connection->fetchOne($select); }
/** * Return last version ID * * @return string */ protected function _getLastVersionId() { $changelogName = $this->_metadata->getChangelogName(); if (empty($changelogName)) { return 0; } if (!$this->_lastVersionId) { $select = $this->_connection->select()->from($changelogName, array('version_id'))->order('version_id DESC')->limit(1); $this->_lastVersionId = (int) $this->_connection->fetchOne($select); } return $this->_lastVersionId; }
/** * Clear changelog table * * @return Enterprise_Mview_Model_Action_Changelog_Clear */ public function execute() { $this->_connection->delete($this->_metadata->getChangelogName(), array('version_id < ?' => $this->_metadata->getVersionId())); return $this; }
/** * Return last version id * * @return int */ public function getLastVersionId() { $select = $this->_connection->select()->from($this->_metadata->getChangelogName(), array('version_id'))->order('version_id DESC')->limit(1); return (int) $this->_connection->fetchOne($select); }