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