diff --git a/expire.admin.inc b/expire.admin.inc index 957fd012e822be201d3e5460c95ec4e80568145d..ec84f50e3d6c95e63551e675003891947b00051d 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 ef5d20911503c876a0bc8c22a6e9955e87f34697..9dc8db391a6e0d1fff1117bbe24e1eb93d33dd6a 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 73fe5807c8305070d457ab67d335d6d3784dda70..e009b85d014612447259b6244c797869f4027d4b 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); + } + } + }