f363d57488be580efe0880fb0e013f7b4de58b11
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / report / class.tx_install_report_installstatus.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 require_once(t3lib_extMgm::extPath('install', 'requirements.php'));
27
28
29 /**
30 * Provides an installation status report
31 *
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage tx_install
35 */
36 class tx_install_report_InstallStatus implements tx_reports_StatusProvider {
37
38 protected $reportList = 'Typo3Version,FileSystem,RemainingUpdates';
39
40 /**
41 * Compiles a collection of system status checks as a status report.
42 *
43 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
44 */
45 public function getStatus() {
46 $reports = array();
47 $reportMethods = explode(',', $this->reportList);
48
49 foreach ($reportMethods as $reportMethod) {
50 $reports[$reportMethod] = $this->{'get' . $reportMethod . 'Status'}();
51 }
52
53 return $reports;
54 }
55
56 /**
57 * Simply gets the current TYPO3 version.
58 *
59 * @return tx_reports_reports_status_Status
60 */
61 protected function getTypo3VersionStatus() {
62 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
63 'TYPO3',
64 TYPO3_version,
65 '',
66 tx_reports_reports_status_Status::NOTICE
67 );
68 }
69
70 /**
71 * Checks for several directoris being writable.
72 *
73 * @return unknown_type
74 */
75 protected function getFileSystemStatus() {
76 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_writable');
77 $message = '';
78 $severity = tx_reports_reports_status_Status::OK;
79
80 // Requirement level
81 // -1 = not required, but if it exists may be writable or not
82 // 0 = not required, if it exists the dir should be writable
83 // 1 = required, don't has to be writable
84 // 2 = required, has to be writable
85
86 $checkWritable = array(
87 'typo3temp/' => 2,
88 'typo3temp/pics/' => 2,
89 'typo3temp/temp/' => 2,
90 'typo3temp/llxml/' => 2,
91 'typo3temp/cs/' => 2,
92 'typo3temp/GB/' => 2,
93 'typo3temp/locks/' => 2,
94 'typo3conf/' => 2,
95 'typo3conf/ext/' => 0,
96 'typo3conf/l10n/' => 0,
97 TYPO3_mainDir . 'ext/' => -1,
98 'uploads/' => 2,
99 'uploads/pics/' => 0,
100 'uploads/media/' => 0,
101 'uploads/tf/' => 0,
102 'fileadmin/' => -1,
103 'fileadmin/_temp_/' => 0,
104 );
105
106 foreach ($checkWritable as $relPath => $requirementLevel) {
107 if (!@is_dir(PATH_site . $relPath)) {
108 // If the directory is missing, try to create it
109 t3lib_div::mkdir(PATH_site . $relPath);
110 }
111
112 if (!@is_dir(PATH_site . $relPath)) {
113 if ($requirementLevel > 0) {
114 // directory is required
115 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_missingDirectory');
116 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
117 $severity = tx_reports_reports_status_Status::ERROR;
118 } else {
119 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryDoesNotExist'), $relPath);
120 if ($requirementLevel == 0) {
121 $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryShouldAlsoBeWritable');
122 }
123 $message .= '<br />';
124
125 if ($severity < tx_reports_reports_status_Status::WARNING) {
126 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_nonExistingDirectory');
127 $severity = tx_reports_reports_status_Status::WARNING;
128 }
129 }
130 } else {
131 if (!is_writable(PATH_site . $relPath)) {
132 switch ($requirementLevel) {
133 case 0:
134 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryShouldBeWritable'), PATH_site . $relPath) . '<br />';
135
136 if ($severity < tx_reports_reports_status_Status::WARNING) {
137 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_recommendedWritableDirectory');
138 $severity = tx_reports_reports_status_Status::WARNING;
139 }
140 break;
141 case 2:
142 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_requiredWritableDirectory');
143 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryMustBeWritable'), PATH_site . $relPath) . '<br />';
144 $severity = tx_reports_reports_status_Status::ERROR;
145 break;
146 }
147 }
148 }
149 }
150
151 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
152 $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_fileSystem'),
153 $value,
154 $message,
155 $severity
156 );
157 }
158
159 /**
160 * Checks if there are still updates to perform
161 *
162 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the installation is not completely updated yet
163 */
164 protected function getRemainingUpdatesStatus() {
165 $value = $GLOBALS['LANG']->getLL('status_updateComplete');
166 $message = '';
167 $severity = tx_reports_reports_status_Status::OK;
168
169 if (!t3lib_div::compat_version(TYPO3_branch)) {
170 $value = $GLOBALS['LANG']->getLL('status_updateIncomplete');
171 $severity = tx_reports_reports_status_Status::WARNING;
172
173 $url = 'install/index.php?redirect_url=index.php'
174 . urlencode('?TYPO3_INSTALL[type]=update');
175 $message = sprintf(
176 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_update'),
177 '<a href="' . $url . '">',
178 '</a>'
179 );
180 }
181
182 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
183 $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_remainingUpdates'), $value, $message, $severity
184 );
185 }
186
187 }
188
189 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/install/report/class.tx_install_report_installstatus.php']) {
190 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/install/report/class.tx_install_report_installstatus.php']);
191 }
192
193 ?>