Backend\Modules\Search\Engine\Model::removeIndex PHP Method

removeIndex() public static method

Remove an index
public static removeIndex ( string $module, integer $otherId, string $language = null )
$module string The module wherein will be searched.
$otherId integer The id of the record.
$language string The language to use.
    public static function removeIndex($module, $otherId, $language = null)
    {
        // module exists?
        if (!in_array('Search', BackendModel::getModules())) {
            return;
        }
        // set language
        if (!$language) {
            $language = BL::getWorkingLanguage();
        }
        // delete indexes
        BackendModel::getContainer()->get('database')->delete('search_index', 'module = ? AND other_id = ? AND language = ?', array((string) $module, (int) $otherId, (string) $language));
        // invalidate the cache for search
        self::invalidateCache();
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // set category id
         $this->categoryId = \SpoonFilter::getGetValue('category', null, null, 'int');
         if ($this->categoryId == 0) {
             $this->categoryId = null;
         }
         // get data
         $this->record = (array) BackendBlogModel::get($this->id);
         // delete item
         BackendBlogModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // delete search indexes
         BackendSearchModel::removeIndex($this->getModule(), $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']);
         // append to redirect URL
         if ($this->categoryId != null) {
             $redirectUrl .= '&category=' . $this->categoryId;
         }
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Search\Engine\Model::removeIndex