From 3c6ab77298a75292ff6179a63bdff071b9fa29ca Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Thu, 6 Jan 2011 22:06:12 +0000
Subject: [PATCH] [gh-68] Merging from testing to staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@406 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 sites/all/modules/unl/unl_site_creation.php | 29 ++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/sites/all/modules/unl/unl_site_creation.php b/sites/all/modules/unl/unl_site_creation.php
index 1c7b11d0..b8169cef 100644
--- a/sites/all/modules/unl/unl_site_creation.php
+++ b/sites/all/modules/unl/unl_site_creation.php
@@ -164,9 +164,15 @@ function unl_site_updates($form, &$form_state) {
     '#description' => 'Using drush, do database updates and clear the caches of all sites.',
   );
   
+  if ($form_state['rebuild']) {
+    $button_text = 'Continue Drush';
+  }
+  else {
+    $button_text = 'Run Drush';
+  } 
   $form['root']['submit'] = array(
     '#type'  => 'submit',
-    '#value' => 'Run Drush',
+    '#value' => $button_text,
   );
   
   return $form;
@@ -178,11 +184,32 @@ function unl_site_updates_submit($form, &$form_state) {
     ->execute()
     ->fetchAll();
   
+  $start_time = time();
+  if (isset($form_state['storage'])) {
+    $completed_sites = $form_state['storage'];
+  }
+  else {
+    $completed_sites = array();
+  }
+  
   foreach ($sites as $site) {
+    if (in_array($site->uri, $completed_sites)) {
+      continue;
+    }
+  
+    if (time() - $start_time > 30) {
+      $form_state['rebuild'] = TRUE;
+      $form_state['storage'] = $completed_sites;
+      drupal_set_message('Drush ran out of time to process every site. Click "Continue Drush" below.', 'warning');
+      return;
+    }
+    
     $uri = escapeshellarg($site->uri);
     $root = escapeshellarg(DRUPAL_ROOT);
     $command = "sites/all/modules/drush/drush.php -y --token=secret --root={$root} --uri={$uri} updatedb";
     drupal_set_message('Messages from ' . $site->uri . ':<br />' . PHP_EOL . '<pre>' . shell_exec($command) . '</pre>', 'status');
+    
+    $completed_sites[] = $site->uri;
   }
 }
 
-- 
GitLab