Skip to content

Commit 7476510

Browse files
HackwarbrianteemanPhil E. Taylorrichard67Quy
authored
[5.0] Smart Search: Add debugging features (#36753)
* Finder: Add debug features for indexing * Reverting accidental deletion * Update administrator/components/com_finder/forms/indexer.xml Co-authored-by: Brian Teeman <[email protected]> * Codestyle * Update administrator/components/com_finder/src/Indexer/Debugadapter.php Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/Indexer/Debugadapter.php Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/Indexer/Debugadapter.php Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/Model/ItemModel.php Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/View/Indexer/HtmlView.php Co-authored-by: Phil E. Taylor <[email protected]> * Update build/media_source/com_finder/js/debug.es6.js Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/View/Indexer/HtmlView.php Co-authored-by: Phil E. Taylor <[email protected]> * Update administrator/components/com_finder/src/Model/IndexerModel.php Co-authored-by: Phil E. Taylor <[email protected]> * Adding accessibility tags to tables * Fixing HTML of item debug output to be more accessible * Adding captions to tables * Fixing width of object dump * Fix the toolbar * Using prepared statements * Update administrator/components/com_finder/src/Model/ItemModel.php Co-authored-by: Quy <[email protected]> * Update administrator/components/com_finder/src/Model/ItemModel.php Co-authored-by: Quy <[email protected]> * Update administrator/components/com_finder/src/Model/ItemModel.php Co-authored-by: Quy <[email protected]> * Update administrator/components/com_finder/src/Model/ItemModel.php Co-authored-by: Quy <[email protected]> * Injecting database object * Using injected database object * Use injected database object * Phase 1 convert BRANCH to PSR-12 * Phase 2 convert BRANCH to PSR-12 * Improving for autoloading * Codestyle * Update administrator/components/com_finder/src/Indexer/DebugIndexer.php Co-authored-by: Harald Leithner <[email protected]> * Update administrator/components/com_finder/src/Indexer/DebugAdapter.php Co-authored-by: Harald Leithner <[email protected]> * Update administrator/components/com_finder/src/Controller/IndexerController.php Co-authored-by: Harald Leithner <[email protected]> --------- Co-authored-by: Brian Teeman <[email protected]> Co-authored-by: Phil E. Taylor <[email protected]> Co-authored-by: Richard Fath <[email protected]> Co-authored-by: Quy <[email protected]> Co-authored-by: Harald Leithner <[email protected]>
1 parent e2170c8 commit 7476510

File tree

15 files changed

+1682
-27
lines changed

15 files changed

+1682
-27
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<form>
3+
<fieldset name="form">
4+
<field
5+
name="plugin"
6+
type="plugins"
7+
label="COM_FINDER_FIELD_FINDER_PLUGIN_LABEL"
8+
folder="finder"
9+
required="true"
10+
/>
11+
12+
<field
13+
name="id"
14+
type="text"
15+
label="JGLOBAL_FIELD_ID_LABEL"
16+
required="true"
17+
/>
18+
</fieldset>
19+
</form>

administrator/components/com_finder/src/Controller/IndexerController.php

Lines changed: 111 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Joomla\CMS\MVC\Controller\BaseController;
1818
use Joomla\CMS\Plugin\PluginHelper;
1919
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;
2023
use Joomla\Component\Finder\Administrator\Indexer\Indexer;
2124
use Joomla\Component\Finder\Administrator\Response\Response;
2225

@@ -147,22 +150,6 @@ public function batch()
147150
// Import the finder plugins.
148151
PluginHelper::importPlugin('finder');
149152

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-
166153
// Start the indexer.
167154
try {
168155
// Trigger the onBeforeIndex event.
@@ -281,4 +268,112 @@ public static function sendResponse($data = null)
281268
// Send the JSON response.
282269
echo json_encode($response);
283270
}
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+
}
284379
}

0 commit comments

Comments
 (0)