? drupal_cron-19173-47-axyjo.patch ? drupal_cron-19173-50.patch Index: cron.php =================================================================== RCS file: /cvs/drupal/drupal/cron.php,v retrieving revision 1.42 diff -u -p -r1.42 cron.php --- cron.php 8 Feb 2009 20:27:51 -0000 1.42 +++ cron.php 2 Aug 2009 04:07:09 -0000 @@ -4,6 +4,8 @@ /** * @file * Handles incoming requests to fire off regularly-scheduled tasks (cron jobs). + * Takes one parameter, include or exclude, which contains a comma separated + * list of modules to either include or exclude from the cron run. */ /** @@ -14,7 +16,27 @@ define('DRUPAL_ROOT', getcwd()); include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (isset($_GET['cron_key']) && variable_get('cron_key', 'drupal') == $_GET['cron_key']) { - drupal_cron_run(); + if (isset($_GET['include'])) $include = $_GET['include']; + if (isset($_GET['exclude'])) $exclude = $_GET['exclude']; + + if (isset($include) && isset($exclude)) { + watchdog('cron', t('Cron has been issued both the include and the exclude parameters.'), array(), WATCHDOG_ERROR); + return false; + } + elseif (isset($include) && !isset($exclude)) { + $cron_param = $include; + $mode = 'include'; + } + elseif (!isset($include) && isset($exclude)) { + $cron_param = $exclude; + $mode = 'exclude'; + } + else { + $cron_param = ''; + $mode = ''; + } + + drupal_cron_run($cron_param, $mode); } else { watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE); Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.951 diff -u -p -r1.951 common.inc --- includes/common.inc 31 Jul 2009 19:56:09 -0000 1.951 +++ includes/common.inc 2 Aug 2009 04:07:11 -0000 @@ -3551,7 +3551,7 @@ function drupal_page_set_cache() { * @return * Returns TRUE if ran successfully */ -function drupal_cron_run() { +function drupal_cron_run($list = '', $mode = '', $delimiter = ',') { // Allow execution to continue even if the request gets canceled. @ignore_user_abort(TRUE); @@ -3583,13 +3583,59 @@ function drupal_cron_run() { // Lock cron semaphore variable_set('cron_semaphore', REQUEST_TIME); + + // Create $cron_message so that it is defined. + $cron_message = ''; // Iterate through the modules calling their cron handlers (if any): - module_invoke_all('cron'); + if ($list == '' && $mode == '') { + // No parameters were passed, so we're running all modules + module_invoke_all('cron'); + watchdog('cron', t('Cron run completed for all modules.'), array(), WATCHDOG_NOTICE); + } + elseif($list != '' && $mode == 'include') { + $module_list = module_list(); + $cron_modules = explode($delimiter, $list); + // Get only a list of modules that are specified AND enabled + $run_array = array_intersect($module_list, $cron_modules); + foreach($run_array as $run_module) { + module_invoke($run_module, 'cron'); + $cron_message .= t($run_module).', '; + } + // Remove the extra ', ' from the end of the string + $cron_message = substr($cron_message, 0, -2); + if ($cron_message != '') { + watchdog('cron', t('Cron run completed for modules: @cron_message.', array('@cron_message' => $cron_message)), array(), WATCHDOG_NOTICE); + } + else { + watchdog('cron', t('Cron did not run because no valid modules were specified.'), array(), WATCHDOG_ERROR); + } + } + elseif($list != '' && $mode == 'exclude') { + $module_list = module_list(); + $cron_modules = explode($delimiter, $list); + // Get only a list of modules that are NOT specified but enabled. + $run_array = array_diff($module_list, $cron_modules); + foreach($run_array as $run_module) { + module_invoke($run_module, 'cron'); + $cron_message .= t($run_module).', '; + } + // Remove the extra ', ' from the end of the string + $cron_message = substr($cron_message, 0, -2); + if ($cron_message != '') { + watchdog('cron', t('Cron run completed for modules: @cron_message.', array('@cron_message' => $cron_message)), array(), WATCHDOG_NOTICE); + } + else { + watchdog('cron', t('Cron did not run because no valid modules were specified.'), array(), WATCHDOG_ERROR); + } + } + else { + // Catch anything that's not covered already. + return false; + } // Record cron time variable_set('cron_last', REQUEST_TIME); - watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE); // Release cron semaphore variable_del('cron_semaphore'); Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.61 diff -u -p -r1.61 system.test --- modules/system/system.test 31 Jul 2009 11:20:43 -0000 1.61 +++ modules/system/system.test 2 Aug 2009 04:07:12 -0000 @@ -379,6 +379,14 @@ class CronRunTestCase extends DrupalWebT $key = variable_get('cron_key', 'drupal'); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => 'cron_key=' . $key)); $this->assertResponse(200); + + // Run cron with an include parameter. + $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'include' => 'system'))); + $this->assertResponse(200); + + // Run cron with an exclude parameter. + $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'exclude' => 'system'))); + $this->assertResponse(200); // Execute cron directly. $this->assertTrue(drupal_cron_run(), t('Cron ran successfully.'));