/** * Method to optimize the index and perform any necessary cleanup. * * @return void * * @since 2.5 */ public function optimize() { // We don't want this form to be cached. header('Pragma: no-cache'); header('Cache-Control: no-cache'); header('Expires: -1'); // Check for a valid token. If invalid, send a 403 with the error message. JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403)); // Put in a buffer to silence noise. ob_start(); // Import the finder plugins. JPluginHelper::importPlugin('finder'); try { // Optimize the index FinderIndexer::getInstance()->optimize(); // Get the indexer state. $state = FinderIndexer::getState(); $state->start = 0; $state->complete = 1; // Send the response. $this->sendResponse($state); } catch (Exception $e) { $this->sendResponse($e); } }
/** * Tests the getInstance method * * @return void * * @since 3.0 * @expectedException RuntimeException */ public function testGetInstanceException() { JFactory::$database->name = 'nosql'; FinderIndexer::getInstance(); }
protected function index(FinderIndexerResult $item, $format = 'html') { // Check if the extension is enabled if (JComponentHelper::isEnabled($this->extension) == false) { return; } // Initialize the item parameters. $registry = new JRegistry(); $registry->loadString($item->params); $item->params = JComponentHelper::getParams('com_k2', true); $item->params->merge($registry); $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry; // Trigger the onContentPrepare event. $item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params); $item->body = FinderIndexerHelper::prepareContent($item->body, $item->params); // Build the necessary route and path information. $item->url = $this->getURL($item->id, $this->extension, $this->layout); $item->route = K2HelperRoute::getItemRoute($item->slug, $item->catslug); $item->path = FinderIndexerHelper::getContentPath($item->route); // Get the menu title if it exists. $title = $this->getItemMenuTitle($item->url); // Adjust the title if necessary. if (!empty($title) && $this->params->get('use_menu_title', true)) { $item->title = $title; } // Add the meta-author. $item->metaauthor = $item->metadata->get('author'); // Add the meta-data processing instructions. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias'); // Translate the state. Articles should only be published if the category is published. $item->state = $this->translateState($item->state, $item->cat_state); // Translate the trash state. Articles should only be accesible if the category is accessible. if ($item->trash || $item->cat_trash) { $item->state = 0; } // Add the type taxonomy data. $item->addTaxonomy('Type', 'K2 Item'); // Add the author taxonomy data. if (!empty($item->author) || !empty($item->created_by_alias)) { $item->addTaxonomy('Author', !empty($item->created_by_alias) ? $item->created_by_alias : $item->author); } // Add the category taxonomy data. $item->addTaxonomy('K2 Category', $item->category, $item->cat_state, $item->cat_access); // Add the language taxonomy data. $item->addTaxonomy('Language', $item->language); // Get content extras. FinderIndexerHelper::getContentExtras($item); // Index the item. if (method_exists('FinderIndexer', 'getInstance')) { FinderIndexer::getInstance()->index($item); } else { FinderIndexer::index($item); } }
/** * Method to instantiate the indexer adapter. * * @param object &$subject The object to observe. * @param array $config An array that holds the plugin configuration. * * @since 2.5 */ public function __construct(&$subject, $config) { // Get the database object. $this->db = JFactory::getDbo(); // Call the parent constructor. parent::__construct($subject, $config); // Get the type id. $this->type_id = $this->getTypeId(); // Add the content type if it doesn't exist and is set. if (empty($this->type_id) && !empty($this->type_title)) { $this->type_id = FinderIndexerHelper::addContentType($this->type_title, $this->mime); } // Check for a layout override. if ($this->params->get('layout')) { $this->layout = $this->params->get('layout'); } // Get the indexer object $this->indexer = FinderIndexer::getInstance(); }
/** * Tests the getInstance method * * @return void * * @since 3.0 */ public function testGetInstanceException() { // Override the database in this method $this->saveFactoryDatabase(); JFactory::$database->name = 'nosql'; $this->setExpectedException('RuntimeException'); FinderIndexer::getInstance(); // Restore the database $this->restoreFactoryDatabase(); }
/** * Method to optimize the index and perform any necessary cleanup. * * @return void * * @since 2.5 */ public function optimize() { // We don't want this form to be cached. $app = JFactory::getApplication(); $app->setHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true); $app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true); $app->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false); $app->setHeader('Pragma', 'no-cache'); // Check for a valid token. If invalid, send a 403 with the error message. JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403)); // Put in a buffer to silence noise. ob_start(); // Import the finder plugins. JPluginHelper::importPlugin('finder'); try { // Optimize the index FinderIndexer::getInstance()->optimize(); // Get the indexer state. $state = FinderIndexer::getState(); $state->start = 0; $state->complete = 1; // Send the response. $this->sendResponse($state); } catch (Exception $e) { $this->sendResponse($e); } }
/** * Main index function run when indexing happens * * @param FinderIndexerResult $item * @return bool|void */ protected function index(FinderIndexerResult $item) { // Check if the extension is enabled if (JComponentHelper::isEnabled($this->extension) == false) { return; } //Add the instructions foreach ($this->instructions as $type => $instructions) { foreach ($instructions as $instruction) { $item->addInstruction($type, $instruction); } } // Add the type taxonomy data. $item->addTaxonomy('Type', $this->type_title); FinderIndexerHelper::getContentExtras($item); // Index the item. if (method_exists('FinderIndexer', 'getInstance')) { FinderIndexer::getInstance()->index($item); } else { FinderIndexer::index($item); } }