[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Report / InstallStatusReport.php
1 <?php
2 namespace TYPO3\CMS\Install\Report;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Provides an installation status report
29 *
30 * @author Ingo Renner <ingo@typo3.org>
31 */
32 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface {
33
34 protected $reportList = 'FileSystem,RemainingUpdates';
35
36 /**
37 * Compiles a collection of system status checks as a status report.
38 *
39 * @return array<\TYPO3\CMS\Reports\Status>
40 */
41 public function getStatus() {
42 $reports = array();
43 $reportMethods = explode(',', $this->reportList);
44 foreach ($reportMethods as $reportMethod) {
45 $reports[$reportMethod] = $this->{'get' . $reportMethod . 'Status'}();
46 }
47 return $reports;
48 }
49
50 /**
51 * Checks for several directories being writable.
52 *
53 * @return \TYPO3\CMS\Reports\Status Indicates status of the file system
54 */
55 protected function getFileSystemStatus() {
56 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
57 $message = '';
58 $severity = \TYPO3\CMS\Reports\Status::OK;
59 // Requirement level
60 // -1 = not required, but if it exists may be writable or not
61 // 0 = not required, if it exists the dir should be writable
62 // 1 = required, don't has to be writable
63 // 2 = required, has to be writable
64 $checkWritable = array(
65 'typo3temp/' => 2,
66 'typo3temp/pics/' => 2,
67 'typo3temp/temp/' => 2,
68 'typo3temp/llxml/' => 2,
69 'typo3temp/cs/' => 2,
70 'typo3temp/GB/' => 2,
71 'typo3temp/locks/' => 2,
72 'typo3conf/' => 2,
73 'typo3conf/ext/' => 0,
74 'typo3conf/l10n/' => 0,
75 TYPO3_mainDir . 'ext/' => -1,
76 'uploads/' => 2,
77 'uploads/pics/' => 0,
78 'uploads/media/' => 0,
79 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
80 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0
81 );
82 foreach ($checkWritable as $relPath => $requirementLevel) {
83 if (!@is_dir((PATH_site . $relPath))) {
84 // If the directory is missing, try to create it
85 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir(PATH_site . $relPath);
86 }
87 if (!@is_dir((PATH_site . $relPath))) {
88 if ($requirementLevel > 0) {
89 // directory is required
90 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
91 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
92 $severity = \TYPO3\CMS\Reports\Status::ERROR;
93 } else {
94 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
95 if ($requirementLevel == 0) {
96 $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
97 }
98 $message .= '<br />';
99 if ($severity < \TYPO3\CMS\Reports\Status::WARNING) {
100 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
101 $severity = \TYPO3\CMS\Reports\Status::WARNING;
102 }
103 }
104 } else {
105 if (!is_writable((PATH_site . $relPath))) {
106 switch ($requirementLevel) {
107 case 0:
108 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
109 if ($severity < \TYPO3\CMS\Reports\Status::WARNING) {
110 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
111 $severity = \TYPO3\CMS\Reports\Status::WARNING;
112 }
113 break;
114 case 2:
115 $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
116 $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
117 $severity = \TYPO3\CMS\Reports\Status::ERROR;
118 break;
119 }
120 }
121 }
122 }
123 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);
124 }
125
126 /**
127 * Checks if there are still updates to perform
128 *
129 * @return \TYPO3\CMS\Reports\Status Represents whether the installation is completely updated yet
130 */
131 protected function getRemainingUpdatesStatus() {
132 $value = $GLOBALS['LANG']->getLL('status_updateComplete');
133 $message = '';
134 $severity = \TYPO3\CMS\Reports\Status::OK;
135 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::compat_version(TYPO3_branch)) {
136 $value = $GLOBALS['LANG']->getLL('status_updateIncomplete');
137 $severity = \TYPO3\CMS\Reports\Status::WARNING;
138 $url = 'install/index.php?redirect_url=index.php' . urlencode('?TYPO3_INSTALL[type]=update');
139 $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.install_update'), '<a href="' . $url . '">', '</a>');
140 }
141 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);
142 }
143
144 }
145
146
147 ?>