diff --git a/recacher.install b/recacher.install index 119905f..dbab802 100644 --- a/recacher.install +++ b/recacher.install @@ -10,11 +10,9 @@ * Implements hook_uninstall(). */ function recacher_uninstall() { - // Rather than using a database query to delete all queries, the best way of - // deleting variables in hook_uninstall() is to simply use variable_del(). - // See https://www.drupal.org/node/2828832 variable_del('recacher_cron_interval'); variable_del('recacher_cron_next_execution'); + variable_del('recacher_hook_exit'); variable_del('recacher_max_urls'); variable_del('recacher_watchdog'); } diff --git a/recacher.module b/recacher.module index 2e0f68e..2ba3209 100644 --- a/recacher.module +++ b/recacher.module @@ -19,7 +19,7 @@ function recacher_permission() { } /** - * Display help and module information + * Display help and module integration * Implements hook_help(). * @param path which path of the site we're displaying help * @param arg array that holds the current path as would be returned from arg() function @@ -133,6 +133,10 @@ function recacher_expire_cache($urls, $wildcards, $object_type, $object) { )) ->expression('expirations', 'expirations + :inc', array(':inc' => 1)) ->execute(); + + // Leave a note for hook_exit() that there are URLs to be crawled. + $queued = &drupal_static(__FUNCTION__); + $queued = TRUE; } if ($paths = array_keys($wildcards, TRUE)) { @@ -240,3 +244,19 @@ function recacher_crawler() { return count($dburls); } + +/** + * Implements hook_exit(). + * + * Optionally trigger the crawler at the end of the page execution. + */ +function recacher_exit($destination = NULL) { + // See if this option is enabled. + if (variable_get('recrawler_hook_exit', FALSE)) { + // Check to see if anything was queued. + $queued = &drupal_static('recacher_expire_cache'); + if ($queued) { + recacher_crawler(); + } + } +} diff --git a/recacher_settings.inc b/recacher_settings.inc index 3718e85..d1b643e 100644 --- a/recacher_settings.inc +++ b/recacher_settings.inc @@ -47,6 +47,13 @@ function recacher_admin($form, &$form_state) { '#required' => TRUE, ); + $form['recrawler_hook_exit'] = array( + '#type' => 'checkbox', + '#title' => t('Re-cache immediately?'), + '#description' => t('This causes the recaching to occur at the end of the page request.'), + '#default_value' => variable_get('recrawler_hook_exit', FALSE), + ); + $form['recacher_run_now'] = array( '#markup' => '

'. l(t('Re-cache immediately'), 'admin/config/system/recacher/crawl') . ': ' . t('don\'t wait for the cron to run; warm caches of the expired pages immediately.') . '', );