Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
parameters:
ignoreErrors:
-
messages:
- '#Action\(\)#'
identifier: method.unused
path: ../../Classes/Controller/MySqlReportController.php
ignoreErrors:
2 changes: 1 addition & 1 deletion Build/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- phpstan-baseline.neon
- phpstan-baseline.neon

parameters:
level: 6
Expand Down
102 changes: 40 additions & 62 deletions Classes/Configuration/ExtConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,108 +11,86 @@

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,
) {
$extConf = [];

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;
}
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'],
) {}

if ($extConf === []) {
return;
}
public static function create(ExtensionConfiguration $extensionConfiguration): self
{
$extensionSettings = self::DEFAULT_SETTINGS;

// call setter method foreach configuration entry
foreach ($extConf as $key => $value) {
$methodName = 'set' . ucfirst($key);
if (method_exists($this, $methodName)) {
$this->$methodName($value);
// Overwrite default extension settings with values from EXT_CONF
try {
$extensionSettings = array_merge(
$extensionSettings,
$extensionConfiguration->get(self::EXT_KEY),
);

if (is_string($extensionSettings['slowQueryThreshold'])) {
$extensionSettings['slowQueryThreshold'] = str_replace(
',',
'.',
$extensionSettings['slowQueryThreshold'],
);
}
} catch (ExtensionConfigurationExtensionNotConfiguredException|ExtensionConfigurationPathDoesNotExistException) {
}

return new self(
enableFrontendLogging: (bool)$extensionSettings['enableFrontendLogging'],
enableBackendLogging: (bool)$extensionSettings['enableBackendLogging'],
activateExplainQuery: (bool)$extensionSettings['activateExplainQuery'],
slowQueryThreshold: (float)$extensionSettings['slowQueryThreshold'],
);
}

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()) {
Expand Down
41 changes: 41 additions & 0 deletions Classes/Controller/FileSortController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/mysqlreport.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Mysqlreport\Controller;

use Psr\Http\Message\ResponseInterface;
use StefanFroemken\Mysqlreport\Domain\Repository\QueryInformationRepository;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class FileSortController extends ActionController
{
public function __construct(
private QueryInformationRepository $queryInformationRepository,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
) {}

public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->getDocHeaderComponent()->setShortcutContext(
'mysqlreport_filesort',
'MySQL Report - Filesort',
);

$moduleTemplate->assign(
'queryInformationRecords',
$this->queryInformationRepository->findQueryInformationRecordsWithFilesort(),
);

return $moduleTemplate->renderResponse('FileSort/Index');
}
}
41 changes: 41 additions & 0 deletions Classes/Controller/FullTableScanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/mysqlreport.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Mysqlreport\Controller;

use Psr\Http\Message\ResponseInterface;
use StefanFroemken\Mysqlreport\Domain\Repository\QueryInformationRepository;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class FullTableScanController extends ActionController
{
public function __construct(
private QueryInformationRepository $queryInformationRepository,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
) {}

public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->getDocHeaderComponent()->setShortcutContext(
'mysqlreport_fulltablescan',
'MySQL Report - Full Table Scan',
);

$moduleTemplate->assign(
'queryInformationRecords',
$this->queryInformationRepository->findQueryInformationRecordsWithFullTableScan(),
);

return $moduleTemplate->renderResponse('FullTableScan/Index');
}
}
38 changes: 38 additions & 0 deletions Classes/Controller/InnoDBController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/mysqlreport.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Mysqlreport\Controller;

use Psr\Http\Message\ResponseInterface;
use StefanFroemken\Mysqlreport\Menu\Page;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class InnoDBController extends ActionController
{
public function __construct(
private readonly Page $page,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
) {}

public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->getDocHeaderComponent()->setShortcutContext(
'mysqlreport_innodb',
'MySQL Report - InnoDB',
);

$moduleTemplate->assign('renderedInfoBoxes', $this->page->getRenderedInfoBoxes());

return $moduleTemplate->renderResponse('InnoDB/Index');
}
}
38 changes: 38 additions & 0 deletions Classes/Controller/MiscController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/mysqlreport.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Mysqlreport\Controller;

use Psr\Http\Message\ResponseInterface;
use StefanFroemken\Mysqlreport\Menu\Page;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class MiscController extends ActionController
{
public function __construct(
private readonly Page $page,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
) {}

public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->getDocHeaderComponent()->setShortcutContext(
'mysqlreport_misc',
'MySQL Report - Misc',
);

$moduleTemplate->assign('renderedInfoBoxes', $this->page->getRenderedInfoBoxes());

return $moduleTemplate->renderResponse('Misc/Index');
}
}
Loading