diff --git a/sites/all/modules/unl/unl_site_creation.php b/sites/all/modules/unl/unl_site_creation.php index b8169cefdb23ab673363e5763c52e52478bb090f..ea72be0cb6bd86ad3978cfec087dabcdf937b969 100644 --- a/sites/all/modules/unl/unl_site_creation.php +++ b/sites/all/modules/unl/unl_site_creation.php @@ -164,15 +164,9 @@ 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' => $button_text, + '#value' => 'Run Drush', ); return $form; @@ -184,33 +178,24 @@ 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(); - } + $operations = 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; + $operations[] = array('unl_site_updates_step', array($site->uri)); } + + $batch = array( + 'operations' => $operations, + 'file' => substr(__FILE__, strlen(DRUPAL_ROOT) + 1), + ); + batch_set($batch); +} + +function unl_site_updates_step($site_uri, &$context) { + $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'); }