You are here

function hosting_migrate_platform_submit in Hostmaster (Aegir) 6

Implements hook_submit().

File

modules/hosting/migrate/hosting_migrate.batch.inc, line 130
Implemented batch migration of sites.

Code

function hosting_migrate_platform_submit($form, &$form_state) {
  $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] : 1;
  switch ($step) {
    case 1:
      $form_state['storage']['current_platform'] = $form['#current_platform']->nid;
      $form_state['storage']['target_platform'] = $form_state['values']['target_platform'];
      $max_per_batch = 5;
      $result = db_query("SELECT n.nid, n.title FROM  {hosting_site} s LEFT JOIN {node} n ON n.nid=s.nid WHERE platform = %d AND s.status = %d and s.verified > 0 ORDER BY n.title", $form['#current_platform']->nid, HOSTING_SITE_ENABLED);
      $operations = array();
      while ($site = db_fetch_object($result)) {
        $operations[] = array(
          'hosting_migrate_platform_batch',
          array(
            $site->nid,
            $form_state['values']['target_platform'],
            $form_state,
          ),
        );
      }
      if (sizeof($operations)) {
        $batch = array(
          'operations' => $operations,
          'finished' => 'hosting_migrate_platform_finished',
          'title' => t('Checking for sites that can be migrated.'),
          'init_message' => t('Retrieving list of sites.'),
          'progress_message' => t('Evaluated @current out of @total sites.'),
          'error_message' => t('Bulk migration has encountered an error.'),
          'file' => drupal_get_path('module', 'hosting_migrate') . '/hosting_migrate.batch.inc',
        );
        batch_set($batch);
        if (!empty($GLOBALS['modalframe_page_template'])) {
          $batch =& batch_get();
          $batch['url'] = 'hosting/js/batch';
          $batch['source_page'] = 'hosting/js/' . $_GET['q'];
        }
      }
      break;
    case 2:

      // Create a task node for logging purposes.
      $current = $form_state['storage']['current_platform'];
      $target = $form_state['storage']['target_platform'];
      $task = hosting_add_task($current, 'migrate', array(
        'target_platform' => $target,
      ), HOSTING_TASK_SUCCESS);
      $operations = array();
      foreach ($form_state['storage']['passed'] as $nid => $url) {
        $operations[] = array(
          'hosting_migrate_platform_submit_batch',
          array(
            $nid,
            $form_state['storage']['target_platform'],
            $url,
            $task->vid,
          ),
        );
      }
      if (sizeof($operations)) {
        $batch = array(
          'operations' => $operations,
          'finished' => 'hosting_migrate_platform_submit_finished',
          'title' => t('Submitting sites for migration.'),
          'init_message' => t('Retrieving list of sites.'),
          'progress_message' => t('Submitted @current out of @total sites.'),
          'error_message' => t('Bulk migration has encountered an error.'),
          'file' => drupal_get_path('module', 'hosting_migrate') . '/hosting_migrate.batch.inc',
        );
        batch_set($batch);
        if (!empty($GLOBALS['modalframe_page_template'])) {
          $batch =& batch_get();
          $batch['url'] = 'hosting/js/batch';
          $batch['source_page'] = 'hosting/js/' . $_GET['q'];
        }
      }
      break;
  }
  $form_state['storage']['step'] = $step + 1;
}