720d7c8bb59007bbb5ccadfce5c6dde823db3492
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Middleware / SqlLogging.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Middleware;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\MiddlewareInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
23 use TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger;
24 use TYPO3\CMS\Adminpanel\Utility\StateUtility;
25 use TYPO3\CMS\Core\Database\ConnectionPool;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27
28 /**
29 * Enable sql logging for the admin panel
30 *
31 * @internal
32 */
33 class SqlLogging implements MiddlewareInterface
34 {
35
36 /**
37 * Enable SQL Logging as early as possible to catch all queries if the admin panel is active
38 */
39 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
40 {
41 if (StateUtility::isActivatedForUser() && StateUtility::isOpen()) {
42 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
43 $connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
44 $connection->getConfiguration()->setSQLLogger(GeneralUtility::makeInstance(DoctrineSqlLogger::class));
45 }
46 return $handler->handle($request);
47 }
48 }