Skip to content

Commit

Permalink
[TASK] Add check if MySQL indexes are enabled
Browse files Browse the repository at this point in the history
Show an error in the backend module if
MySQL indexes are disabled together with
note why this can happen and what to do.
  • Loading branch information
christianbltr committed Jun 14, 2024
1 parent 06ac0a8 commit 57b638e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ChangeLog

Upcoming version
[BUGFIX] Use correct table names for query builder or connection. Thanks to Andreas Kießling. https://github.com/tpwd/ke_search/issues/228
[TASK] Add check if MySQL indexes are enabled on the index table and show an error in the backend module if not

Version 5.5.0, 17 May 2024
[FEATURE] Add pagination in the backend module "Indexed content" function and avoid out of memory error. https://github.com/tpwd/ke_search/issues/100
Expand Down
16 changes: 11 additions & 5 deletions Classes/Controller/BackendModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Tpwd\KeSearch\Lib\SearchHelper;
use Tpwd\KeSearch\Pagination\SlidingWindowPagination as BackportedSlidingWindowPagination;
use Tpwd\KeSearch\Service\IndexerStatusService;
use Tpwd\KeSearch\Utility\SanityCheckUtility;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Expand Down Expand Up @@ -140,12 +141,15 @@ public function startIndexingAction(ServerRequestInterface $request, ModuleTempl
$indexer = GeneralUtility::makeInstance(IndexerRunner::class);
$indexerConfigurations = $indexer->getConfigurations();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$mySqlIndexEnabled = SanityCheckUtility::IsIndexTableIndexesEnabled();

if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) {
$this->pageRenderer->addJsFile('EXT:ke_search/Resources/Public/JavaScript/v11/getIndexerStatusRequest.js');
} else {
// @phpstan-ignore-next-line
$this->pageRenderer->loadJavaScriptModule('@tpwd/ke-search/getIndexerStatusRequest.js');
if ($mySqlIndexEnabled) {
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) {
$this->pageRenderer->addJsFile('EXT:ke_search/Resources/Public/JavaScript/v11/getIndexerStatusRequest.js');
} else {
// @phpstan-ignore-next-line
$this->pageRenderer->loadJavaScriptModule('@tpwd/ke-search/getIndexerStatusRequest.js');
}
}

$indexingMode = (int)($request->getQueryParams()['indexingMode'] ?? IndexerBase::INDEXING_MODE_FULL);
Expand Down Expand Up @@ -270,10 +274,12 @@ public function startIndexingAction(ServerRequestInterface $request, ModuleTempl
$moduleTemplate->getView()->setLayoutRootPaths(['EXT:ke_search/Resources/Private/Layouts/']);
$moduleTemplate->getView()->setTemplatePathAndFilename('EXT:ke_search/Resources/Private/Templates/BackendModule/StartIndexing.html');
$moduleTemplate->getView()->assign('content', $content);
$moduleTemplate->getView()->assign('mySqlIndexEnabled', $mySqlIndexEnabled);
// @extensionScannerIgnoreLine
return new HtmlResponse($moduleTemplate->renderContent());
}
$moduleTemplate->assign('content', $content);
$moduleTemplate->assign('mySqlIndexEnabled', $mySqlIndexEnabled);
return $moduleTemplate->renderResponse('BackendModule/StartIndexing');
}

Expand Down
26 changes: 26 additions & 0 deletions Classes/Utility/SanityCheckUtility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tpwd\KeSearch\Utility;

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class SanityCheckUtility
{
public static function IsIndexTableIndexesEnabled(): bool
{
$indexEnabled = true;
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$connection = $connectionPool->getConnectionForTable('tx_kesearch_index');
$statement = $connection->prepare('SHOW INDEX FROM tx_kesearch_index');
$resultRows = $statement->executeQuery()->fetchAllAssociative();
if (!empty($resultRows)) {
foreach ($resultRows as $resultRow) {
if ($resultRow['Comment'] == 'disabled') {
$indexEnabled = false;
}
}
}
return $indexEnabled;
}
}
12 changes: 12 additions & 0 deletions Resources/Private/Templates/BackendModule/StartIndexing.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<div class="alert alert-notice">Waiting for indexer status.</div>
</div>
</div>
<f:if condition="!{mySqlIndexEnabled}">
<div class="row">
<div class="col-md-8">
<div class="alert alert-danger">The MySQL indexes in the table 'tx_kesearch_index' are disabled.
Searching in the frontend will not work.
<br />
This can happen if during first indexing there is an error and the indexing process has been
stopped. Please make sure that the indexing process runs through completely, that will
re-enable the indexes.</div>
</div>
</div>
</f:if>
<f:format.raw>{content}</f:format.raw>
</f:section>

Expand Down

0 comments on commit 57b638e

Please sign in to comment.