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