/**
  * Init materialized view metadata
  *
  * @param string $name
  * @return Enterprise_Mview_Model_Client
  */
 public function init($name)
 {
     $tableName = $this->_factory->getSingleton('core/resource')->getTableName($name);
     $this->_metadata = $this->_factory->getModel('enterprise_mview/metadata')->load($tableName, 'table_name');
     if (!$this->_metadata->getId()) {
         $this->_metadata->setTableName($tableName);
     }
     return $this;
 }
 /**
  * Refresh the custom products position index : just rebuild data from this data provider
  *
  * @return Smile_VirtualCategories_Model_Index_Action_VirtualCategories_Product_Position_Refresh
  *
  * @throws Enterprise_Index_Model_Action_Exception
  */
 public function execute()
 {
     if (!Mage::helper('smile_elasticsearch')->isActiveEngine() == false) {
         $this->_metadata->setInProgressStatus()->save();
         // Let the index process all data
         $this->_indexer->reindexAll();
         if ($this->_metadata->getStatus() == Enterprise_Mview_Model_Metadata::STATUS_IN_PROGRESS) {
             $this->_metadata->setValidStatus()->save();
         }
     }
     return $this;
 }
 /**
  * Refresh rows by ids from changelog.
  *
  * @return Smile_ElasticSearch_Model_Index_Action_Search_Terms_Refresh_Changelog
  *
  * @throws Enterprise_Index_Model_Action_Exception
  */
 public function execute()
 {
     if (!$this->_metadata->isValid()) {
         throw new Enterprise_Index_Model_Action_Exception("Can't perform operation, incomplete metadata!");
     }
     if (Mage::helper('smile_elasticsearch')->isActiveEngine() == true) {
         $this->_setProductIdsFromValue();
         $engine = Mage::helper('catalogsearch')->getEngine();
         $mapping = $engine->getCurrentIndex()->getMapping('product');
         $dataprovider = $mapping->getDataProvider('search_terms_position');
         $dataprovider->updateAllData(null, $this->_productIds);
     }
     return $this;
 }
 /**
  * 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';
 }
Esempio n. 5
0
 /**
  * Drop materialized view table, view and metadata.
  *
  * @return Enterprise_Mview_Model_Action_Mview_Drop
  */
 public function execute()
 {
     $this->_view->drop();
     $this->_table->drop();
     $this->_metadata->delete();
     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;
 }
Esempio n. 7
0
 /**
  * Set changelog valid and update version id into metedata
  *
  * @return Enterprise_Index_Model_Action_Abstract
  */
 protected function _updateMetadata()
 {
     if ($this->_metadata->getStatus() == Enterprise_Mview_Model_Metadata::STATUS_IN_PROGRESS) {
         $this->_metadata->setValidStatus();
     }
     $this->_metadata->setVersionId($this->_getLastVersionId())->save();
     return $this;
 }
Esempio n. 8
0
 /**
  * Execute additional operations before reindex
  *
  * @return Enterprise_Catalog_Model_Index_Action_Catalog_Category_Product_Refresh
  */
 protected function _beforeReindex()
 {
     $this->_metadata->setInProgressStatus()->save();
     /** @var $client Enterprise_Mview_Model_Client */
     $client = $this->_factory->getModel('enterprise_mview/client');
     $client->init($this->_getPairedIndexerCode())->getMetadata()->setInProgressStatus()->save();
     return $this;
 }
Esempio n. 9
0
 /**
  * Init materialized view metadata by table name
  *
  * @param string $tableName
  *
  * @return Enterprise_Mview_Model_Client
  */
 public function initByTableName($tableName)
 {
     $this->_metadata = $this->_factory->getModel('enterprise_mview/metadata')->load($tableName, 'table_name');
     if (!$this->_metadata->getId()) {
         $this->_metadata->setTableName($tableName);
     }
     return $this;
 }
 /**
  * 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);
 }
Esempio n. 11
0
 /**
  * Removes redirect rows which have no corresponding records in redirect table from index.
  *
  * @return Enterprise_UrlRewrite_Model_Index_Action_Url_Rewrite_Redirect_Refresh_Orphan
  * @throws Enterprise_Index_Model_Action_Exception
  */
 public function execute()
 {
     try {
         $select = $this->_connection->select()->from(array('ur' => $this->_getTable('enterprise_urlrewrite/url_rewrite')), '*')->joinInner(array('rr' => $this->_getTable('enterprise_urlrewrite/redirect_rewrite')), 'ur.url_rewrite_id = rr.url_rewrite_id')->joinLeft(array('redirect' => $this->_getTable('enterprise_urlrewrite/redirect')), 'redirect.redirect_id = rr.redirect_id')->where('ur.entity_type = ?', Enterprise_UrlRewrite_Model_Redirect::URL_REWRITE_ENTITY_TYPE)->where('redirect.redirect_id IS NULL');
         $this->_connection->query($this->_connection->deleteFromSelect($select, 'ur'));
     } catch (Exception $e) {
         $this->_metadata->setInvalidStatus()->save();
         throw new Enterprise_Index_Model_Action_Exception($e->getMessage(), $e->getCode(), $e);
     }
     return $this;
 }
 /**
  * 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;
 }
Esempio n. 13
0
 /**
  * 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;
 }
 /**
  * Create view and mview table
  * 1) Create view;
  * 2) Create table;
  * 3) Update view name and status in metadata.
  *
  * @return Enterprise_Mview_Model_Action_Mview_Create
  * @throws Exception
  */
 public function execute()
 {
     try {
         if (!$this->_view->isExists()) {
             $this->_view->createFromSource($this->_select);
         }
         if (!$this->_table->isExists()) {
             $select = $this->_connection->select()->from($this->_view->getObjectName());
             $this->_table->createFromSource($select);
         }
         $this->_metadata->setViewName($this->_view->getObjectName());
         $this->_metadata->setValidStatus();
         $this->_metadata->save();
     } catch (Exception $e) {
         $this->_view->drop();
         $this->_table->drop();
         throw $e;
     }
     return $this;
 }
Esempio n. 16
0
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
Esempio n. 18
0
 /**
  * Drops changelog table
  * Updates changelog_name in the metadata.
  *
  * @return Enterprise_Mview_Model_Action_Changelog_Create
  */
 public function execute()
 {
     $this->_changelog->drop();
     $this->_metadata->setData('changelog_name', null)->save();
     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);
 }
 /**
  * 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);
 }