2 /***************************************************************
5 * (c) 2009-2010 Ingo Renner <ingo@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Performs some checks about the install tool protection status
29 * @author Ingo Renner <ingo@typo3.org>
35 class tx_reports_reports_status_ConfigurationStatus
implements tx_reports_StatusProvider
{
38 * Determines the Install Tool's status, mainly concerning its protection.
40 * @return array List of statuses
41 * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
43 public function getStatus() {
45 'emptyReferenceIndex' => $this->getReferenceIndexStatus(),
48 if ($this->isMemcachedUsed()) {
49 $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
56 * Checks if sys_refindex is empty.
58 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether the reference index is empty or not
60 protected function getReferenceIndexStatus() {
61 $value = $GLOBALS['LANG']->getLL('status_ok');
63 $severity = tx_reports_reports_status_Status
::OK
;
65 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
66 $registry = t3lib_div
::makeInstance('t3lib_Registry');
67 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
69 if (!$count && $lastRefIndexUpdate) {
70 $value = $GLOBALS['LANG']->getLL('status_empty');
71 $severity = tx_reports_reports_status_Status
::WARNING
;
73 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
75 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
76 '<a href="' . $url . '">',
78 t3lib_BeFunc
::dateTime($lastRefIndexUpdate)
81 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
82 $GLOBALS['LANG']->getLL('status_referenceIndex'), $value, $message, $severity
87 * Checks whether memcached is configured, if that's the case we asume it's also used.
89 * @return boolean True if memcached is used, false otherwise.
91 protected function isMemcachedUsed() {
92 $memcachedUsed = FALSE;
94 $memcachedServers = $this->getConfiguredMemcachedServers();
95 if (count($memcachedServers)) {
96 $memcachedUsed = TRUE;
99 return $memcachedUsed;
103 * Gets the configured memcached server connections.
105 * @return array An array of configured memcached server connections.
107 protected function getConfiguredMemcachedServers() {
108 $memcachedServers = array();
110 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
111 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
112 if (is_array($conf)) {
113 foreach ($conf as $key => $value) {
114 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
115 $memcachedServers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
123 return $memcachedServers;
127 * Checks whether TYPO3 can connect to the configured memcached servers.
129 * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object representing whether TYPO3 can connect to the configured memcached servers
131 protected function getMemcachedConnectionStatus() {
132 $value = $GLOBALS['LANG']->getLL('status_ok');
134 $severity = tx_reports_reports_status_Status
::OK
;
136 $failedConnections = array();
137 $defaultMemcachedPort = ini_get('memcache.default_port');
138 $memcachedServers = $this->getConfiguredMemcachedServers();
140 if (function_exists('memcache_connect') && is_array($memcachedServers)) {
141 foreach ($memcachedServers as $testServer) {
142 $configuredServer = $testServer;
143 if (substr($testServer, 0, 7) == 'unix://') {
147 if (substr($testServer, 0, 6) === 'tcp://') {
148 $testServer = substr($testServer, 6);
150 if (strstr($testServer, ':') !== FALSE) {
151 list($host, $port) = explode(':', $testServer, 2);
154 $port = $defaultMemcachedPort;
157 $memcachedConnection = @memcache_connect
($host, $port);
158 if ($memcachedConnection != null) {
159 memcache_close($memcachedConnection);
161 $failedConnections[] = $configuredServer;
166 if (count($failedConnections)) {
167 $value = $GLOBALS['LANG']->getLL('status_connectionFailed');
168 $severity = tx_reports_reports_status_Status
::WARNING
;
170 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable')
173 . implode('</li><li>', $failedConnections)
177 return t3lib_div
::makeInstance('tx_reports_reports_status_Status',
178 $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity
185 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']) {
186 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']);