diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index c807b41..5fe43e6 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # -# EXT:examples test runner based on docker/podman. +# EXT:mysqlreport test runner based on docker/podman. # trap 'cleanUp;exit 2' SIGINT @@ -60,8 +60,8 @@ handleDbmsOptions() { echo "Use \".Build/Scripts/runTests.sh -h\" to display help and valid options" >&2 exit 1 fi - [ -z "${DBMS_VERSION}" ] && DBMS_VERSION="10.4" - if ! [[ ${DBMS_VERSION} =~ ^(10.4|10.5|10.6|10.7|10.8|10.9|10.10|10.11|11.0|11.1)$ ]]; then + [ -z "${DBMS_VERSION}" ] && DBMS_VERSION="10.11" + if ! [[ ${DBMS_VERSION} =~ ^(10.6|10.7|10.8|10.9|10.10|10.11|11.0|11.1)$ ]]; then echo "Invalid combination -d ${DBMS} -i ${DBMS_VERSION}" >&2 echo >&2 echo "Use \".Build/Scripts/runTests.sh -h\" to display help and valid options" >&2 diff --git a/Build/phpunit/FunctionalTestsBootstrap.php b/Build/phpunit/FunctionalTestsBootstrap.php index a95bc52..9882f8f 100644 --- a/Build/phpunit/FunctionalTestsBootstrap.php +++ b/Build/phpunit/FunctionalTestsBootstrap.php @@ -1,4 +1,5 @@ $queries */ public function __construct( - readonly private StatementInterface $wrappedStatement, - readonly private MySqlReportSqlLogger $logger, - readonly private string $sql, - readonly private \SplQueue $queries, + private readonly StatementInterface $wrappedStatement, + private readonly MySqlReportSqlLogger $logger, + private readonly string $sql, + private readonly \SplQueue $queries, ) {} public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void diff --git a/Classes/Doctrine/Middleware/LoggerWithQueryTimeMiddleware.php b/Classes/Doctrine/Middleware/LoggerWithQueryTimeMiddleware.php index a400045..8d6d7c5 100644 --- a/Classes/Doctrine/Middleware/LoggerWithQueryTimeMiddleware.php +++ b/Classes/Doctrine/Middleware/LoggerWithQueryTimeMiddleware.php @@ -19,7 +19,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; /** - * With new driverMiddlewares-hook of TYPO3 we register a Middleware into Doctrine. + * With the new driverMiddlewares-hook of TYPO3 we register a Middleware into Doctrine. */ readonly class LoggerWithQueryTimeMiddleware implements UsableForConnectionInterface { @@ -43,7 +43,7 @@ public function canBeUsedForConnection(string $identifier, array $connectionPara public function wrap(Driver $driver): Driver { - // As $driver is transferred as constructor argument, DI can not be used in that class + // As $driver is transferred as a constructor argument, DI cannot be used in that class return GeneralUtility::makeInstance(LoggerWithQueryTimeDriver::class, $driver); } } diff --git a/Classes/Domain/Repository/QueryInformationRepository.php b/Classes/Domain/Repository/QueryInformationRepository.php index c7205f2..c53e771 100644 --- a/Classes/Domain/Repository/QueryInformationRepository.php +++ b/Classes/Domain/Repository/QueryInformationRepository.php @@ -408,7 +408,7 @@ public function findQueryInformationRecordsWithSlowQueries(): array public function bulkInsert(array $queries): void { try { - $connection = $this->getDefaultConnection(); + $connection = $this->getConnectionForMySqlReport(); foreach (array_chunk($queries, 50) as $chunkOfQueriesToStore) { $connection->bulkInsert( diff --git a/Classes/EventListener/CacheAction.php b/Classes/EventListener/CacheAction.php index 53728de..3348d98 100644 --- a/Classes/EventListener/CacheAction.php +++ b/Classes/EventListener/CacheAction.php @@ -15,7 +15,6 @@ use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent; use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Create ClearCache entry and process Cache Clearing of mysqlreport @@ -24,6 +23,10 @@ { use DatabaseConnectionTrait; + public function __construct( + private UriBuilder $uriBuilder, + ) {} + /** * Add clear cache menu entry * @@ -32,13 +35,12 @@ */ public function __invoke(ModifyClearCacheActionsEvent $modifyClearCacheActionsEvent): void { - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - $modifyClearCacheActionsEvent->addCacheActionIdentifier('mysqlprofiles'); $modifyClearCacheActionsEvent->addCacheAction([ + 'id' => 'mysqlprofile', 'title' => 'LLL:EXT:mysqlreport/Resources/Private/Language/locallang.xlf:clearCache.title', 'description' => 'LLL:EXT:mysqlreport/Resources/Private/Language/locallang.xlf:clearCache.description', - 'href' => (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'mysqlprofiles']), + 'href' => (string)$this->uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'mysqlprofiles']), 'iconIdentifier' => 'actions-system-cache-clear-impact-high', ]); } @@ -54,7 +56,7 @@ public function clearProfiles(array $params = []): void isset($params['cacheCmd']) && $params['cacheCmd'] === 'mysqlprofiles' ) { - $this->getDefaultConnection()->truncate('tx_mysqlreport_query_information'); + $this->getConnectionForMySqlReport()->truncate('tx_mysqlreport_query_information'); } } } diff --git a/Classes/Helper/QueryParamsHelper.php b/Classes/Helper/QueryParamsHelper.php index 3c06c75..be17258 100644 --- a/Classes/Helper/QueryParamsHelper.php +++ b/Classes/Helper/QueryParamsHelper.php @@ -18,7 +18,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool; /** - * Helper to replace query params in query to get a ready to use query for EXPLAIN + * Helper to replace query params in a query to get a ready to use query for EXPLAIN */ readonly class QueryParamsHelper { diff --git a/Classes/Traits/DatabaseConnectionTrait.php b/Classes/Traits/DatabaseConnectionTrait.php index bb45589..174e7b6 100644 --- a/Classes/Traits/DatabaseConnectionTrait.php +++ b/Classes/Traits/DatabaseConnectionTrait.php @@ -38,6 +38,16 @@ private function getDefaultConnection(): Connection ); } + /** + * It may happen that the mysqlreport table is NOT configured for DEFAULT_CONNECTION_NAME (read-ony|write setups) + */ + private function getConnectionForMySqlReport(): Connection + { + return $this->getConnectionPool()->getConnectionForTable( + 'tx_mysqlreport_query_information', + ); + } + private function isValidConnectionDriver(string $connectionDriver): bool { return in_array($connectionDriver, ['mysqli', 'pdo_mysql'], true); diff --git a/Documentation/ChangeLog/Index.rst b/Documentation/ChangeLog/Index.rst index 9434ce8..a096822 100644 --- a/Documentation/ChangeLog/Index.rst +++ b/Documentation/ChangeLog/Index.rst @@ -10,6 +10,11 @@ ChangeLog .. contents:: :local: +Version 4.0.2 +============= + +* [TASK] Use specific connection for mysqlreport table + Version 4.0.1 ============= diff --git a/Documentation/guides.xml b/Documentation/guides.xml index c2a9904..a15fe44 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -15,7 +15,7 @@ /> 'froemken@gmail.com', 'state' => 'stable', 'author_company' => '', - 'version' => '4.0.1', + 'version' => '4.0.2', 'constraints' => [ 'depends' => [ 'typo3' => '13.0.0-13.4.99',