You are here

function hosting_migrate_platform in Hostmaster (Aegir) 6

Batch migration of sites between platforms.

1 string reference to 'hosting_migrate_platform'
hosting_migrate_hosting_tasks in modules/hosting/migrate/hosting_migrate.module
Implementation of hook_hosting_tasks().

File

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

Code

function hosting_migrate_platform($form_state, $node) {
  drupal_add_js(drupal_get_path('module', 'hosting_migrate') . '/hosting_migrate.js');
  $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] : 1;

  // Step 1 - choose target platform
  if ($step == 1) {
    $result = db_query("SELECT count(nid) as site_count FROM {hosting_site} WHERE status=%d AND verified > 0 AND platform=%d", HOSTING_SITE_ENABLED, $node->nid);
    if ($obj = db_fetch_object($result)) {
      if ($obj->site_count == 0) {
        $form['error'] = array(
          '#type' => 'markup',
          '#value' => t('This platform does not have any sites that can be migrated.'),
        );
        return $form;
      }
    }
    $platforms = _hosting_get_platforms();
    if (sizeof($platforms) > 1) {
      unset($platforms[$node->nid]);
      $form['#current_platform'] = $node;
      $form['description'] = array(
        '#type' => 'item',
        '#description' => 'Perform a batch migration of sites from this platform to a target platform.',
      );
      $form['target_platform'] = array(
        '#type' => 'radios',
        '#required' => TRUE,
        '#title' => t('Platform'),
        '#description' => t('Choose where you want to migrate the sites on this platform to'),
        '#options' => $platforms,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
      );
    }
    else {
      $form['no_platforms'] = array(
        '#type' => 'item',
        '#description' => t('There are no alternate platforms to migrate to.'),
      );
    }
  }

  // Step 2 - review sites that pass or fail the requirements to be migrated
  if ($step == 2) {
    $title = array(
      'passed' => t("The following sites will be migrated"),
      'failed' => t("The following sites will not be migrated"),
    );
    $header = array(
      t('Site'),
      t('Upgrades'),
      t('Warnings'),
      t('Errors'),
      t('Actions'),
    );
    $options['attributes']['class'] = 'hosting-package-comparison-link';
    foreach (array(
      'passed',
      'failed',
    ) as $type) {
      if (sizeof($form_state['storage'][$type])) {
        $rows = array();
        foreach ($form_state['storage'][$type] as $site_id => $url) {
          $form['output'][$type]['title'] = array(
            '#type' => 'markup',
            '#value' => '<h2>' . $title[$type] . '</h2>',
          );
          $status = $form_state['storage']['status'][$site_id];
          $row = array(
            array(
              'data' => $url,
              'class' => 'hosting-status',
            ),
            $status['upgrade'],
            $status['missing'],
            $status['error'],
          );
          if (isset($form_state['storage']['instance'][$site_id])) {
            $link = l(t('Compare'), 'hosting/migrate/compare/' . $node->nid . '/' . $form_state['storage']['instance'][$site_id], $options);
          }
          else {
            $link = t('Profile not found');
          }
          $row[] = $link;
          $rows[] = array(
            'data' => $row,
            'class' => 'hosting-' . _hosting_migrate_site_list_class($status),
          );
        }
        $form['output'][$type]['table'] = array(
          '#type' => 'markup',
          '#value' => theme('table', $header, $rows, array(
            'class' => 'hosting-table',
          )),
        );
      }
    }
    if (sizeof($form_state['storage']['passed'])) {
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
      );
    }
  }

  // Step 3 - All migrate tasks have been created, close the modal if needed.
  if ($step == 3) {
    if (!empty($GLOBALS['modalframe_page_template'])) {
      modalframe_close_dialog();
    }
    else {
      drupal_goto('node/' . $form_state['storage']['target_platform']);
    }
  }
  return $form;
}