d6fb3c96a1886ff5cad0b95a6f796b03cd4f1750
[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\Toolbar\Enumeration\InformationStatus;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
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 $systemInformationToolbarItem->addSystemMessage(
69 sprintf(LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count, BackendUtility::getModuleUrl('system_BelogLog')),
70 InformationStatus::STATUS_ERROR,
71 $count,
72 'system_BelogLog'
73 );
74 }
75 }
76
77 /**
78 * Get module states (the constraint object) from user data
79 *
80 * @return \TYPO3\CMS\Belog\Domain\Model\Constraint|NULL
81 */
82 protected function getConstraintFromBeUserData()
83 {
84 $serializedConstraint = $this->getBackendUserAuthentication()->getModuleData(ToolsController::class);
85 if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
86 return null;
87 }
88 return @unserialize($serializedConstraint);
89 }
90
91 /**
92 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
93 */
94 protected function getBackendUserAuthentication()
95 {
96 return $GLOBALS['BE_USER'];
97 }
98 }