[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Report / InstallStatusReport.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 use TYPO3\CMS\Backend\Utility\BackendUtility;
17
18 /**
19 * Provides an installation status report
20 *
21 * @author Ingo Renner <ingo@typo3.org>
22 */
23 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface {
24
25 protected $reportList = 'FileSystem,RemainingUpdates';
26
27 /**
28 * Compiles a collection of system status checks as a status report.
29 *
30 * @return array<\TYPO3\CMS\Reports\Status>
31 */
32 public function getStatus() {
33 $reports = array();
34 $reportMethods = explode(',', $this->reportList);
35 foreach ($reportMethods as $reportMethod) {
36 $reports[$reportMethod] = $this->{'get' . $reportMethod . 'Status'}();
37 }
38 return $reports;
39 }
40
41 /**
42 * Checks for several directories being writable.
43 *
44 * @return \TYPO3\CMS\Reports\Status Indicates status of the file system
45 */
46 protected function getFileSystemStatus() {
47 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
48 $message = '';
49 $severity = \TYPO3\CMS\Reports\Status::OK;
50 // Requirement level
51 // -1 = not required, but if it exists may be writable or not
52 // 0 = not required, if it exists the dir should be writable
53 // 1 = required, don't has to be writable
54 // 2 = required, has to be writable
55 $checkWritable = array(
56 'typo3temp/' => 2,
57 'typo3temp/pics/' => 2,
58 'typo3temp/temp/' => 2,
59 'typo3temp/llxml/' => 2,
60 'typo3temp/cs/' => 2,
61 'typo3temp/GB/' => 2,
62 'typo3temp/locks/' => 2,
63 'typo3conf/' => 2,
64 'typo3conf/ext/' => 0,
65 'typo3conf/l10n/' => 0,
66 TYPO3_mainDir . 'ext/' => -1,
67 'uploads/' => 2,
68 'uploads/pics/' => 0,
69 'uploads/media/' => 0,
70 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
71 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0
72 );
73 foreach ($checkWritable as $relPath => $requirementLevel) {
74 if (!@is_dir((PATH_site . $relPath))) {
75 // If the directory is missing, try to create it
76 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir(PATH_site . $relPath);
77 }
78 if (!@is_dir((PATH_site . $relPath))) {
79 if ($requirementLevel > 0) {
80 // directory is required
81 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
82 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
83 $severity = \TYPO3\CMS\Reports\Status::ERROR;
84 } else {
85 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
86 if ($requirementLevel == 0) {
87 $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
88 }
89 $message .= '<br />';
90 if ($severity < \TYPO3\CMS\Reports\Status::WARNING) {
91 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
92 $severity = \TYPO3\CMS\Reports\Status::WARNING;
93 }
94 }
95 } else {
96 if (!is_writable((PATH_site . $relPath))) {
97 switch ($requirementLevel) {
98 case 0:
99 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
100 if ($severity < \TYPO3\CMS\Reports\Status::WARNING) {
101 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
102 $severity = \TYPO3\CMS\Reports\Status::WARNING;
103 }
104 break;
105 case 2:
106 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
107 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
108 $severity = \TYPO3\CMS\Reports\Status::ERROR;
109 break;
110 }
111 }
112 }
113 }
114 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
115 }
116
117 /**
118 * Checks if there are still updates to perform
119 *
120 * @return \TYPO3\CMS\Reports\Status Represents whether the installation is completely updated yet
121 */
122 protected function getRemainingUpdatesStatus() {
123 $value = $GLOBALS['LANG']->getLL('status_updateComplete');
124 $message = '';
125 $severity = \TYPO3\CMS\Reports\Status::OK;
126 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::compat_version(TYPO3_branch)) {
127 $value = $GLOBALS['LANG']->getLL('status_updateIncomplete');
128 $severity = \TYPO3\CMS\Reports\Status::WARNING;
129 $url = BackendUtility::getModuleUrl('system_InstallInstall');
130 $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.install_update'), '<a href="' . $url . '">', '</a>');
131 }
132 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
133 }
134
135 }