From 4bc72609a24d5d8d60a0b503cad22c7e8b08e08a Mon Sep 17 00:00:00 2001 From: Lorenz Schori Date: Sat, 19 Jan 2013 13:48:31 +0100 Subject: [PATCH 2/3] Implement hook_requirements --- authcache.install | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/authcache.install b/authcache.install index e1702f3..b4d5725 100644 --- a/authcache.install +++ b/authcache.install @@ -13,8 +13,7 @@ function authcache_enable() { global $user; // Did admin follow install instructions? - //if (substr(variable_get('cache_inc', FALSE), -13) != 'authcache.inc') { - if (!variable_get('cache_class_cache_page', false)) { + if (!_authcache_backendstatus()) { drupal_set_message(st('Your settings.php file must be modified to enable Authcache. See README.txt.', array('@url' => base_path() . drupal_get_path('module', 'authcache') . '/README.txt')), 'error'); } @@ -32,6 +31,32 @@ function authcache_disable() { } /** + * Implements hook_requirements(). + */ +function authcache_requirements($phase) { + $requirements = array(); + // Ensure translations don't break during installation. + $t = get_t(); + + // Retrieve the name of the cache class used for the cache_page bin. + $page_cache_class = get_class(_cache_get_object('cache_page')); + + $requirements['authcache'] = array( + 'title' => $t('Authcache'), + ); + if (_authcache_backendstatus()) { + $requirements['authcache']['value'] = $t('Using %class as cache backend', array('%class' => $page_cache_class)); + } + else { + $requirements['authcache']['value'] = $t('authcache.inc is not the last entry in cache_backends variable.'); + $requirements['authcache']['description'] = $t('Your settings.php file must be modified to enable Authcache. See README.txt.', array('@url' => base_path() . drupal_get_path('module', 'authcache') . '/README.txt')); + $requirements['authcache']['severity'] = REQUIREMENT_ERROR; + } + + return $requirements; +} + +/** * Implements hook_install(). */ function authcache_install() { @@ -57,3 +82,14 @@ function authcache_uninstall() { ->execute(); cache_clear_all('variables', 'cache'); } + +/** + * Return true if settings.php is properly configured and authcache.inc is the + * last entry in the cache_backends array. + */ +function _authcache_backendstatus() { + // Check whether authcache.inc is last in cache_backends. + $last_in_backends = end(variable_get('cache_backends', array())); + $authcache_inc = drupal_get_path('module', 'authcache') . '/authcache.inc'; + return $authcache_inc == $last_in_backends; +} -- 1.7.10.4