[ Index ]

PHP Cross Reference of Joomla 3.3.0

title

Body

[close]

/cli/ -> finder_indexer.php (source)

   1  <?php
   2  /**
   3   * @package    Joomla.Cli
   4   *
   5   * @copyright  Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  /**
  10   * Finder CLI Bootstrap
  11   *
  12   * Run the framework bootstrap with a couple of mods based on the script's needs
  13   */
  14  
  15  // We are a valid entry point.
  16  const _JEXEC = 1;
  17  
  18  // Load system defines
  19  if (file_exists(dirname(__DIR__) . '/defines.php'))
  20  {
  21      require_once dirname(__DIR__) . '/defines.php';
  22  }
  23  
  24  if (!defined('_JDEFINES'))
  25  {
  26      define('JPATH_BASE', dirname(__DIR__));
  27      require_once  JPATH_BASE . '/includes/defines.php';
  28  }
  29  
  30  // Get the framework.
  31  require_once JPATH_LIBRARIES . '/import.legacy.php';
  32  
  33  // Bootstrap the CMS libraries.
  34  require_once JPATH_LIBRARIES . '/cms.php';
  35  
  36  // Import the configuration.
  37  require_once JPATH_CONFIGURATION . '/configuration.php';
  38  
  39  // System configuration.
  40  $config = new JConfig;
  41  
  42  // Configure error reporting to maximum for CLI output.
  43  error_reporting(E_ALL);
  44  ini_set('display_errors', 1);
  45  
  46  // Load Library language
  47  $lang = JFactory::getLanguage();
  48  
  49  // Try the finder_cli file in the current language (without allowing the loading of the file in the default language)
  50  $lang->load('finder_cli', JPATH_SITE, null, false, false)
  51  // Fallback to the finder_cli file in the default language
  52  || $lang->load('finder_cli', JPATH_SITE, null, true);
  53  
  54  /**
  55   * A command line cron job to run the Finder indexer.
  56   *
  57   * @package  Joomla.Cli
  58   *
  59   * @since    2.5
  60   */
  61  class FinderCli extends JApplicationCli
  62  {
  63      /**
  64       * Start time for the index process
  65       *
  66       * @var    string
  67       * @since  2.5
  68       */
  69      private $_time = null;
  70  
  71      /**
  72       * Start time for each batch
  73       *
  74       * @var    string
  75       * @since  2.5
  76       */
  77      private $_qtime = null;
  78  
  79      /**
  80       * Entry point for Finder CLI script
  81       *
  82       * @return  void
  83       *
  84       * @since   2.5
  85       */
  86  	public function doExecute()
  87      {
  88          // Print a blank line.
  89          $this->out(JText::_('FINDER_CLI'));
  90          $this->out('============================');
  91          $this->out();
  92  
  93          $this->_index();
  94  
  95          // Print a blank line at the end.
  96          $this->out();
  97      }
  98  
  99      /**
 100       * Run the indexer
 101       *
 102       * @return  void
 103       *
 104       * @since   2.5
 105       */
 106  	private function _index()
 107      {
 108          $this->_time = microtime(true);
 109  
 110          require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
 111  
 112          // Fool the system into thinking we are running as JSite with Finder as the active component
 113          JFactory::getApplication('site');
 114          $_SERVER['HTTP_HOST'] = 'domain.com';
 115          define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_finder');
 116  
 117          // Disable caching.
 118          $config = JFactory::getConfig();
 119          $config->set('caching', 0);
 120          $config->set('cache_handler', 'file');
 121  
 122          // Reset the indexer state.
 123          FinderIndexer::resetState();
 124  
 125          // Import the finder plugins.
 126          JPluginHelper::importPlugin('finder');
 127  
 128          // Starting Indexer.
 129          $this->out(JText::_('FINDER_CLI_STARTING_INDEXER'), true);
 130  
 131          // Trigger the onStartIndex event.
 132          JEventDispatcher::getInstance()->trigger('onStartIndex');
 133  
 134          // Remove the script time limit.
 135          @set_time_limit(0);
 136  
 137          // Get the indexer state.
 138          $state = FinderIndexer::getState();
 139  
 140          // Setting up plugins.
 141          $this->out(JText::_('FINDER_CLI_SETTING_UP_PLUGINS'), true);
 142  
 143          // Trigger the onBeforeIndex event.
 144          JEventDispatcher::getInstance()->trigger('onBeforeIndex');
 145  
 146          // Startup reporting.
 147          $this->out(JText::sprintf('FINDER_CLI_SETUP_ITEMS', $state->totalItems, round(microtime(true) - $this->_time, 3)), true);
 148  
 149          // Get the number of batches.
 150          $t = (int) $state->totalItems;
 151          $c = (int) ceil($t / $state->batchSize);
 152          $c = $c === 0 ? 1 : $c;
 153  
 154          try
 155          {
 156              // Process the batches.
 157              for ($i = 0; $i < $c; $i++)
 158              {
 159                  // Set the batch start time.
 160                  $this->_qtime = microtime(true);
 161  
 162                  // Reset the batch offset.
 163                  $state->batchOffset = 0;
 164  
 165                  // Trigger the onBuildIndex event.
 166                  JEventDispatcher::getInstance()->trigger('onBuildIndex');
 167  
 168                  // Batch reporting.
 169                  $this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', ($i + 1), round(microtime(true) - $this->_qtime, 3)), true);
 170              }
 171          }
 172          catch (Exception $e)
 173          {
 174              // Display the error
 175              $this->out($e->getMessage(), true);
 176  
 177              // Reset the indexer state.
 178              FinderIndexer::resetState();
 179  
 180              // Close the app
 181              $this->close($e->getCode());
 182          }
 183  
 184          // Total reporting.
 185          $this->out(JText::sprintf('FINDER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->_time, 3)), true);
 186  
 187          // Reset the indexer state.
 188          FinderIndexer::resetState();
 189      }
 190  }
 191  
 192  // Instantiate the application object, passing the class name to JCli::getInstance
 193  // and use chaining to execute the application.
 194  JApplicationCli::getInstance('FinderCli')->execute();


Generated: Fri May 2 13:54:24 2014 Cross-referenced by PHPXref 0.7.1