[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / Controller / SystemInformationController.php
1 <?php
2 namespace TYPO3\CMS\Belog\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem;
18 use TYPO3\CMS\Backend\Routing\UriBuilder;
19 use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
20 use TYPO3\CMS\Belog\Domain\Model\Constraint;
21 use TYPO3\CMS\Core\Database\Connection;
22 use TYPO3\CMS\Core\Database\ConnectionPool;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25
26 /**
27 * Count newest exceptions for the system information menu
28 */
29 class SystemInformationController extends AbstractController
30 {
31 /**
32 * Modifies the SystemInformation array
33 *
34 * @param SystemInformationToolbarItem $systemInformationToolbarItem
35 */
36 public function appendMessage(SystemInformationToolbarItem $systemInformationToolbarItem)
37 {
38 $constraint = $this->getConstraintFromBeUserData();
39 if ($constraint === null) {
40 $constraint = $this->objectManager->get(Constraint::class);
41 }
42
43 $timestamp = $constraint->getStartTimestamp();
44 $backendUser = $this->getBackendUserAuthentication();
45 if (isset($backendUser->uc['systeminformation'])) {
46 $systemInformationUc = json_decode($backendUser->uc['systeminformation'], true);
47 if (isset($systemInformationUc['system_BelogLog']['lastAccess'])) {
48 $timestamp = $systemInformationUc['system_BelogLog']['lastAccess'];
49 }
50 }
51
52 $this->setStartAndEndTimeFromTimeSelector($constraint);
53 // we can't use the extbase repository here as the required TypoScript may not be parsed yet
54 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');
55 $count = $queryBuilder->count('error')
56 ->from('sys_log')
57 ->where(
58 $queryBuilder->expr()->gte('tstamp', $queryBuilder->createNamedParameter($timestamp, \PDO::PARAM_INT)),
59 $queryBuilder->expr()->in(
60 'error',
61 $queryBuilder->createNamedParameter([-1, 1, 2], Connection::PARAM_INT_ARRAY)
62 )
63 )
64 ->execute()
65 ->fetchColumn(0);
66
67 if ($count > 0) {
68 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
69 $systemInformationToolbarItem->addSystemMessage(
70 sprintf(LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count, (string)$uriBuilder->buildUriFromRoute('system_BelogLog', ['tx_belog_system_beloglog' => ['constraint' => ['action' => -1]]])),
71 InformationStatus::STATUS_ERROR,
72 $count,
73 'system_BelogLog',
74 http_build_query(['tx_belog_system_beloglog' => ['constraint' => ['action' => -1]]])
75 );
76 }
77 }
78
79 /**
80 * Get module states (the constraint object) from user data
81 *
82 * @return \TYPO3\CMS\Belog\Domain\Model\Constraint|null
83 */
84 protected function getConstraintFromBeUserData()
85 {
86 $serializedConstraint = $this->getBackendUserAuthentication()->getModuleData(ToolsController::class);
87 if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
88 return null;
89 }
90 return @unserialize($serializedConstraint);
91 }
92
93 /**
94 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
95 */
96 protected function getBackendUserAuthentication()
97 {
98 return $GLOBALS['BE_USER'];
99 }
100 }