04c72d43dfa7aa3bd0dedbe427cd877dd284b1a2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Report / EnvironmentStatusReport.php
1 <?php
2 namespace TYPO3\CMS\Install\Report;
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\Reports\ExtendedStatusProviderInterface;
18 use TYPO3\CMS\Reports\StatusProviderInterface;
19
20 /**
21 * Provides an environment status report
22 */
23 class EnvironmentStatusReport implements StatusProviderInterface, ExtendedStatusProviderInterface
24 {
25 /**
26 * Compile environment status report
27 *
28 * @return \TYPO3\CMS\Reports\Status[]
29 */
30 public function getStatus()
31 {
32 return $this->getStatusInternal(false);
33 }
34
35 /**
36 * Returns the detailed status of an extension or (sub)system
37 *
38 * @return \TYPO3\CMS\Reports\Status[]
39 */
40 public function getDetailedStatus()
41 {
42 return $this->getStatusInternal(true);
43 }
44
45 /**
46 * @param $verbose
47 * @return \TYPO3\CMS\Reports\Status[]
48 * @throws \TYPO3\CMS\Install\Exception
49 */
50 protected function getStatusInternal($verbose)
51 {
52 /** @var $statusCheck \TYPO3\CMS\Install\SystemEnvironment\Check */
53 $statusCheck = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Install\SystemEnvironment\Check::class);
54 $statusObjects = $statusCheck->getStatus();
55
56 /** @var $statusCheck \TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck */
57 $databaseStatusCheck = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck::class);
58 $statusObjects = array_merge($statusObjects, $databaseStatusCheck->getStatus());
59
60 $reportStatusTypes = array(
61 'error' => array(),
62 'warning' => array(),
63 'ok' => array(),
64 'information' => array(),
65 'notice' => array(),
66 );
67
68 /** @var $statusObject \TYPO3\CMS\Install\Status\AbstractStatus */
69 foreach ($statusObjects as $statusObject) {
70 $severityIdentifier = $statusObject->getSeverity();
71 if (empty($severityIdentifier) || !is_array($reportStatusTypes[$severityIdentifier])) {
72 throw new \TYPO3\CMS\Install\Exception('Unknown reports severity type', 1362602560);
73 }
74 $reportStatusTypes[$severityIdentifier][] = $statusObject;
75 }
76
77 $statusArray = array();
78 foreach ($reportStatusTypes as $type => $statusObjects) {
79 $value = count($statusObjects);
80 $message = '';
81 if ($verbose) {
82 foreach ($statusObjects as $statusObject) {
83 $message .= '### ' . $statusObject->getTitle() . ': ' . $statusObject->getSeverity() . CRLF;
84 }
85 }
86
87 if ($value > 0) {
88 $pathToXliff = 'LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf';
89 // Map information type to abbreviation which is used in \TYPO3\CMS\Reports\Status class
90 if ($type === 'information') {
91 $type = 'info';
92 }
93 if (!$verbose) {
94 $message = $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.message.' . $type);
95 }
96 $severity = constant('\TYPO3\CMS\Reports\Status::' . strtoupper($type));
97 $statusArray[] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
98 \TYPO3\CMS\Reports\Status::class,
99 $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.title'),
100 sprintf($GLOBALS['LANG']->sL($pathToXliff . ':environment.status.value'), $value),
101 $message,
102 $severity
103 );
104 }
105 }
106
107 return $statusArray;
108 }
109 }