/** * 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->_table = $this->_factory->getMagentoDbObjectTable($this->_connection, $this->_metadata->getTableName()); $this->_view = $this->_factory->getMagentoDbObjectView($this->_connection, $this->_metadata->getViewName()); }
/** * Prepare changelog table name * * @return string * @throws Enterprise_Mview_Exception */ protected function _getChangelogName() { if (!$this->_metadata->getTableName()) { throw new Enterprise_Mview_Exception('Mview table name should be specified'); } return $this->_metadata->getTableName() . '_cl'; }
/** * Refresh materialized view * * @return Enterprise_Mview_Model_Action_Mview_Refresh * @throws Exception */ public function execute() { try { $insert = $this->_connection->insertFromSelect($this->_connection->select()->from($this->_metadata->getViewName()), $this->_metadata->getTableName()); $this->_connection->delete($this->_metadata->getTableName()); $this->_connection->query($insert); $this->_metadata->setValidStatus()->setVersionId($this->_selectLastVersionId())->save(); } catch (Exception $e) { $this->_metadata->setInvalidStatus()->save(); throw $e; } 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 materialized view name * * @return string */ protected function _getViewName() { return $this->_metadata->getTableName() . '_view'; }
/** * Initialize and execute changelog clear action with metadata provided. * * @param Enterprise_Mview_Model_Metadata $metadata */ protected function _runCleanupAction(Enterprise_Mview_Model_Metadata $metadata) { $this->_getClient()->init($metadata->getTableName()); try { $this->_getClient()->execute('enterprise_mview/action_changelog_clear'); } catch (Exception $e) { $this->_logger->logException($e); } }
/** * Returns insert sql * * @return string */ public function _getInsertSql() { return $this->_connection->insertFromSelect($this->_getSelectSql(), $this->_metadata->getTableName()); }
/** * Retrieve code for the paired indexer * * @return string */ protected function _getPairedIndexerCode() { return $this->_metadata->getTableName() == 'catalog_category_product_index' ? 'catalog_category_product_cat' : 'catalog_category_product_index'; }