[FOLLOWUP][FEATURE] Introduce System Information dropdown item
[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\Belog\Domain\Model\Constraint;
18
19 /**
20 * Count newest exceptions for the system information menu
21 */
22 class SystemInformationController extends AbstractController {
23
24 /**
25 * Modifies the SystemInformation array
26 *
27 * @return NULL|array
28 */
29 public function appendMessage() {
30 $constraint = $this->getConstraintFromBeUserData();
31 if ($constraint === NULL) {
32 $constraint = $this->objectManager->get(Constraint::class);
33 }
34
35 $this->setStartAndEndTimeFromTimeSelector($constraint);
36 // we can't use the extbase repository here as the required TypoScript may not be parsed yet
37 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $constraint->getStartTimestamp() . ' AND tstamp <= ' . $constraint->getEndTimestamp() . ' AND error IN(-1,1,2)');
38
39 if ($count > 0) {
40 return array(
41 array(
42 'count' => $count,
43 'status' => \TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus::STATUS_ERROR,
44 'text' => sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count)
45 )
46 );
47 }
48 return NULL;
49 }
50
51 /**
52 * Get module states (the constraint object) from user data
53 *
54 * @return \TYPO3\CMS\Belog\Domain\Model\Constraint|NULL
55 */
56 protected function getConstraintFromBeUserData() {
57 $serializedConstraint = $GLOBALS['BE_USER']->getModuleData(ToolsController::class);
58 if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
59 return NULL;
60 }
61 return @unserialize($serializedConstraint);
62 }
63
64 /**
65 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
66 */
67 protected function getDatabaseConnection() {
68 return $GLOBALS['TYPO3_DB'];
69 }
70 }