示例#1
0
 public function startup()
 {
     adminlog::init(ADMINLOG_DIR);
     if (!Environment::getUser()->isAuthenticated()) {
         $this->redirect('Login:default');
         $this->terminate();
         return;
     }
     fulltext::init(FULLTEXT_DIR);
 }
示例#2
0
 /**
  * Init fulltext
  * @param string fulltext directory
  */
 public static function init($dir)
 {
     static $done = FALSE;
     if (!$done) {
         self::$dir = rtrim($dir, DIRECTORY_SEPARATOR);
         $index_dir = self::$dir . DIRECTORY_SEPARATOR . 'index';
         if (!is_dir($index_dir)) {
             self::$index = Zend_Search_Lucene::create($index_dir);
         } else {
             self::$index = Zend_Search_Lucene::open($index_dir);
         }
         if (!file_exists(self::$dir . DIRECTORY_SEPARATOR . self::DIRTY_BITMAP_FILENAME)) {
             if (!@touch(self::$dir . DIRECTORY_SEPARATOR . self::DIRTY_BITMAP_FILENAME)) {
                 return FALSE;
             }
         }
         $done = TRUE;
     }
 }
 public function renderDefault($q, $page = 1)
 {
     try {
         $ids = array();
         foreach (fulltext::index()->find($q) as $hit) {
             $ids[] = $hit->getDocument()->id;
         }
         $this->template->paginator = new Paginator();
         $this->template->paginator->setItemCount(count($ids));
         $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
         $this->template->paginator->setPage($page);
         $this->template->products = mapper::products()->findByIds(array_slice($ids, $this->template->paginator->getOffset(), $this->template->paginator->getLength()));
         $this->template->title = __('Search results for ``%s"', $q);
         $this->template->q = $q;
         Environment::getSession(SESSION_SEARCH_NS)->last = $q;
         searchlog::log($q);
     } catch (Exception $e) {
         $this->template->products = array();
     }
 }
 public function actionOptimizeFulltext()
 {
     adminlog::log(__('Attempt to optimize fulltext'));
     // optimize
     fulltext::index()->optimize();
     adminlog::log(__('Sucessfully optimized fulltext'));
     $this->redirect('fulltext');
     $this->terminate();
 }
示例#5
0
 /**
  * Update
  */
 public function updateOne(array $values)
 {
     try {
         dibi::begin();
         $product = array();
         $product['price'] = intval($values['price']);
         if (isset($values['manufacturer_id'])) {
             $product['manufacturer_id'] = $values['manufacturer_id'] == 0 ? NULL : intval($values['manufacturer_id']);
         }
         if (isset($values['category_id'])) {
             $product['category_id'] = $values['category_id'] == 0 ? NULL : intval($values['category_id']);
         }
         $product_id = intval($values['id']);
         if (isset($values['availability_id'])) {
             $product['availability_id'] = $values['availability_id'] == 0 ? NULL : intval($values['availability_id']);
         }
         if (isset($values['code'])) {
             $product['code'] = empty($values['code']) ? NULL : $values['code'];
         }
         unset($values['price'], $values['manufacturer_id'], $values['category_id'], $values['availability_id'], $values['id'], $values['code']);
         dibi::query('UPDATE [:prefix:products] SET', $product, 'WHERE [id] = %i', $product_id);
         $change = array('product_id' => $product_id, 'price' => $product['price'], 'changed_at' => new DibiVariable('NOW()', 'sql'));
         dibi::query('INSERT INTO [:prefix:price_changes]', $change);
         if (isset($values['picture_id'])) {
             $values['picture_id'] = $values['picture_id'] == 0 ? NULL : intval($values['picture_id']);
         }
         if (isset($values['meta_keywords']) && empty($values['meta_keywords'])) {
             $values['meta_keywords'] = NULL;
         }
         if (isset($values['meta_description']) && empty($values['meta_description'])) {
             $values['meta_description'] = NULL;
         }
         if (isset($values['content']) && empty($values['content'])) {
             $values['content'] = NULL;
         }
         if (!empty($values)) {
             $where = array();
             $where['ref_id'] = $product_id;
             $where['ref_type'] = pages::PRODUCT;
             dibi::query('UPDATE [:prefix:pages] SET', $values, 'WHERE %and', $where);
         }
         dibi::commit();
         //<fulltext>
         fulltext::dirty($product_id, TRUE);
         //</fulltext>
         return TRUE;
     } catch (Exception $e) {
         dibi::rollback();
         return FALSE;
     }
 }