예제 #1
0
 /**
  * Method to start the indexer.
  *
  * @return  void
  *
  * @since   2.5
  */
 public function start()
 {
     static $log;
     $params = JComponentHelper::getParams('com_finder');
     if ($params->get('enable_logging', '0')) {
         if ($log == null) {
             $options['format'] = '{DATE}\\t{TIME}\\t{LEVEL}\\t{CODE}\\t{MESSAGE}';
             $options['text_file'] = 'indexer.php';
             $log = JLog::addLogger($options);
         }
     }
     // Log the start
     JLog::add('Starting the indexer', JLog::INFO);
     // 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();
     // Reset the indexer state.
     FinderIndexer::resetState();
     // Import the finder plugins.
     JPluginHelper::importPlugin('finder');
     // Add the indexer language to JS
     JText::script('COM_FINDER_AN_ERROR_HAS_OCCURRED');
     JText::script('COM_FINDER_NO_ERROR_RETURNED');
     // Start the indexer.
     try {
         // Trigger the onStartIndex event.
         JEventDispatcher::getInstance()->trigger('onStartIndex');
         // Get the indexer state.
         $state = FinderIndexer::getState();
         $state->start = 1;
         // Send the response.
         $this->sendResponse($state);
     } catch (Exception $e) {
         $this->sendResponse($e);
     }
 }
예제 #2
0
 /**
  * Method to start the indexer.
  *
  * @return  void
  *
  * @since   2.5
  */
 public function start()
 {
     $params = JComponentHelper::getParams('com_finder');
     if ($params->get('enable_logging', '0')) {
         $options['format'] = '{DATE}\\t{TIME}\\t{LEVEL}\\t{CODE}\\t{MESSAGE}';
         $options['text_file'] = 'indexer.php';
         JLog::addLogger($options);
     }
     // Log the start
     JLog::add('Starting the indexer', JLog::INFO);
     // 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();
     // Reset the indexer state.
     FinderIndexer::resetState();
     // Import the finder plugins.
     JPluginHelper::importPlugin('finder');
     // Add the indexer language to JS
     JText::script('COM_FINDER_AN_ERROR_HAS_OCCURRED');
     JText::script('COM_FINDER_NO_ERROR_RETURNED');
     // Start the indexer.
     try {
         // Trigger the onStartIndex event.
         JFactory::getApplication()->triggerEvent('onStartIndex');
         // Get the indexer state.
         $state = FinderIndexer::getState();
         $state->start = 1;
         // Send the response.
         $this->sendResponse($state);
     } catch (Exception $e) {
         $this->sendResponse($e);
     }
 }
예제 #3
0
 /**
  * Tests the resetState method
  *
  * @return  void
  *
  * @since   3.0
  */
 public function testResetState()
 {
     // Reset the state
     FinderIndexer::resetState();
     // Test we get a null object
     $this->assertNull(JFactory::getSession()->get('_finder.state', null));
 }
예제 #4
0
 public function createIndexes(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(\JText::_('FINDER_CLI_INDEX_PURGE'));
     require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
     // Initialize the time value.
     $this->time = microtime(true);
     // Remove the script time limit.
     @set_time_limit(0);
     $_SERVER['HTTP_HOST'] = 'domain.com';
     // 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.
     $output->writeln(\JText::_('FINDER_CLI_STARTING_INDEXER'));
     // 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.
     $output->writeln(\JText::_('FINDER_CLI_SETTING_UP_PLUGINS'));
     // Trigger the onBeforeIndex event.
     \JEventDispatcher::getInstance()->trigger('onBeforeIndex');
     // Startup reporting.
     $output->writeln(\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.
             $output->writeln("<info>" . \JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->qtime, 3)) . "</info>");
         }
     } catch (Exception $e) {
         // Reset the indexer state.
         \FinderIndexer::resetState();
         throw new \RuntimeException($e->getMessage());
     }
     // Reset the indexer state.
     \FinderIndexer::resetState();
 }
예제 #5
0
파일: run.php 프로젝트: raeldc/joomla-cms
 /**
  * Run the indexer
  *
  * @return  void
  *
  * @since   2.5
  */
 private function _index()
 {
     // initialize the time value
     $this->_time = microtime(true);
     // import library dependencies
     require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
     jimport('joomla.application.component.helper');
     // 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.
     JDispatcher::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.
     JDispatcher::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;
     // 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.
         JDispatcher::getInstance()->trigger('onBuildIndex');
         // Batch reporting.
         $this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->_qtime, 3)), true);
     }
     // Total reporting.
     $this->out(JText::sprintf('FINDER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->_time, 3)), true);
     // Reset the indexer state.
     FinderIndexer::resetState();
 }
예제 #6
0
 /**
  * Run the indexer.
  *
  * @return  void
  *
  * @since   2.5
  */
 private function index()
 {
     require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
     // 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.
     JFactory::getApplication()->triggerEvent('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.
     JFactory::getApplication()->triggerEvent('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.
             JFactory::getApplication()->triggerEvent('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());
     }
     // Reset the indexer state.
     FinderIndexer::resetState();
 }
 /**
  * Tests the resetState method
  *
  * @return  void
  *
  * @since   3.0
  */
 public function testResetState()
 {
     // Override the database in this method
     $this->saveFactoryDatabase();
     // Reset the state
     FinderIndexer::resetState();
     // Test we get a null object
     $this->assertThat(JFactory::getSession()->get('_finder.state', null), $this->isNull());
     // Restore the database
     $this->restoreFactoryDatabase();
 }