예제 #1
0
 public function actionFulltext()
 {
     // get dirty
     $this->template->num_docs = fulltext::index()->numDocs();
     $this->template->dirty = fulltext::dirty();
     $this->template->num_dirty = count($this->template->dirty);
     // index
     $index = fulltext::index();
     $this->template->update_now = array_slice($this->template->dirty, 0, 50);
     if (!empty($this->template->update_now)) {
         adminlog::log(__('Attempt to update fulltext'));
     }
     foreach (mapper::products()->findByIds($this->template->update_now) as $product) {
         // delete old
         foreach ($index->termDocs(new Zend_Search_Lucene_Index_Term($product->getId(), 'id')) as $id) {
             $index->delete($id);
         }
         // add
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $product->getId()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('name', $product->getName()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('nice_name', $product->getNiceName()));
         $doc->addField(Zend_Search_Lucene_Field::Unstored('code', $product->getCode()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('meta_keywords', $product->getMetaKeywords()));
         $doc->addField(Zend_Search_Lucene_Field::UnStored('meta_description', $product->getMetaDescription()));
         $description = '';
         if (strlen($product->getDescription()) < 1) {
             if (strlen($product->getMetaDescription()) < 1) {
                 $description = $product->getName();
             } else {
                 $description = $product->getMetaDescription();
             }
         } else {
             $description = $product->getDescription();
         }
         if ($manufacturer = mapper::products()->findManufacturerOf($product->getId())) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored('manufacturer', $manufacturer->getName()));
             $description .= ' ' . $manufacturer->getName();
             $description .= ' ' . $manufacturer->getDescription();
         }
         if ($category = mapper::products()->findCategoryOf($product->getId())) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored('category', $category->getName()));
             $description .= ' ' . $category->getName();
             $description .= ' ' . $category->getDescription();
         }
         $description .= ' ' . $product->getName();
         $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $description));
         $index->addDocument($doc);
     }
     // undirty updated
     foreach ($this->template->update_now as $id) {
         fulltext::dirty($id, FALSE);
     }
     // log
     adminlog::log(__('Successfully updated %d fulltext items, %d remains'), count($this->template->update_now), $this->template->num_dirty - count($this->template->update_now));
     // refresh
     $s = 5;
     Environment::getHttpResponse()->setHeader('Refresh', $s . '; ' . (string) Environment::getHttpRequest()->getOriginalUri());
     $this->template->next_update = $s;
 }
예제 #2
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;
     }
 }