You are here

function hosting_migrate_platform_submit in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 migrate/hosting_migrate.batch.inc \hosting_migrate_platform_submit()
  2. 7.3 migrate/hosting_migrate.batch.inc \hosting_migrate_platform_submit()

Implements hook_submit().

File

migrate/hosting_migrate.batch.inc, line 139
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 = :platform AND s.status = :status and s.verified > :verified ORDER BY n.title", array(
        ':platform' => $form['#current_platform']->nid,
        ':status' => HOSTING_SITE_ENABLED,
        ':verified' => 0,
      ));
      $operations = array();
      while ($site = $result
        ->fetch()) {
        $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['rebuild'] = TRUE;
  $form_state['storage']['step'] = $step + 1;
}