Fixed issue #14729: Backwards compatibility broken by disabled deprecation log
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / reports / status / class.tx_reports_reports_status_configurationstatus.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2010 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 /**
27 * Performs some checks about the install tool protection status
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 *
33 * $Id$
34 */
35 class tx_reports_reports_status_ConfigurationStatus implements tx_reports_StatusProvider {
36
37 // 10 MB
38 protected $deprecationLogFileSizeWarningThreshold = 10485760;
39 // 100 MB
40 protected $deprecationLogFileSizeErrorThreshold = 104857600;
41
42
43 /**
44 * Determines the Install Tool's status, mainly concerning its protection.
45 *
46 * @return array List of statuses
47 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
48 */
49 public function getStatus() {
50 $statuses = array(
51 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
52 'deprecationLog' => $this->getDeprecationLogStatus()
53 );
54
55 if ($this->isMemcachedUsed()) {
56 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
57 }
58
59 return $statuses;
60 }
61
62 /**
63 * Checks if sys_refindex is empty.
64 *
65 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
66 */
67 protected function getReferenceIndexStatus() {
68 $value = $GLOBALS['LANG']->getLL('status_ok');
69 $message = '';
70 $severity = tx_reports_reports_status_Status::OK;
71
72 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
73 $registry = t3lib_div::makeInstance('t3lib_Registry');
74 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
75
76 if (!$count && $lastRefIndexUpdate) {
77 $value = $GLOBALS['LANG']->getLL('status_empty');
78 $severity = tx_reports_reports_status_Status::WARNING;
79
80 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
81 $message = sprintf(
82 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
83 '<a href="' . $url . '">',
84 '</a>',
85 t3lib_BeFunc::dateTime($lastRefIndexUpdate)
86 );
87 }
88 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
89 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity
90 );
91 }
92
93 /**
94 * Checks whether memcached is configured, if that's the case we asume it's also used.
95 *
96 * @return boolean True if memcached is used, false otherwise.
97 */
98 protected function isMemcachedUsed() {
99 $memcachedUsed = FALSE;
100
101 $memcachedServers = $this->getConfiguredMemcachedServers();
102 if (count($memcachedServers)) {
103 $memcachedUsed = TRUE;
104 }
105
106 return $memcachedUsed;
107 }
108
109 /**
110 * Gets the configured memcached server connections.
111 *
112 * @return array An array of configured memcached server connections.
113 */
114 protected function getConfiguredMemcachedServers() {
115 $memcachedServers = array();
116
117 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
118 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
119 if (is_array($conf)) {
120 foreach ($conf as $key => $value) {
121 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
122 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
123 break;
124 }
125 }
126 }
127 }
128 }
129
130 return $memcachedServers;
131 }
132
133 /**
134 * Checks whether TYPO3 can connect to the configured memcached servers.
135 *
136 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
137 */
138 protected function getMemcachedConnectionStatus() {
139 $value = $GLOBALS['LANG']->getLL('status_ok');
140 $message = '';
141 $severity = tx_reports_reports_status_Status::OK;
142
143 $failedConnections = array();
144 $defaultMemcachedPort = ini_get('memcache.default_port');
145 $memcachedServers = $this->getConfiguredMemcachedServers();
146
147 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
148 foreach ($memcachedServers as $testServer) {
149 $configuredServer = $testServer;
150 if (substr($testServer, 0, 7) == 'unix://') {
151 $host = $testServer;
152 $port = 0;
153 } else {
154 if (substr($testServer, 0, 6) === 'tcp://') {
155 $testServer = substr($testServer, 6);
156 }
157 if (strstr($testServer, ':') !== FALSE) {
158 list($host, $port) = explode(':', $testServer, 2);
159 } else {
160 $host = $testServer;
161 $port = $defaultMemcachedPort;
162 }
163 }
164 $memcachedConnection = @memcache_connect($host, $port);
165 if ($memcachedConnection != null) {
166 memcache_close($memcachedConnection);
167 } else {
168 $failedConnections[] = $configuredServer;
169 }
170 }
171 }
172
173 if (count($failedConnections)) {
174 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
175 $severity = tx_reports_reports_status_Status::WARNING;
176
177 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
178 . '<br /><br />'
179 . '<ul><li>'
180 . implode('</li><li>', $failedConnections)
181 . '</li></ul>';
182 }
183
184 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
185 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
186 );
187 }
188
189 /**
190 * Provides status information on the deprecation log, whether it's enabled
191 * and if so whether certain limits in file size are reached.
192 *
193 * @return tx_reports_reports_status_Status The deprecation log status.
194 */
195 protected function getDeprecationLogStatus() {
196 $title = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLog');
197 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disabled');
198 $message = '';
199 $severity = tx_reports_reports_status_Status::OK;
200
201 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
202 $value = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enabled');
203 $message = '<p>' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogEnabled') . '</p>';
204 $severity = tx_reports_reports_status_Status::NOTICE;
205
206 $logFile = t3lib_div::getDeprecationLogFileName();
207 $logFileSize = 0;
208
209 if (file_exists($logFile)) {
210 $logFileSize = filesize($logFile);
211
212 $message .= '<p> ' . sprintf(
213 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
214 $this->getDeprecationLogFileLink()
215 ) . '</p>';
216 }
217
218 if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) {
219 $severity = tx_reports_reports_status_Status::WARNING;
220 }
221
222 if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) {
223 $severity = tx_reports_reports_status_Status::ERROR;
224 }
225
226 if ($severity > tx_reports_reports_status_Status::OK) {
227 $message .= '<p> ' . sprintf(
228 $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'),
229 t3lib_div::formatSize($logFileSize)
230 ) . '</p>';
231 }
232 }
233
234 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
235 $title, $value, $message, $severity
236 );
237 }
238
239 /**
240 * Creates a link to the deprecation log file with the absolute path as the
241 * link text.
242 *
243 * @return string Link to the deprecation log file
244 */
245 protected function getDeprecationLogFileLink() {
246 $logFile = t3lib_div::getDeprecationLogFileName();
247 $documentRoot = t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT');
248
249 $relativePath = substr($logFile, strlen($documentRoot));
250 $link = '<a href="..' . $relativePath . '">' . $logFile . '</a>';
251
252 return $link;
253 }
254
255 }
256
257
258 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']) {
259 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']);
260 }
261
262 ?>