Commit afb51193 authored by spleshka's avatar spleshka

Added debug mode.

parent 05d6f90a
......@@ -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(
......
......@@ -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);
......
......@@ -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);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment