You are here

function hosting_migrate_platform in Hosting 7.3

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

Batch migration of sites between platforms.

1 string reference to 'hosting_migrate_platform'
hosting_migrate_hosting_tasks in migrate/hosting_migrate.module
Implements hook_hosting_tasks().

File

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

Code

function hosting_migrate_platform($form, $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 = :status AND verified > :verified AND platform = :platform", array(
      ':status' => HOSTING_SITE_ENABLED,
      ':verified' => 0,
      ':platform' => $node->nid,
    ))
      ->fetch();
    if ($result->site_count == 0) {
      $form['no_sites'] = array(
        '#markup' => t('This platform does not have any sites that can be migrated.'),
      );
      return $form;
    }

    // TODO: hosting_get_enabled_platforms should be sufficient here, except
    // that we haven't implemented node-level access control on platforms yet.
    // See: http://drupal.org/node/725952.
    if (function_exists('_hosting_get_allowed_platforms')) {
      $platforms = _hosting_get_allowed_platforms();
    }
    else {
      $platforms = _hosting_get_enabled_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(
        '#markup' => 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 (isset($form_state['storage'][$type]) && sizeof($form_state['storage'][$type])) {
        $rows = array();
        foreach ($form_state['storage'][$type] as $site_id => $url) {
          $form['output'][$type]['title'] = array(
            '#type' => 'markup',
            '#markup' => '<h2>' . $title[$type] . '</h2>',
          );
          $status = $form_state['storage']['status'][$site_id];
          $row = array(
            array(
              'data' => $url,
              'class' => array(
                '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' => array(
              'hosting-' . _hosting_migrate_site_list_class($status),
            ),
          );
        }
        $form['output'][$type]['table'] = array(
          '#type' => 'markup',
          '#markup' => theme('table', array(
            'header' => $header,
            'rows' => $rows,
            'attributes' => array(
              'class' => array(
                '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'])) {
      if (module_exists('overlay')) {
        overlay_close_dialog();
      }
    }
    else {
      drupal_goto('node/' . $form_state['storage']['target_platform']);
    }
  }
  return $form;
}