[TASK] Add verbose output to report mail for failed tests
[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 * @author Christian Kuhn <lolli@schwarzbu.ch>
24 */
25 class EnvironmentStatusReport implements StatusProviderInterface, ExtendedStatusProviderInterface {
26
27 /**
28 * Compile environment status report
29 *
30 * @return \TYPO3\CMS\Reports\Status[]
31 */
32 public function getStatus() {
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 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 /** @var $statusCheck \TYPO3\CMS\Install\SystemEnvironment\Check */
52 $statusCheck = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\SystemEnvironment\\Check');
53 $statusObjects = $statusCheck->getStatus();
54
55 $reportStatusTypes = array(
56 'error' => array(),
57 'warning' => array(),
58 'ok' => array(),
59 'information' => array(),
60 'notice' => array(),
61 );
62
63 /** @var $statusObject \TYPO3\CMS\Install\Status\AbstractStatus */
64 foreach ($statusObjects as $statusObject) {
65 $severityIdentifier = $statusObject->getSeverity();
66 if (empty($severityIdentifier) || !is_array($reportStatusTypes[$severityIdentifier])) {
67 throw new \TYPO3\CMS\Install\Exception('Unknown reports severity type', 1362602560);
68 }
69 $reportStatusTypes[$severityIdentifier][] = $statusObject;
70 }
71
72 $statusArray = array();
73 foreach ($reportStatusTypes as $type => $statusObjects) {
74 $value = count($statusObjects);
75 $message = '';
76 if ($verbose) {
77 foreach ($statusObjects as $statusObject) {
78 $message .= '### ' . $statusObject->getTitle() . ': ' . $statusObject->getSeverity() . CRLF;
79 }
80 }
81
82 if ($value > 0) {
83 $pathToXliff = 'LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf';
84 // Map information type to abbreviation which is used in \TYPO3\CMS\Reports\Status class
85 if ($type === 'information') {
86 $type = 'info';
87 }
88 if (!$verbose) {
89 $message = $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.message.' . $type);
90 }
91 $severity = constant('\TYPO3\CMS\Reports\Status::' . strtoupper($type));
92 $statusArray[] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
93 'TYPO3\\CMS\\Reports\\Status',
94 $GLOBALS['LANG']->sL($pathToXliff . ':environment.status.title'),
95 sprintf($GLOBALS['LANG']->sL($pathToXliff . ':environment.status.value'), $value),
96 $message,
97 $severity
98 );
99 }
100 }
101
102 return $statusArray;
103 }
104
105 }