|
17 | 17 | use Joomla\CMS\MVC\Controller\BaseController; |
18 | 18 | use Joomla\CMS\Plugin\PluginHelper; |
19 | 19 | use Joomla\CMS\Session\Session; |
| 20 | +use Joomla\Component\Finder\Administrator\Indexer\Adapter; |
| 21 | +use Joomla\Component\Finder\Administrator\Indexer\DebugAdapter; |
| 22 | +use Joomla\Component\Finder\Administrator\Indexer\DebugIndexer; |
20 | 23 | use Joomla\Component\Finder\Administrator\Indexer\Indexer; |
21 | 24 | use Joomla\Component\Finder\Administrator\Response\Response; |
22 | 25 |
|
@@ -147,22 +150,6 @@ public function batch() |
147 | 150 | // Import the finder plugins. |
148 | 151 | PluginHelper::importPlugin('finder'); |
149 | 152 |
|
150 | | - /* |
151 | | - * We are going to swap out the raw document object with an HTML document |
152 | | - * in order to work around some plugins that don't do proper environment |
153 | | - * checks before trying to use HTML document functions. |
154 | | - */ |
155 | | - $lang = Factory::getLanguage(); |
156 | | - |
157 | | - // Get the document properties. |
158 | | - $attributes = [ |
159 | | - 'charset' => 'utf-8', |
160 | | - 'lineend' => 'unix', |
161 | | - 'tab' => ' ', |
162 | | - 'language' => $lang->getTag(), |
163 | | - 'direction' => $lang->isRtl() ? 'rtl' : 'ltr', |
164 | | - ]; |
165 | | - |
166 | 153 | // Start the indexer. |
167 | 154 | try { |
168 | 155 | // Trigger the onBeforeIndex event. |
@@ -281,4 +268,112 @@ public static function sendResponse($data = null) |
281 | 268 | // Send the JSON response. |
282 | 269 | echo json_encode($response); |
283 | 270 | } |
| 271 | + |
| 272 | + /** |
| 273 | + * Method to call a specific indexing plugin and return debug info |
| 274 | + * |
| 275 | + * @return void |
| 276 | + * |
| 277 | + * @since __DEPLOY_VERSION__ |
| 278 | + * @internal |
| 279 | + */ |
| 280 | + public function debug() |
| 281 | + { |
| 282 | + // Check for a valid token. If invalid, send a 403 with the error message. |
| 283 | + if (!Session::checkToken('request')) { |
| 284 | + static::sendResponse(new \Exception(Text::_('JINVALID_TOKEN_NOTICE'), 403)); |
| 285 | + |
| 286 | + return; |
| 287 | + } |
| 288 | + |
| 289 | + // We don't want this form to be cached. |
| 290 | + $this->app->allowCache(false); |
| 291 | + |
| 292 | + // Put in a buffer to silence noise. |
| 293 | + ob_start(); |
| 294 | + |
| 295 | + // Remove the script time limit. |
| 296 | + @set_time_limit(0); |
| 297 | + |
| 298 | + // Get the indexer state. |
| 299 | + Indexer::resetState(); |
| 300 | + $state = Indexer::getState(); |
| 301 | + |
| 302 | + // Reset the batch offset. |
| 303 | + $state->batchOffset = 0; |
| 304 | + |
| 305 | + // Update the indexer state. |
| 306 | + Indexer::setState($state); |
| 307 | + |
| 308 | + // Start the indexer. |
| 309 | + try { |
| 310 | + // Import the finder plugins. |
| 311 | + class_alias(DebugAdapter::class, Adapter::class); |
| 312 | + $plugin = Factory::getApplication()->bootPlugin($this->app->input->get('plugin'), 'finder'); |
| 313 | + $plugin->setIndexer(new DebugIndexer()); |
| 314 | + $plugin->debug($this->app->input->get('id')); |
| 315 | + |
| 316 | + $output = ''; |
| 317 | + |
| 318 | + // Create list of attributes |
| 319 | + $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_ATTRIBUTES') . '</legend>'; |
| 320 | + $output .= '<dl class="row">'; |
| 321 | + |
| 322 | + foreach (DebugIndexer::$item as $key => $value) { |
| 323 | + $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10">' . $value . '</dd>'; |
| 324 | + } |
| 325 | + |
| 326 | + $output .= '</dl>'; |
| 327 | + $output .= '</fieldset>'; |
| 328 | + |
| 329 | + $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_ELEMENTS') . '</legend>'; |
| 330 | + $output .= '<dl class="row">'; |
| 331 | + |
| 332 | + foreach (DebugIndexer::$item->getElements() as $key => $element) { |
| 333 | + $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10">' . $element . '</dd>'; |
| 334 | + } |
| 335 | + |
| 336 | + $output .= '</dl>'; |
| 337 | + $output .= '</fieldset>'; |
| 338 | + |
| 339 | + $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_INSTRUCTIONS') . '</legend>'; |
| 340 | + $output .= '<dl class="row">'; |
| 341 | + $contexts = [ |
| 342 | + 1 => 'Title context', |
| 343 | + 2 => 'Text context', |
| 344 | + 3 => 'Meta context', |
| 345 | + 4 => 'Path context', |
| 346 | + 5 => 'Misc context', |
| 347 | + ]; |
| 348 | + |
| 349 | + foreach (DebugIndexer::$item->getInstructions() as $key => $element) { |
| 350 | + $output .= '<dt class="col-sm-2">' . $contexts[$key] . '</dt><dd class="col-sm-10">' . json_encode($element) . '</dd>'; |
| 351 | + } |
| 352 | + |
| 353 | + $output .= '</dl>'; |
| 354 | + $output .= '</fieldset>'; |
| 355 | + |
| 356 | + $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_TAXONOMIES') . '</legend>'; |
| 357 | + $output .= '<dl class="row">'; |
| 358 | + |
| 359 | + foreach (DebugIndexer::$item->getTaxonomy() as $key => $element) { |
| 360 | + $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10">' . json_encode($element) . '</dd>'; |
| 361 | + } |
| 362 | + |
| 363 | + $output .= '</dl>'; |
| 364 | + $output .= '</fieldset>'; |
| 365 | + |
| 366 | + // Get the indexer state. |
| 367 | + $state = Indexer::getState(); |
| 368 | + $state->start = 0; |
| 369 | + $state->complete = 0; |
| 370 | + $state->rendered = $output; |
| 371 | + |
| 372 | + echo json_encode($state); |
| 373 | + } catch (\Exception $e) { |
| 374 | + // Catch an exception and return the response. |
| 375 | + // Send the response. |
| 376 | + static::sendResponse($e); |
| 377 | + } |
| 378 | + } |
284 | 379 | } |
0 commit comments