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