[TASK] Use ModuleTemplate API for ext:belog
[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\Toolbar\Enumeration\InformationStatus;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Belog\Domain\Model\Constraint;
20 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
21
22 /**
23 * Count newest exceptions for the system information menu
24 */
25 class SystemInformationController extends AbstractController {
26
27 /**
28 * Modifies the SystemInformation array
29 *
30 * @return NULL|array
31 */
32 public function appendMessage() {
33 $constraint = $this->getConstraintFromBeUserData();
34 if ($constraint === NULL) {
35 $constraint = $this->objectManager->get(Constraint::class);
36 }
37
38 $timestamp = $constraint->getStartTimestamp();
39 $backendUser = $this->getBackendUserAuthentication();
40 if (isset($backendUser->uc['systeminformation'])) {
41 $systemInformationUc = json_decode($backendUser->uc['systeminformation'], TRUE);
42 if (isset($systemInformationUc['system_BelogLog']['lastAccess'])) {
43 $timestamp = $systemInformationUc['system_BelogLog']['lastAccess'];
44 }
45 }
46
47 $this->setStartAndEndTimeFromTimeSelector($constraint);
48 // we can't use the extbase repository here as the required TypoScript may not be parsed yet
49 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $timestamp . ' AND error IN(-1,1,2)');
50
51 if ($count > 0) {
52 return array(
53 array(
54 'module' => 'system_BelogLog',
55 'count' => $count,
56 'status' => InformationStatus::STATUS_ERROR,
57 'text' => sprintf(LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count, BackendUtility::getModuleUrl('system_BelogLog'))
58 )
59 );
60 }
61 return NULL;
62 }
63
64 /**
65 * Get module states (the constraint object) from user data
66 *
67 * @return \TYPO3\CMS\Belog\Domain\Model\Constraint|NULL
68 */
69 protected function getConstraintFromBeUserData() {
70 $serializedConstraint = $this->getBackendUserAuthentication()->getModuleData(ToolsController::class);
71 if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
72 return NULL;
73 }
74 return @unserialize($serializedConstraint);
75 }
76
77 /**
78 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
79 */
80 protected function getBackendUserAuthentication() {
81 return $GLOBALS['BE_USER'];
82 }
83
84 /**
85 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
86 */
87 protected function getDatabaseConnection() {
88 return $GLOBALS['TYPO3_DB'];
89 }
90 }