Fixed bug #12025: Make statuses in the status report sorted and grouped
[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 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 class tx_reports_reports_status_ConfigurationStatus implements tx_reports_StatusProvider {
34
35 /**
36 * Determines the Install Tool's status, mainly concerning its protection.
37 *
38 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
39 */
40 public function getStatus() {
41 $statuses = array(
42 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
43
44 );
45
46 if ($this->isMemcachedUsed()) {
47 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
48 }
49
50 return $statuses;
51 }
52
53 /**
54 * Checks if sys_refindex is empty.
55 *
56 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
57 */
58 protected function getReferenceIndexStatus() {
59 $value = $GLOBALS['LANG']->getLL('status_ok');
60 $message = '';
61 $severity = tx_reports_reports_status_Status::OK;
62
63 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
64
65 if (!$count) {
66 $value = $GLOBALS['LANG']->getLL('status_empty');
67 $severity = tx_reports_reports_status_Status::WARNING;
68
69 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
70 $message = sprintf(
71 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference'),
72 '<a href="' . $url . '">',
73 '</a>'
74 );
75 }
76
77 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
78 'Reference Index', $value, $message, $severity
79 );
80 }
81
82 /**
83 * Checks whether memcached is configured, if that's the case we asume it's also used.
84 *
85 * @return boolean True if memcached is used, false otherwise.
86 */
87 protected function isMemcachedUsed() {
88 $memcachedUsed = false;
89
90 $memcachedServers = $this->getConfiguredMemcachedServers();
91 if (count($memcachedServers)) {
92 $memcachedUsed = true;
93 }
94
95 return $memcachedUsed;
96 }
97
98 /**
99 * Gets the configured memcached server connections.
100 *
101 * @return array An array of configured memcached server connections.
102 */
103 protected function getConfiguredMemcachedServers() {
104 $memcachedServers = array();
105
106 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
107 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
108 if (is_array($conf)) {
109 foreach ($conf as $key => $value) {
110 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
111 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
112 break;
113 }
114 }
115 }
116 }
117 }
118
119 return $memcachedServers;
120 }
121
122 /**
123 * Checks whether TYPO3 can connect to the configured memcached servers.
124 *
125 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
126 */
127 protected function getMemcachedConnectionStatus() {
128 $value = $GLOBALS['LANG']->getLL('status_ok');
129 $message = '';
130 $severity = tx_reports_reports_status_Status::OK;
131
132 $failedConnections = array();
133 $defaultMemcachedPort = ini_get('memcache.default_port');
134 $memcachedServers = $this->getConfiguredMemcachedServers();
135
136 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
137 foreach ($memcachedServers as $testServer) {
138 $configuredServer = $testServer;
139 if (substr($testServer, 0, 7) == 'unix://') {
140 $host = $testServer;
141 $port = 0;
142 } else {
143 if (substr($testServer, 0, 6) === 'tcp://') {
144 $testServer = substr($testServer, 6);
145 }
146 if (strstr($testServer, ':') !== FALSE) {
147 list($host, $port) = explode(':', $testServer, 2);
148 } else {
149 $host = $testServer;
150 $port = $defaultPort;
151 }
152 }
153 $memcachedConnection = @memcache_connect($host, $port);
154 if ($memcachedConnection != null) {
155 memcache_close($memcachedConnection);
156 } else {
157 $failedConnections[] = $configuredServer;
158 }
159 }
160 }
161
162 if (count($failedConnections)) {
163 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
164 $severity = tx_reports_reports_status_Status::WARNING;
165
166 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
167 . '<br /><br />'
168 . '<ul><li>'
169 . implode('</li><li>', $failedConnections)
170 . '</li></ul>';
171 }
172
173 return t3lib_div::makeInstance('tx_reports_reports_status_Status',
174 'Memcached Configuration', $value, $message, $severity
175 );
176 }
177
178 }
179
180
181 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_installtoolstatus.php']) {
182 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_installtoolstatus.php']);
183 }
184
185 ?>