load('finder_cli', JPATH_SITE, null, false, false) // Fallback to the finder_cli file in the default language || $lang->load('finder_cli', JPATH_SITE, null, true); /** * A command line cron job to run the Finder indexer. * * @package Joomla.CLI * @subpackage com_finder * @since 2.5 */ class FinderCli extends JApplicationCli { /** * Start time for the index process * * @var string * @since 2.5 */ private $_time = null; /** * Start time for each batch * * @var string * @since 2.5 */ private $_qtime = null; /** * Entry point for Finder CLI script * * @return void * * @since 2.5 */ public function doExecute() { // Print a blank line. $this->out(JText::_('FINDER_CLI')); $this->out('============================'); $this->out(); $this->_index(); // Print a blank line at the end. $this->out(); } /** * Run the indexer * * @return void * * @since 2.5 */ private function _index() { $this->_time = microtime(true); require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php'; // Fool the system into thinking we are running as JSite with Finder as the active component JFactory::getApplication('site'); $_SERVER['HTTP_HOST'] = 'domain.com'; define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_finder'); // Disable caching. $config = JFactory::getConfig(); $config->set('caching', 0); $config->set('cache_handler', 'file'); // Reset the indexer state. FinderIndexer::resetState(); // Import the finder plugins. JPluginHelper::importPlugin('finder'); // Starting Indexer. $this->out(JText::_('FINDER_CLI_STARTING_INDEXER'), true); // Trigger the onStartIndex event. JEventDispatcher::getInstance()->trigger('onStartIndex'); // Remove the script time limit. @set_time_limit(0); // Get the indexer state. $state = FinderIndexer::getState(); // Setting up plugins. $this->out(JText::_('FINDER_CLI_SETTING_UP_PLUGINS'), true); // Trigger the onBeforeIndex event. JEventDispatcher::getInstance()->trigger('onBeforeIndex'); // Startup reporting. $this->out(JText::sprintf('FINDER_CLI_SETUP_ITEMS', $state->totalItems, round(microtime(true) - $this->_time, 3)), true); // Get the number of batches. $t = (int) $state->totalItems; $c = (int) ceil($t / $state->batchSize); $c = $c === 0 ? 1 : $c; try { // Process the batches. for ($i = 0; $i < $c; $i++) { // Set the batch start time. $this->_qtime = microtime(true); // Reset the batch offset. $state->batchOffset = 0; // Trigger the onBuildIndex event. JEventDispatcher::getInstance()->trigger('onBuildIndex'); // Batch reporting. $this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', ($i + 1), round(microtime(true) - $this->_qtime, 3)), true); } } catch (Exception $e) { // Display the error $this->out($e->getMessage(), true); // Reset the indexer state. FinderIndexer::resetState(); // Close the app $this->close($e->getCode()); } // Total reporting. $this->out(JText::sprintf('FINDER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->_time, 3)), true); // Reset the indexer state. FinderIndexer::resetState(); } } // Instantiate the application object, passing the class name to JCli::getInstance // and use chaining to execute the application. JApplicationCli::getInstance('FinderCli')->execute();