Created
April 28, 2014 10:36
-
-
Save gielfeldt/11368061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ultimate_cron.api.php b/ultimate_cron.api.php | |
index d0c93f1..a8cf0ca 100644 | |
--- a/ultimate_cron.api.php | |
+++ b/ultimate_cron.api.php | |
@@ -187,7 +187,7 @@ function hook_cron_easy_hooks_alter(&$easy_hooks) { | |
* @param UltimateCronJob $job | |
* The job being queried. | |
*/ | |
-function hook_pre_schedule($job) { | |
+function hook_cron_pre_schedule($job) { | |
} | |
/** | |
@@ -196,7 +196,7 @@ function hook_pre_schedule($job) { | |
* @param UltimateCronJob $job | |
* The job being queried. | |
*/ | |
-function hook_post_schedule($job) { | |
+function hook_cron_post_schedule($job) { | |
} | |
/** | |
@@ -205,7 +205,7 @@ function hook_post_schedule($job) { | |
* @param UltimateCronJob $job | |
* The job being launched. | |
*/ | |
-function hook_pre_launch($job) { | |
+function hook_cron_pre_launch($job) { | |
} | |
/** | |
@@ -214,7 +214,7 @@ function hook_pre_launch($job) { | |
* @param UltimateCronJob $job | |
* The job that was launched. | |
*/ | |
-function hook_post_launch($job) { | |
+function hook_cron_post_launch($job) { | |
} | |
/** | |
@@ -223,7 +223,7 @@ function hook_post_launch($job) { | |
* @param UltimateCronJob $job | |
* The job being run. | |
*/ | |
-function hook_pre_run($job) { | |
+function hook_cron_pre_run($job) { | |
} | |
/** | |
@@ -232,7 +232,7 @@ function hook_pre_run($job) { | |
* @param UltimateCronJob $job | |
* The job that was run. | |
*/ | |
-function hook_post_run($job) { | |
+function hook_cron_post_run($job) { | |
} | |
/** | |
@@ -241,7 +241,7 @@ function hook_post_run($job) { | |
* @param UltimateCronJob $job | |
* The job being invoked. | |
*/ | |
-function hook_pre_invoke($job) { | |
+function hook_cron_pre_invoke($job) { | |
} | |
/** | |
@@ -250,7 +250,7 @@ function hook_pre_invoke($job) { | |
* @param UltimateCronJob $job | |
* The job that was invoked. | |
*/ | |
-function hook_post_invoke($job) { | |
+function hook_cron_post_invoke($job) { | |
} | |
/** | |
@@ -265,5 +265,5 @@ function hook_post_invoke($job) { | |
* @param array &$allowed_operations | |
* Allowed operations for this job. | |
*/ | |
-function hook_ultimate_cron_plugin_build_operations($job, &$allowed_operations) { | |
+function hook_ultimate_cron_plugin_build_operations_alter($job, &$allowed_operations) { | |
} | |
diff --git a/ultimate_cron.background_process.inc b/ultimate_cron.background_process.inc | |
new file mode 100644 | |
index 0000000..85fe316 | |
--- /dev/null | |
+++ b/ultimate_cron.background_process.inc | |
@@ -0,0 +1,62 @@ | |
+<?php | |
+/** | |
+ * @file | |
+ * Hooks for legacy handling of Background Process 1.x. | |
+ */ | |
+ | |
+/** | |
+ * Implements hook_background_process_shutdown(). | |
+ * | |
+ * @param BackgroundProcess $process | |
+ * The background process object. | |
+ * @param string $msg | |
+ * The shutdown message. | |
+ */ | |
+function ultimate_cron_background_process_shutdown($process = NULL, $msg = NULL) { | |
+ // Some sanity checking. | |
+ if (!$process || !is_object($process) || empty($process->callback)) { | |
+ return; | |
+ } | |
+ // We only handle the legacy callback here. | |
+ if ( | |
+ !is_array($process->callback) || | |
+ $process->callback[0] !== 'UltimateCronBackgroundProcessLegacyLauncher' || | |
+ $process->callback[1] !== 'job_callback' | |
+ ) { | |
+ return; | |
+ } | |
+ | |
+ // Close the Ultimate Cron log entry. | |
+ list ($name, $lock_id) = $process->args; | |
+ | |
+ // If someone has set the dont log signal, it means that they | |
+ // are handling the shutdown of the log. | |
+ $job = ultimate_cron_job_load($name); | |
+ if (!$job) { | |
+ return; | |
+ } | |
+ | |
+ if ($job->getSignal('background_process_legacy_dont_log')) { | |
+ // Resend within this request, just in case. | |
+ $job->sendSignal('background_process_legacy_dont_log'); | |
+ return; | |
+ } | |
+ | |
+ $log_entry = $job->resumeLog($lock_id); | |
+ | |
+ // Rewrite message to conform with Ultimate Cron style, if this is | |
+ // a manual unlock. | |
+ global $user; | |
+ $username = !empty($user->uid) ? $user->name : ''; | |
+ if ($msg == t('Manually unlocked by !name', array('!name' => $username))) { | |
+ $username = !empty($user->uid) ? $user->name : t('anonymous'); | |
+ $msg = t('@name manually unlocked by user @username (@uid)', array( | |
+ '@name' => $name, | |
+ '@username' => $username, | |
+ '@uid' => !empty($user->uid) ? $user->uid : 0, | |
+ )); | |
+ } | |
+ | |
+ $log_entry->log('bgpl_launcher', $msg, array(), WATCHDOG_WARNING); | |
+ $log_entry->finish(); | |
+} | |
diff --git a/ultimate_cron.background_process_legacy.inc b/ultimate_cron.background_process_legacy.inc | |
deleted file mode 100644 | |
index 85fe316..0000000 | |
--- a/ultimate_cron.background_process_legacy.inc | |
+++ /dev/null | |
@@ -1,62 +0,0 @@ | |
-<?php | |
-/** | |
- * @file | |
- * Hooks for legacy handling of Background Process 1.x. | |
- */ | |
- | |
-/** | |
- * Implements hook_background_process_shutdown(). | |
- * | |
- * @param BackgroundProcess $process | |
- * The background process object. | |
- * @param string $msg | |
- * The shutdown message. | |
- */ | |
-function ultimate_cron_background_process_shutdown($process = NULL, $msg = NULL) { | |
- // Some sanity checking. | |
- if (!$process || !is_object($process) || empty($process->callback)) { | |
- return; | |
- } | |
- // We only handle the legacy callback here. | |
- if ( | |
- !is_array($process->callback) || | |
- $process->callback[0] !== 'UltimateCronBackgroundProcessLegacyLauncher' || | |
- $process->callback[1] !== 'job_callback' | |
- ) { | |
- return; | |
- } | |
- | |
- // Close the Ultimate Cron log entry. | |
- list ($name, $lock_id) = $process->args; | |
- | |
- // If someone has set the dont log signal, it means that they | |
- // are handling the shutdown of the log. | |
- $job = ultimate_cron_job_load($name); | |
- if (!$job) { | |
- return; | |
- } | |
- | |
- if ($job->getSignal('background_process_legacy_dont_log')) { | |
- // Resend within this request, just in case. | |
- $job->sendSignal('background_process_legacy_dont_log'); | |
- return; | |
- } | |
- | |
- $log_entry = $job->resumeLog($lock_id); | |
- | |
- // Rewrite message to conform with Ultimate Cron style, if this is | |
- // a manual unlock. | |
- global $user; | |
- $username = !empty($user->uid) ? $user->name : ''; | |
- if ($msg == t('Manually unlocked by !name', array('!name' => $username))) { | |
- $username = !empty($user->uid) ? $user->name : t('anonymous'); | |
- $msg = t('@name manually unlocked by user @username (@uid)', array( | |
- '@name' => $name, | |
- '@username' => $username, | |
- '@uid' => !empty($user->uid) ? $user->uid : 0, | |
- )); | |
- } | |
- | |
- $log_entry->log('bgpl_launcher', $msg, array(), WATCHDOG_WARNING); | |
- $log_entry->finish(); | |
-} | |
diff --git a/ultimate_cron.cron.inc b/ultimate_cron.cron.inc | |
new file mode 100644 | |
index 0000000..3f3b96c | |
--- /dev/null | |
+++ b/ultimate_cron.cron.inc | |
@@ -0,0 +1,71 @@ | |
+<?php | |
+/** | |
+ * @file | |
+ * Cron hook implementations for Ultimate Cron. | |
+ */ | |
+ | |
+/** | |
+ * Implements hook_cronapi(). | |
+ * | |
+ * Adds clean up jobs for plugins. | |
+ */ | |
+function ultimate_cron_cronapi() { | |
+ $items = array(); | |
+ | |
+ ctools_include('plugins'); | |
+ $plugin_types = ctools_plugin_get_plugin_type_info(); | |
+ foreach ($plugin_types['ultimate_cron'] as $plugin_type => $info) { | |
+ foreach (ultimate_cron_plugin_load_all($plugin_type) as $name => $plugin) { | |
+ if ($plugin->isValid() && method_exists($plugin, 'cleanup')) { | |
+ $items["ultimate_cron_plugin_{$plugin_type}_{$name}_cleanup"] = array( | |
+ 'title' => t('Ultimate Cron @type @title cleanup', array( | |
+ '@type' => $info['defaults']['static']['title singular proper'], | |
+ '@title' => $plugin->title, | |
+ )), | |
+ 'callback' => 'ultimate_cron_plugin_cleanup', | |
+ 'callback arguments' => array( | |
+ 'type' => $plugin_type, | |
+ 'name' => $name, | |
+ ), | |
+ ); | |
+ } | |
+ } | |
+ } | |
+ | |
+ return $items; | |
+} | |
+ | |
+// ---------- FIXUPS FOR CORE ---------- | |
+ | |
+/** | |
+ * Implements hook_cron_alter(). | |
+ * | |
+ * Add better description to core modules. | |
+ */ | |
+function ultimate_cron_cron_alter(&$hooks) { | |
+ $update['dblog_cron']['title'] = t('Remove expired log messages and flood control events'); | |
+ $update['field_cron']['title'] = t('Purges deleted Field API data'); | |
+ $update['filter_cron']['title'] = t('Expire outdated filter cache entries'); | |
+ $update['node_cron']['title'] = t('Mark old nodes as read'); | |
+ $update['search_cron']['title'] = t('Update indexes'); | |
+ $update['system_cron']['title'] = t('Cleanup (caches, batch, flood, temp-files, etc.)'); | |
+ $update['aggregator_cron']['title'] = t('Refresh feeds'); | |
+ $update['openid_cron']['title'] = t('Remove expired nonces from the database'); | |
+ $update['ping_cron']['title'] = t('Notify remote sites'); | |
+ $update['poll_cron']['title'] = t('Close expired polls'); | |
+ $update['statistics_cron']['title'] = t('Reset counts and clean up'); | |
+ $update['trigger_cron']['title'] = t('Run actions for cron triggers'); | |
+ $update['tracker_cron']['title'] = t('Update tracker index'); | |
+ $update['update_cron']['title'] = t('Check system for updates'); | |
+ $update['dblog_cron']['configure'] = 'admin/config/development/logging'; | |
+ $update['ctools_cron']['title'] = t('Clean up old caches'); | |
+ | |
+ $update['system_cron']['scheduler']['crontab'] = array('rules' => array('0+@ */3 * * *')); | |
+ $update['system_cron']['scheduler']['simple'] = array('rules' => array('0+@ */3 * * *')); | |
+ | |
+ foreach ($update as $name => $data) { | |
+ if (isset($hooks[$name])) { | |
+ $hooks[$name] = array_replace_recursive($hooks[$name], $data); | |
+ } | |
+ } | |
+} | |
diff --git a/ultimate_cron.module b/ultimate_cron.module | |
index 941b238..cae60ec 100755 | |
--- a/ultimate_cron.module | |
+++ b/ultimate_cron.module | |
@@ -730,13 +730,48 @@ function ultimate_cron_flush_caches() { | |
*/ | |
function ultimate_cron_hook_info() { | |
$hooks = array(); | |
- $hooks['background_process_shutdown'] = array( | |
- 'group' => 'background_process_legacy', | |
+ | |
+ // Add all easy hooks to cron group. | |
+ $easy_hooks = ultimate_cron_get_easy_hooks(); | |
+ | |
+ // Always ensure hook_cron() plus more is present in group. | |
+ $easy_hooks += array( | |
+ 'cron' => array(), | |
+ 'cron_alter' => array(), | |
+ 'cronapi' => array(), | |
); | |
+ | |
+ foreach (array_keys($easy_hooks) as $name) { | |
+ $hooks[$name] = array('group' => 'cron'); | |
+ } | |
+ $hooks['cron_easy_hooks'] = array('group' => 'cron'); | |
+ $hooks['cron_easy_hooks_alter'] = array('group' => 'cron'); | |
+ $hooks['cron_pre_schedule'] = array('group' => 'cron'); | |
+ $hooks['cron_post_schedule'] = array('group' => 'cron'); | |
+ $hooks['cron_pre_launch'] = array('group' => 'cron'); | |
+ $hooks['cron_post_launch'] = array('group' => 'cron'); | |
+ $hooks['cron_pre_run'] = array('group' => 'cron'); | |
+ $hooks['cron_post_run'] = array('group' => 'cron'); | |
+ $hooks['cron_pre_invoke'] = array('group' => 'cron'); | |
+ $hooks['cron_post_invoke'] = array('group' => 'cron'); | |
+ $hooks['ultimate_cron_plugin_build_operations_alter'] = array('group' => 'cron'); | |
+ | |
return $hooks; | |
} | |
/** | |
+ * Implements hook_hook_info_alter(). | |
+ */ | |
+function ultimate_cron_hook_info_alter(&$hooks) { | |
+ if (module_exists('background_process')) { | |
+ $info = system_get_info('module', 'background_process'); | |
+ if (!empty($info['dependencies']) && in_array('progress', $info['dependencies'])) { | |
+ $hooks['background_process_shutdown']['group'] = 'background_process'; | |
+ } | |
+ } | |
+} | |
+ | |
+/** | |
* Implements hook_init(). | |
* | |
* Make sure we have the proper "last run" of cron in global $conf | |
@@ -937,37 +972,6 @@ function ultimate_cron_plugin_cleanup($job, $arguments) { | |
} | |
/** | |
- * Implements hook_cronapi(). | |
- * | |
- * Adds clean up jobs for plugins. | |
- */ | |
-function ultimate_cron_cronapi() { | |
- $items = array(); | |
- | |
- ctools_include('plugins'); | |
- $plugin_types = ctools_plugin_get_plugin_type_info(); | |
- foreach ($plugin_types['ultimate_cron'] as $plugin_type => $info) { | |
- foreach (ultimate_cron_plugin_load_all($plugin_type) as $name => $plugin) { | |
- if ($plugin->isValid() && method_exists($plugin, 'cleanup')) { | |
- $items["ultimate_cron_plugin_{$plugin_type}_{$name}_cleanup"] = array( | |
- 'title' => t('Ultimate Cron @type @title cleanup', array( | |
- '@type' => $info['defaults']['static']['title singular proper'], | |
- '@title' => $plugin->title, | |
- )), | |
- 'callback' => 'ultimate_cron_plugin_cleanup', | |
- 'callback arguments' => array( | |
- 'type' => $plugin_type, | |
- 'name' => $name, | |
- ), | |
- ); | |
- } | |
- } | |
- } | |
- | |
- return $items; | |
-} | |
- | |
-/** | |
* Implements hook_watchdog(). | |
* | |
* Capture watchdog messages and send them to the loggers. | |
@@ -978,41 +982,6 @@ function ultimate_cron_watchdog(array $log_entry) { | |
} | |
} | |
-// ---------- FIXUPS FOR CORE ---------- | |
- | |
-/** | |
- * Implements hook_cron_alter(). | |
- * | |
- * Add better description to core modules. | |
- */ | |
-function ultimate_cron_cron_alter(&$hooks) { | |
- $update['dblog_cron']['title'] = t('Remove expired log messages and flood control events'); | |
- $update['field_cron']['title'] = t('Purges deleted Field API data'); | |
- $update['filter_cron']['title'] = t('Expire outdated filter cache entries'); | |
- $update['node_cron']['title'] = t('Mark old nodes as read'); | |
- $update['search_cron']['title'] = t('Update indexes'); | |
- $update['system_cron']['title'] = t('Cleanup (caches, batch, flood, temp-files, etc.)'); | |
- $update['aggregator_cron']['title'] = t('Refresh feeds'); | |
- $update['openid_cron']['title'] = t('Remove expired nonces from the database'); | |
- $update['ping_cron']['title'] = t('Notify remote sites'); | |
- $update['poll_cron']['title'] = t('Close expired polls'); | |
- $update['statistics_cron']['title'] = t('Reset counts and clean up'); | |
- $update['trigger_cron']['title'] = t('Run actions for cron triggers'); | |
- $update['tracker_cron']['title'] = t('Update tracker index'); | |
- $update['update_cron']['title'] = t('Check system for updates'); | |
- $update['dblog_cron']['configure'] = 'admin/config/development/logging'; | |
- $update['ctools_cron']['title'] = t('Clean up old caches'); | |
- | |
- $update['system_cron']['scheduler']['crontab'] = array('rules' => array('0+@ */3 * * *')); | |
- $update['system_cron']['scheduler']['simple'] = array('rules' => array('0+@ */3 * * *')); | |
- | |
- foreach ($update as $name => $data) { | |
- if (isset($hooks[$name])) { | |
- $hooks[$name] = array_replace_recursive($hooks[$name], $data); | |
- } | |
- } | |
-} | |
- | |
// ---------- CALLBACK FUNCTIONS ---------- | |
/** | |
@@ -1167,12 +1136,13 @@ function _ultimate_cron_variable_save($name, $value) { | |
* @return array | |
* Easy hooks. | |
*/ | |
-function ultimate_cron_easy_hooks() { | |
+function ultimate_cron_get_easy_hooks() { | |
static $easy_hooks; | |
if (isset($easy_hooks)) { | |
return $easy_hooks; | |
} | |
+ // Default provided easy hooks. | |
$easy_hooks = array( | |
'cron' => array( | |
'title' => 'Default cron job', | |
@@ -1232,8 +1202,13 @@ function ultimate_cron_easy_hooks() { | |
), | |
), | |
); | |
+ | |
+ // Allow modules to define their own easy hooks. | |
$easy_hooks += module_invoke_all('cron_easy_hooks'); | |
+ | |
+ // Allow modules to alter the defined easy hooks. | |
drupal_alter('cron_easy_hooks', $easy_hooks); | |
+ | |
return $easy_hooks; | |
} | |
@@ -1338,7 +1313,7 @@ function ultimate_cron_get_module_hooks($module) { | |
$items["{$module}_cron"]['tags'][] = 'core'; | |
} | |
- foreach (ultimate_cron_easy_hooks() as $name => $easy_hook) { | |
+ foreach (ultimate_cron_get_easy_hooks() as $name => $easy_hook) { | |
$hook_name = "{$module}_{$name}"; | |
if (module_hook($module, $name)) { | |
if (empty($items[$hook_name])) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment