You are here

function hosting_site_list_form_submit in Hostmaster (Aegir) 6

Process hosting_site_list form submissions.

1 string reference to 'hosting_site_list_form_submit'
hosting_site_list_form in modules/hosting/site/hosting_site.module
Create a form for building a list of sites. @TODO Add ability to filter by additional fields

File

modules/hosting/site/hosting_site.module, line 629

Code

function hosting_site_list_form_submit($form, &$form_state) {
  $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] : 1;
  $task = $form_state['values']['task'];
  switch ($step) {
    case 1:
      $form_state['storage']['task'] = $task;

      // Verify tasks can be performed on each site.
      $tasks = hosting_available_tasks('site');

      // Filter out unchecked sites
      $sites = array_filter($form_state['values']['sites']);
      $operations = array();
      foreach ($sites as $site) {
        $operations[] = array(
          'hosting_sites_batch_process',
          array(
            $site,
            $task,
          ),
        );
      }
      if (sizeof($operations)) {
        $batch = array(
          'operations' => $operations,
          'title' => t('Processing'),
          'progress_message' => t('Evaluated @current out of @total sites.'),
          'error_message' => t('The update has encountered an error.'),
        );
        batch_set($batch);
      }
      break;
    case 2:
      $values = $form_state['values'];
      foreach ($form_state['storage']['passed'] as $site_id => $url) {
        hosting_add_task($site_id, $form_state['storage']['task'], $values['parameters']);
      }
      unset($form_state['storage']);
      $step = 0;
      drupal_set_message(t('The task @task will be applied to the selected sites and have been added to the task queue.', array(
        '@task' => $form_state['storage']['task'],
      )));
      break;
  }
  $form_state['storage']['step'] = $step + 1;
}