? .DS_Store
? drupal_cron-19173-40-axyjo.patch
? drupal_cron-19173-43-axyjo.patch
? drupal_cron-19173-44-axyjo.patch
? drupal_cron-19173-47-axyjo.patch
? drupal_cron-19173-54-axyjo.patch
? drupal_cron-19173-55-axyjo.patch
? sites/default/files
? sites/default/settings.php
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	8 Aug 2009 22:21:49 -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();
+  $include = (isset($_GET['include'])) ? $_GET['include'] : '';
+  $exclude = (isset($_GET['exclude'])) ? $_GET['exclude'] : '';
+
+  if ($include && $exclude) {
+    watchdog('cron', t('Cron has been issued both the include and the exclude parameters.'), array(), WATCHDOG_ERROR);
+    return FALSE;
+  }
+  elseif ($include && !$exclude) {
+    $cron_param = $include;
+    $mode = 'include';
+  }
+  elseif (!$include && $exclude) {
+    $cron_param = $exclude;
+    $mode = 'exclude';
+  }
+  else {
+    $cron_param = NULL;
+    $mode = NULL;
+  }
+
+  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.956
diff -u -p -r1.956 common.inc
--- includes/common.inc	8 Aug 2009 20:52:32 -0000	1.956
+++ includes/common.inc	8 Aug 2009 22:21:58 -0000
@@ -3610,11 +3610,25 @@ function drupal_page_set_cache() {
 }
 
 /**
- * Executes a cron run when called
+ * Executes a cron run when called.
+ *
+ * If the function is called with no arguments, then cron for all modules is
+ * run. If only one argument is passed in, the result is FALSE. If both
+ * arguments are provided, then the function includes or excludes the specified
+ * modules in the first argument.
+ *
+ * @param $list
+ *   A comma separated list of modules to act upon.
+ * @param $mode
+ *   The mode of the operation. One of the following values are possible:
+ *   - '' or NULL
+ *   - 'include'
+ *   - 'exclude'
+ *
  * @return
- * Returns TRUE if ran successfully
+ *   Returns TRUE if ran successfully.
  */
-function drupal_cron_run() {
+function drupal_cron_run($list = NULL, $mode = NULL) {
   // Allow execution to continue even if the request gets canceled.
   @ignore_user_abort(TRUE);
 
@@ -3630,7 +3644,7 @@ function drupal_cron_run() {
       // was not reset due to a database error.
       watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR);
 
-      // Release cron semaphore
+      // Release cron semaphore.
       variable_del('cron_semaphore');
     }
     else {
@@ -3639,23 +3653,56 @@ function drupal_cron_run() {
     }
   }
   else {
-    // Register shutdown callback
+    // Register shutdown callback.
     register_shutdown_function('drupal_cron_cleanup');
 
-    // Lock cron semaphore
+    // 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) {
+      $module_list = module_implements('cron');
+      $cron_modules = explode(',', $list);
+      $run_array = array();
+      if ($mode == 'include') {
+        // Get only a list of modules that are specified AND enabled.
+        $run_array = array_intersect($module_list, $cron_modules);
+      }
+      elseif ($mode == 'exclude') {
+        // Get only a list of modules that are NOT specified but enabled.
+        $run_array = array_diff($module_list, $cron_modules);
+      }
+      if ($run_array) {
+        foreach ($run_array as $module) {
+          module_invoke($module, 'cron');
+        }
+        $msg = implode(',', $run_array);
+        watchdog('cron', t('Cron run completed for modules: @ran.', array('@ran' => $msg)), 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
+    // Record cron time.
     variable_set('cron_last', REQUEST_TIME);
-    watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE);
 
-    // Release cron semaphore
+    // Release cron semaphore.
     variable_del('cron_semaphore');
 
-    // Return TRUE so other functions can check if it did run successfully
+    // Return TRUE so other functions can check if it did run successfully.
     return TRUE;
   }
 }
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.62
diff -u -p -r1.62 system.test
--- modules/system/system.test	5 Aug 2009 16:16:41 -0000	1.62
+++ modules/system/system.test	8 Aug 2009 22:22:01 -0000
@@ -385,7 +385,48 @@ 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 a single, valid include parameter.
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'include' => 'system')));
+    $this->assertResponse(200);
+    
+    // Run cron with a single, valid exclude parameter.
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'exclude' => 'system')));
+    $this->assertResponse(200);
+    
+    // Run cron with a single, invalid include parameter.
+    $name = $this->randomName(8);
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'include' => $name)));
+    $this->assertResponse(200);
+    
+    // Run cron with a single, invalid exclude parameter.
+    $name = $this->randomName(8);
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'exclude' => $name)));
+    $this->assertResponse(200);
+    
+    // Run cron with two include parameters where both are valid.
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'include' => 'system,node')));
+    $this->assertResponse(200);
+    
+    // Run cron with two exclude parameters where both are valid.
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'exclude' => 'system,node')));
+    $this->assertResponse(200);
+    
+    // Run cron with two include parameters where only one is valid.
+    $name = $this->randomName(8);
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'include' => 'system,'.$name)));
+    $this->assertResponse(200);
+    
+    // Run cron with two exclude parameters where only one is valid.
+    $name = $this->randomName(8);
+    $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key, 'exclude' => 'system,'.$name)));
+    $this->assertResponse(200);
+    
+    /*
+     * We can test all of these much better once we get assertLogMessage() into
+     * DrupalWebTestCase (see issue #500394).
+     */
+    
     // Execute cron directly.
     $this->assertTrue(drupal_cron_run(), t('Cron ran successfully.'));
   }
