From b32b71ac3aac4714cb30f63201c2ef7e90811f2f Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Sat, 18 Oct 2025 21:49:30 +0200 Subject: [PATCH 01/15] Upgrade to TYPO3 14-dev --- Classes/Configuration/ExtConf.php | 93 ++++------- Classes/Controller/MySqlReportController.php | 7 +- Classes/Controller/ProfileController.php | 2 +- Classes/Controller/QueryController.php | 2 +- Classes/DependencyInjection/DashboardPass.php | 6 +- .../Domain/Repository/StatusRepository.php | 4 +- Classes/Helper/DownloadHelper.php | 2 +- Classes/Helper/ExplainQueryHelper.php | 16 +- Classes/Helper/ModuleTemplateHelper.php | 15 +- Classes/Helper/QueryCacheHelper.php | 14 +- Classes/InfoBox/AbstractInfoBox.php | 89 ++--------- Classes/InfoBox/InfoBoxStateInterface.php | 19 +++ .../InfoBox/InfoBoxUnorderedListInterface.php | 17 ++ .../InfoBox/Information/ConnectionInfoBox.php | 150 +++++++++++------- .../Information/ServerVersionInfoBox.php | 53 +++++-- Classes/InfoBox/Information/UptimeInfoBox.php | 71 +++++---- .../InfoBox/InnoDb/HitRatioBySFInfoBox.php | 50 ++++-- Classes/InfoBox/InnoDb/HitRatioInfoBox.php | 47 ++++-- .../InnoDb/InnoDbBufferLoadInfoBox.php | 61 +++++-- Classes/InfoBox/InnoDb/InstancesInfoBox.php | 49 ++++-- Classes/InfoBox/InnoDb/LogFileSizeInfoBox.php | 59 ++++--- Classes/InfoBox/InnoDb/WriteRatioInfoBox.php | 46 ++++-- .../InfoBox/Misc/AbortedConnectsInfoBox.php | 18 ++- Classes/InfoBox/Misc/BackLogInfoBox.php | 17 +- Classes/InfoBox/Misc/BinaryLogInfoBox.php | 20 +-- .../InfoBox/Misc/MaxAllowedPacketInfoBox.php | 36 +++-- .../Misc/StandaloneReplicationInfoBox.php | 17 +- Classes/InfoBox/Misc/SyncBinaryLogInfoBox.php | 17 +- Classes/InfoBox/Misc/TempTablesInfoBox.php | 127 ++++++++------- .../QueryCache/AverageQuerySizeInfoBox.php | 61 ++++--- .../QueryCache/AverageUsedBlocksInfoBox.php | 62 +++++--- .../QueryCache/FragmentationRatioInfoBox.php | 46 ++++-- .../InfoBox/QueryCache/HitRatioInfoBox.php | 47 ++++-- .../InfoBox/QueryCache/InsertRatioInfoBox.php | 47 ++++-- .../InfoBox/QueryCache/PruneRatioInfoBox.php | 44 +++-- .../QueryCacheSizeTooHighInfoBox.php | 32 ++-- .../QueryCache/QueryCacheStatusInfoBox.php | 29 ++-- .../OpenedTableDefinitionsInfoBox.php | 93 ++++++----- .../TableCache/OpenedTablesInfoBox.php | 134 +++++++++------- .../InfoBox/ThreadCache/HitRatioInfoBox.php | 48 +++--- Classes/Logger/MySqlReportSqlLogger.php | 2 +- Classes/Menu/Page.php | 103 +++++------- Classes/Report/StatusReport.php | 12 +- .../GetStatusValuesAndVariablesTrait.php | 47 ++++++ Classes/Traits/Typo3RequestTrait.php | 22 ++- Configuration/Services.php | 2 - Configuration/Services.yaml | 110 ------------- composer.json | 24 +-- ext_emconf.php | 4 +- 49 files changed, 1170 insertions(+), 923 deletions(-) create mode 100644 Classes/InfoBox/InfoBoxStateInterface.php create mode 100644 Classes/InfoBox/InfoBoxUnorderedListInterface.php create mode 100644 Classes/Traits/GetStatusValuesAndVariablesTrait.php diff --git a/Classes/Configuration/ExtConf.php b/Classes/Configuration/ExtConf.php index a76c999..182f308 100644 --- a/Classes/Configuration/ExtConf.php +++ b/Classes/Configuration/ExtConf.php @@ -11,59 +11,59 @@ namespace StefanFroemken\Mysqlreport\Configuration; -use Psr\Log\LoggerInterface; use StefanFroemken\Mysqlreport\Traits\Typo3RequestTrait; +use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Core\Environment; -use TYPO3\CMS\Core\Utility\MathUtility; /** - * This class will streamline the values from extension settings + * This class streamlines all settings from the extension manager */ -class ExtConf +#[Autoconfigure(constructor: 'create')] +final readonly class ExtConf { use Typo3RequestTrait; - private bool $enableFrontendLogging = false; + private const EXT_KEY = 'mysqlreport'; - private bool $enableBackendLogging = false; - - private bool $activateExplainQuery = false; - - private float $slowQueryThreshold = 10.0; + private const DEFAULT_SETTINGS = [ + 'enableFrontendLogging' => false, + 'enableBackendLogging' => false, + 'activateExplainQuery' => false, + 'slowQueryThreshold' => 10.0, + ]; public function __construct( - ExtensionConfiguration $extensionConfiguration, - private readonly LoggerInterface $logger, + private bool $enableFrontendLogging = self::DEFAULT_SETTINGS['enableFrontendLogging'], + private bool $enableBackendLogging = self::DEFAULT_SETTINGS['enableBackendLogging'], + private bool $activateExplainQuery = self::DEFAULT_SETTINGS['activateExplainQuery'], + private float $slowQueryThreshold = self::DEFAULT_SETTINGS['slowQueryThreshold'], ) { - $extConf = []; + } + + public static function create(ExtensionConfiguration $extensionConfiguration): self + { + $extensionSettings = self::DEFAULT_SETTINGS; + // Overwrite default extension settings with values from EXT_CONF try { - $extConf = (array)$extensionConfiguration->get('mysqlreport'); - } catch (ExtensionConfigurationExtensionNotConfiguredException $exception) { - $this->logger->error('No extension settings could be found for extension: mysqlreport', [ - 'exception' => $exception, - ]); - } catch (ExtensionConfigurationPathDoesNotExistException $exception) { - $this->logger->error('No extension settings could be found in TYPO3_CONF_VARS for extension: mysqlreport', [ - 'exception' => $exception, - ]); - return; - } + $extensionSettings = array_merge( + $extensionSettings, + $extensionConfiguration->get(self::EXT_KEY), + ); - if ($extConf === []) { - return; + $extensionSettings['slowQueryThreshold'] = str_replace(',', '.', $extensionSettings['slowQueryThreshold']); + } catch (ExtensionConfigurationExtensionNotConfiguredException|ExtensionConfigurationPathDoesNotExistException) { } - // call setter method foreach configuration entry - foreach ($extConf as $key => $value) { - $methodName = 'set' . ucfirst($key); - if (method_exists($this, $methodName)) { - $this->$methodName($value); - } - } + return new self( + enableFrontendLogging: (bool)$extensionSettings['enableFrontendLogging'], + enableBackendLogging: (bool)$extensionSettings['enableBackendLogging'], + activateExplainQuery: (bool)$extensionSettings['activateExplainQuery'], + slowQueryThreshold: (float)$extensionSettings['slowQueryThreshold'], + ); } public function isEnableFrontendLogging(): bool @@ -71,48 +71,21 @@ public function isEnableFrontendLogging(): bool return $this->enableFrontendLogging; } - public function setEnableFrontendLogging(string $enableFrontendLogging): void - { - $this->enableFrontendLogging = (bool)$enableFrontendLogging; - } - public function isEnableBackendLogging(): bool { return $this->enableBackendLogging; } - public function setEnableBackendLogging(string $enableBackendLogging): void - { - $this->enableBackendLogging = (bool)$enableBackendLogging; - } - public function isActivateExplainQuery(): bool { return $this->activateExplainQuery; } - public function setActivateExplainQuery(string $activateExplainQuery): void - { - $this->activateExplainQuery = (bool)$activateExplainQuery; - } - public function getSlowQueryThreshold(): float { return $this->slowQueryThreshold; } - public function setSlowQueryThreshold(string $slowQueryThreshold): void - { - if (MathUtility::canBeInterpretedAsFloat($slowQueryThreshold)) { - $this->slowQueryThreshold = (float)$slowQueryThreshold; - } else { - $slowQueryThreshold = str_replace(',', '.', $slowQueryThreshold); - if (MathUtility::canBeInterpretedAsFloat($slowQueryThreshold)) { - $this->slowQueryThreshold = (float)$slowQueryThreshold; - } - } - } - public function isQueryLoggingActivated(): bool { if (Environment::isCli()) { diff --git a/Classes/Controller/MySqlReportController.php b/Classes/Controller/MySqlReportController.php index 4690d8d..de616d9 100644 --- a/Classes/Controller/MySqlReportController.php +++ b/Classes/Controller/MySqlReportController.php @@ -16,14 +16,17 @@ use Psr\Http\Message\ServerRequestInterface; use StefanFroemken\Mysqlreport\Helper\ModuleTemplateHelper; use StefanFroemken\Mysqlreport\Menu\Page; +use StefanFroemken\Mysqlreport\Traits\GetStatusValuesAndVariablesTrait; use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; /** * Controller to show a basic analysis of MySQL variables and status */ -readonly class MySqlReportController +class MySqlReportController { + use GetStatusValuesAndVariablesTrait; + /** * @param ContainerInterface $serviceLocator A container just containing a few objects available for this controller */ @@ -56,7 +59,7 @@ private function overviewAction(ModuleTemplate $moduleTemplate): ResponseInterfa 'MySqlReport Overview', ); - $moduleTemplate->assign('status', $this->serviceLocator->get('repository.status')->findAll()); + $moduleTemplate->assign('status', $this->getStatusValues()); return $moduleTemplate->renderResponse('MySqlReport/Overview'); } diff --git a/Classes/Controller/ProfileController.php b/Classes/Controller/ProfileController.php index ec22156..95ce945 100644 --- a/Classes/Controller/ProfileController.php +++ b/Classes/Controller/ProfileController.php @@ -21,7 +21,7 @@ /** * Controller to show and analyze all queries of a request */ -readonly class ProfileController +class ProfileController { public function __construct( private QueryInformationRepository $queryInformationRepository, diff --git a/Classes/Controller/QueryController.php b/Classes/Controller/QueryController.php index a874b95..1ca528c 100644 --- a/Classes/Controller/QueryController.php +++ b/Classes/Controller/QueryController.php @@ -21,7 +21,7 @@ /** * Controller to show results of FTS and filesort */ -readonly class QueryController +class QueryController { public function __construct( private QueryInformationRepository $queryInformationRepository, diff --git a/Classes/DependencyInjection/DashboardPass.php b/Classes/DependencyInjection/DashboardPass.php index 459d7f6..417fd5f 100644 --- a/Classes/DependencyInjection/DashboardPass.php +++ b/Classes/DependencyInjection/DashboardPass.php @@ -30,14 +30,14 @@ public function __construct(string $tagName) } /** - * Start removing registered dashboard widgets, if EXT:dashboard is not installed + * Start removing registered dashboard widgets if EXT:dashboard is not installed * * This CompilerPass was called at a very early state, where $container was not injected into * GeneralUtility for makeInstance usage and ExtensionManagementUtility could not be used - * as PackageManager was not injected into that class already. We also can not use the container itself, as the + * as PackageManager was not injected into that class already. We also cannot use the container itself, as the * real PackageManger will be added to $container AFTER processing all CompilerPasses. * - * The only solution is, to check if there is a class definition of EXT:dashboard registered in given $container + * The only solution is to check if there is a class definition of EXT:dashboard registered in a given $ container */ public function process(ContainerBuilder $container): void { diff --git a/Classes/Domain/Repository/StatusRepository.php b/Classes/Domain/Repository/StatusRepository.php index 6bcf954..ad30e04 100644 --- a/Classes/Domain/Repository/StatusRepository.php +++ b/Classes/Domain/Repository/StatusRepository.php @@ -23,7 +23,9 @@ { use DatabaseConnectionTrait; - public function __construct(private LoggerInterface $logger) {} + public function __construct( + private LoggerInterface $logger, + ) {} public function findAll(): StatusValues { diff --git a/Classes/Helper/DownloadHelper.php b/Classes/Helper/DownloadHelper.php index 584c2eb..1068d7b 100644 --- a/Classes/Helper/DownloadHelper.php +++ b/Classes/Helper/DownloadHelper.php @@ -36,7 +36,7 @@ public function __construct( */ public function asCSV(array $headerRow, array $records): ResponseInterface { - // Create result + // Create the result $result[] = CsvUtility::csvValues($headerRow, self::CSV_DELIMITER, self::CSV_QUOTE); foreach ($records as $record) { $result[] = CsvUtility::csvValues($record, self::CSV_DELIMITER, self::CSV_QUOTE); diff --git a/Classes/Helper/ExplainQueryHelper.php b/Classes/Helper/ExplainQueryHelper.php index 4da5486..0f6f91c 100644 --- a/Classes/Helper/ExplainQueryHelper.php +++ b/Classes/Helper/ExplainQueryHelper.php @@ -16,23 +16,26 @@ use StefanFroemken\Mysqlreport\Configuration\ExtConf; use StefanFroemken\Mysqlreport\Domain\Model\QueryInformation; use StefanFroemken\Mysqlreport\Traits\DatabaseConnectionTrait; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** - * Helper to analyze EXPLAIN query result and add information to QueryInformation model + * Helper to analyze an EXPLAIN query result and add information to QueryInformation model */ readonly class ExplainQueryHelper { use DatabaseConnectionTrait; - public function __construct(private LoggerInterface $logger) {} + public function __construct( + private ExtConf $extConf, + private LoggerInterface $logger, + ) { + } /** * @param QueryInformation $queryInformation */ public function updateQueryInformation(QueryInformation $queryInformation): void { - if (!$this->getExtConf()->isActivateExplainQuery()) { + if (!$this->extConf->isActivateExplainQuery()) { return; } @@ -79,9 +82,4 @@ private function getExplainRows(QueryInformation $queryInformation): array return $explainRows; } - - private function getExtConf(): ExtConf - { - return GeneralUtility::makeInstance(ExtConf::class); - } } diff --git a/Classes/Helper/ModuleTemplateHelper.php b/Classes/Helper/ModuleTemplateHelper.php index da2a3e4..2057e82 100644 --- a/Classes/Helper/ModuleTemplateHelper.php +++ b/Classes/Helper/ModuleTemplateHelper.php @@ -15,14 +15,16 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Imaging\IconSize; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** - * Helper to add buttons to button bar + * Helper to add buttons to the button bar */ readonly class ModuleTemplateHelper { - public function __construct(private UriBuilder $uriBuilder) {} + public function __construct( + private IconFactory $iconFactory, + private UriBuilder $uriBuilder, + ) {} public function addOverviewButton(ButtonBar $buttonBar): void { @@ -30,7 +32,7 @@ public function addOverviewButton(ButtonBar $buttonBar): void ->makeLinkButton() ->setShowLabelText(true) ->setTitle('Overview') - ->setIcon($this->getIconFactory()->getIcon('actions-viewmode-tiles', IconSize::SMALL)) + ->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles', IconSize::SMALL)) ->setHref( (string)$this->uriBuilder->buildUriFromRoute('system_mysqlreport'), ); @@ -57,9 +59,4 @@ public function addShortcutButton( $buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT); } - - protected function getIconFactory(): IconFactory - { - return GeneralUtility::makeInstance(IconFactory::class); - } } diff --git a/Classes/Helper/QueryCacheHelper.php b/Classes/Helper/QueryCacheHelper.php index 39843dc..17b4e44 100644 --- a/Classes/Helper/QueryCacheHelper.php +++ b/Classes/Helper/QueryCacheHelper.php @@ -11,7 +11,7 @@ namespace StefanFroemken\Mysqlreport\Helper; -use StefanFroemken\Mysqlreport\Menu\Page; +use StefanFroemken\Mysqlreport\Domain\Model\Variables; /** * Helper with useful methods for Query Cache @@ -19,18 +19,18 @@ readonly class QueryCacheHelper { /** - * Returns true, if Query Cache is activated + * Returns true if Query Cache is activated * * @api */ - public function isQueryCacheEnabled(Page $page): bool + public function isQueryCacheEnabled(Variables $variables): bool { - return isset($page->getVariables()['query_cache_type']) + return isset($variables['query_cache_type']) && ( - strtolower($page->getVariables()['query_cache_type']) === 'on' + strtolower($variables['query_cache_type']) === 'on' || ( - is_numeric($page->getVariables()['query_cache_type']) - && (int)($page->getVariables()['query_cache_type']) === 1 + is_numeric($variables['query_cache_type']) + && (int)($variables['query_cache_type']) === 1 ) ); } diff --git a/Classes/InfoBox/AbstractInfoBox.php b/Classes/InfoBox/AbstractInfoBox.php index ebd0745..f502c67 100644 --- a/Classes/InfoBox/AbstractInfoBox.php +++ b/Classes/InfoBox/AbstractInfoBox.php @@ -11,91 +11,32 @@ namespace StefanFroemken\Mysqlreport\InfoBox; -use StefanFroemken\Mysqlreport\Enumeration\StateEnumeration; -use StefanFroemken\Mysqlreport\Menu\Page; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Core\View\ViewInterface; /** * Model with properties for panels you can see in BE module */ -abstract class AbstractInfoBox implements \SplObserver +abstract class AbstractInfoBox { - protected string $pageIdentifier = ''; + protected const TITLE = ''; - /** - * This is the title of the infobox - */ - protected string $title = ''; - - /** - * Use addUnorderedListEntry to add new elements to