Inheritance: extends Mage_Core_Helper_Abstract
Esempio n. 1
0
 public function run($limit)
 {
     $full_reindex = $limit === -1;
     $limit = $full_reindex ? 1 : $limit;
     $element_count = 0;
     $jobs = array();
     $offset = 0;
     $max_size = $this->config->getNumberOfElementByPage() * $limit;
     while ($element_count < $max_size) {
         $data = $this->db->query($this->db->select()->from($this->table, '*')->where('pid IS NULL')->order(array('job_id'))->limit($limit, $limit * $offset));
         $data = $data->fetchAll();
         $offset++;
         if (count($data) <= 0) {
             break;
         }
         foreach ($data as $job) {
             $job_size = (int) $job['data_size'];
             if ($element_count + $job_size <= $max_size) {
                 $jobs[] = $job;
                 $element_count += $job_size;
             } else {
                 break 2;
             }
         }
     }
     if (count($jobs) <= 0) {
         return;
     }
     $first_id = $jobs[0]['job_id'];
     $last_id = $jobs[count($jobs) - 1]['job_id'];
     $pid = getmypid();
     // Reserve all new jobs since last run
     $this->db->query("UPDATE {$this->db->quoteIdentifier($this->table, true)} SET pid = " . $pid . ' WHERE job_id >= ' . $first_id . " AND job_id <= {$last_id}");
     foreach ($jobs as &$job) {
         $job['data'] = json_decode($job['data'], true);
     }
     $jobs = $this->sortAndMergeJob($jobs);
     // Run all reserved jobs
     foreach ($jobs as $job) {
         try {
             $model = Mage::getSingleton($job['class']);
             $method = $job['method'];
             $model->{$method}(new Varien_Object($job['data']));
         } catch (Exception $e) {
             // Increment retries and log error information
             $this->logger->log("Queue processing {$job['pid']} [KO]: Mage::getSingleton({$job['class']})->{$job['method']}(" . json_encode($job['data']) . ')');
             $this->logger->log(date('c') . ' ERROR: ' . get_class($e) . ": '{$e->getMessage()}' in {$e->getFile()}:{$e->getLine()}\n" . "Stack trace:\n" . $e->getTraceAsString());
         }
     }
     // Delete only when finished to be able to debug the queue if needed
     $where = $this->db->quoteInto('pid = ?', $pid);
     $this->db->delete($this->table, $where);
     if ($full_reindex) {
         $this->run(-1);
     }
 }
Esempio n. 2
0
 public function stopEmulation($info)
 {
     $this->logger->start('STOP EMULATION');
     $appEmulation = Mage::getSingleton('core/app_emulation');
     Mage::app()->setCurrentStore($info->getInitialStoreId());
     Mage::app()->getStore($info->getEmulatedStoreId())->setConfig(Mage_Catalog_Helper_Product_Flat::XML_PATH_USE_PRODUCT_FLAT, $info->getUseProductFlat());
     Mage::app()->getStore($info->getEmulatedStoreId())->setConfig(Mage_Catalog_Helper_Category_Flat::XML_PATH_IS_ENABLED_FLAT_CATALOG_CATEGORY, $info->getUseCategoryFlat());
     $appEmulation->stopEnvironmentEmulation($info);
     $this->logger->stop('STOP EMULATION');
 }
Esempio n. 3
0
 /**
  * Rebuild all index data
  */
 public function reindexAll()
 {
     if (!$this->config->getApplicationID() || !$this->config->getAPIKey() || !$this->config->getSearchOnlyAPIKey()) {
         Mage::getSingleton('adminhtml/session')->addError('Algolia reindexing failed: You need to configure your Algolia credentials in System > Configuration > Algolia Search.');
         $this->logger->log('ERROR Credentials not configured correctly');
         return;
     }
     $this->logger->start('PRODUCTS FULL REINDEX');
     $this->engine->rebuildProducts();
     $this->logger->stop('PRODUCTS FULL REINDEX');
     return $this;
 }
Esempio n. 4
0
 public function rebuildCategories()
 {
     foreach (Mage::app()->getStores() as $store) {
         if ($this->config->isEnabledBackEnd($store->getId()) === false) {
             $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()));
             continue;
         }
         if ($store->getIsActive()) {
             $this->addToQueue('algoliasearch/observer', 'rebuildCategoryIndex', array('store_id' => $store->getId(), 'category_ids' => array()), $this->config->getQueueMaxRetries());
         } else {
             $this->addToQueue('algoliasearch/observer', 'deleteCategoriesStoreIndices', array('store_id' => $store->getId()), $this->config->getQueueMaxRetries());
         }
     }
 }
Esempio n. 5
0
 public function rebuildCategories()
 {
     foreach (Mage::app()->getStores() as $store) {
         if ($this->config->isEnabledBackEnd($store->getId()) === false) {
             if (php_sapi_name() === 'cli') {
                 echo '[ALGOLIA] INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()) . "\n";
             }
             Mage::getSingleton('adminhtml/session')->addWarning('[ALGOLIA] INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()));
             $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()));
             continue;
         }
         if ($store->getIsActive()) {
             $this->addToQueue('algoliasearch/observer', 'rebuildCategoryIndex', array('store_id' => $store->getId(), 'category_ids' => array()), 1);
         } else {
             $this->addToQueue('algoliasearch/observer', 'deleteCategoriesStoreIndices', array('store_id' => $store->getId()), 1);
         }
     }
 }