|
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
|
|
|
* @param ServerRequestInterface $request |
|
39
|
|
|
* @param RequestHandlerInterface $handler |
|
40
|
|
|
* @return ResponseInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
43
|
|
|
{ |
|
44
|
|
|
if (StateUtility::isActivatedForUser() && StateUtility::isOpen()) { |
|
45
|
|
|
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
46
|
|
|
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME); |
|
47
|
|
|
$connection->getConfiguration()->setSQLLogger(GeneralUtility::makeInstance(DoctrineSqlLogger::class)); |
|
48
|
|
|
} |
|
49
|
|
|
return $handler->handle($request); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|