summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspleshka2013-06-26 13:28:54 (GMT)
committerspleshka2013-06-26 13:28:54 (GMT)
commitafb511937863c3e2d444d0b184a952b07dc29204 (patch)
treee8d6cb7111684beef09be67791067b0c5adeed5f
parent05d6f90a30b34ab50eb68f4077e34bf832a65cce (diff)
Added debug mode.7.x-2.0-beta1
-rw-r--r--expire.admin.inc15
-rw-r--r--expire.module5
-rw-r--r--includes/expire.api.inc36
3 files changed, 56 insertions, 0 deletions
diff --git a/expire.admin.inc b/expire.admin.inc
index 957fd01..ec84f50 100644
--- a/expire.admin.inc
+++ b/expire.admin.inc
@@ -57,6 +57,21 @@ function expire_admin_settings_form() {
'#markup' => $modules ? theme('item_list', array('items' => $modules)) : t('There are no implementations.'),
);
+ $form['tabs']['status']['debug'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Debug'),
+ );
+
+ $form['tabs']['status']['debug']['expire_debug'] = array(
+ '#type' => 'radios',
+ '#title' => t('Debug level'),
+ '#options' => array(
+ EXPIRE_DEBUG_DISABLED => t('Disabled'),
+ EXPIRE_DEBUG_WATCHDOG => t('Watchdog'),
+ EXPIRE_DEBUG_FULL => t('Watchdog + site message'),
+ ),
+ '#default_value' => variable_get('expire_debug', EXPIRE_DEBUG_DISABLED),
+ );
// NODE SETTINGS.
$form['tabs']['node'] = array(
diff --git a/expire.module b/expire.module
index ef5d209..9dc8db3 100644
--- a/expire.module
+++ b/expire.module
@@ -36,6 +36,11 @@ define('EXPIRE_USER_CANCEL', 4);
define('EXPIRE_VOTINGAPI_INSERT', 1);
define('EXPIRE_VOTINGAPI_DELETE', 2);
+// Debug levels.
+define('EXPIRE_DEBUG_DISABLED', 0);
+define('EXPIRE_DEBUG_WATCHDOG', 1);
+define('EXPIRE_DEBUG_FULL', 2);
+
// Default values for cache expirations.
define('EXPIRE_NODE_FRONT_PAGE' , FALSE);
define('EXPIRE_NODE_NODE_PAGE' , TRUE);
diff --git a/includes/expire.api.inc b/includes/expire.api.inc
index 73fe580..e009b85 100644
--- a/includes/expire.api.inc
+++ b/includes/expire.api.inc
@@ -36,6 +36,9 @@ class ExpireAPI {
list($absolute_urls, $wildcards) = self::convertToAbsoluteUrls($urls);
}
+ // Write some debug information.
+ self::debugLog($absolute_urls, $wildcards, $object_type);
+
$status = variable_get('expire_status', EXPIRE_STATUS_DISABLED);
if ($status == EXPIRE_STATUS_ENABLED_INTERNAL) {
self::executeInternalExpiration($absolute_urls, $wildcards);
@@ -227,4 +230,37 @@ class ExpireAPI {
return array($absolute_urls, $wildcards);
}
+ /**
+ * Log debug information.
+ *
+ * @param $absolute_urls
+ * @param $wildcards
+ * @param $object_type
+ */
+ protected static function debugLog($absolute_urls, $wildcards, $object_type) {
+
+ $debug = variable_get('expire_debug', EXPIRE_DEBUG_DISABLED);
+ if (empty($debug)) {
+ return;
+ }
+
+ $output_urls = array();
+ foreach ($absolute_urls as $internal_path => $url) {
+ $wildcard = !empty($wildcards[$internal_path]) ? 'true' : 'false';
+ $output_urls[] = t('URL: @url', array('@url' => check_url($url)));
+ $output_urls[] = t('Wildcard: @wildcard', array('@wildcard' => $wildcard));
+ $output_urls[] = t('Expired object: @type', array('@type' => $object_type ? $object_type : '(none)'));
+ $output_urls[] = '--------';
+ }
+
+ // Log debug message in watchdog.
+ $message = t('Expiration was executed for the next URLs: !urls', array('!urls' => theme('item_list', array('items' => $output_urls))));
+ watchdog('expire', $message, array(), WATCHDOG_DEBUG);
+
+ // For development might be useful to print info on screen.
+ if ($debug == EXPIRE_DEBUG_FULL) {
+ drupal_set_message($message);
+ }
+ }
+
}