You are here

function hosting_task_migrate_form in Hosting 7.4

Same name and namespace in other branches
  1. 5 migrate/hosting_migrate.module \hosting_task_migrate_form()
  2. 6.2 migrate/hosting_migrate.module \hosting_task_migrate_form()
  3. 7.3 migrate/hosting_migrate.module \hosting_task_migrate_form()

Implements hook_form().

2 calls to hosting_task_migrate_form()
hosting_task_clone_form in clone/hosting_clone.module
Implements hook_hosting_task_TASK_TYPE_form().
hosting_task_TASK_TYPE_form in task/hosting_task.api.php
Add fields to the task confirmation form.

File

migrate/hosting_migrate.module, line 122

Code

function hosting_task_migrate_form($node) {
  $node->check_profile_migrations = TRUE;
  $valid_options = hosting_site_available_options($node);
  $form['new_uri'] = array(
    '#title' => t('Domain name'),
    '#description' => t("Changing the domain name when migrating effectively 'renames' the site."),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#weight' => '-1',
    '#default_value' => hosting_site_canonical_url($node),
  );
  $db_servers = hosting_get_servers('db');
  if (sizeof($db_servers) > 1) {
    $form['new_db_server'] = array(
      '#type' => 'radios',
      '#title' => t('Database server'),
      '#required' => TRUE,
      '#description' => t('The database server the site will use to host its content.'),
      '#options' => $db_servers,
      '#default_value' => $node->db_server,
    );
  }
  else {
    $form['new_db_server'] = array(
      '#type' => 'hidden',
      '#value' => $node->db_server,
    );
  }
  drupal_add_js(drupal_get_path('module', 'hosting_migrate') . '/hosting_migrate.js');
  $packages = array();
  $site_profile = node_load($node->profile);
  $profile_platform_instances = hosting_package_instances_load(array(
    'r.type' => 'platform',
    'n.nid' => $node->profile,
    'h.status' => HOSTING_PLATFORM_ENABLED,
  ));

  // In the list of possible targets, we also include install profiles on platforms that
  // USED to be named the same as our current install profile. Such as the d6 -> d7 rename
  // of the default profile to standard.
  $profile_platform_instances = array_merge($profile_platform_instances, hosting_package_instances_load(array(
    'r.type' => 'platform',
    'p.old_short_name' => $site_profile->short_name,
  )));
  $site_platform = node_load($node->platform);
  $has_platform_available = FALSE;

  // Don't show the current platform if it's locked
  if (!_hosting_platform_is_locked($node->platform)) {
    $form[$node->platform]['target_platform'] = array(
      '#type' => 'radio',
      '#title' => check_plain($site_platform->title),
      "#return_value" => $node->platform,
      "#default_value" => $node->platform,
      '#description' => t("Current platform"),
      '#parents' => array(
        'parameters',
        'target_platform',
      ),
    );
    $has_platform_available = TRUE;
  }
  foreach ($profile_platform_instances as $profile_instance) {
    if ($profile_instance->rid != $node->platform && in_array($profile_instance->rid, $valid_options['platform'])) {
      $status = hosting_package_comparison($node->nid, $profile_instance->iid);
      $description = t("Upgrades: !upgrades, Warnings: !missing, Errors: !errors | <a href='!url' class='hosting-package-comparison-link'>Compare platforms</a>", array(
        '!upgrades' => $status['upgrade'],
        '!missing' => $status['missing'] + $status['downgrade'],
        '!errors' => $status['error'],
        '!url' => url('hosting/migrate/compare/' . $node->nid . '/' . $profile_instance->iid),
      ));
      $platform = node_load($profile_instance->rid);
      $form[$platform->nid]['target_platform'] = array(
        '#type' => 'radio',
        '#title' => check_plain($platform->title),
        '#parents' => array(
          'parameters',
          'target_platform',
        ),
        "#return_value" => $platform->nid,
        '#description' => $description,
      );
      if ($status['error']) {
        $form[$platform->nid]['target_platform']['#disabled'] = TRUE;
      }
      $has_platform_available = TRUE;
    }
  }
  if (!$has_platform_available) {
    form_set_error('parameters][target_platform', t("You have no platform available as target. Are they locked?"));
  }
  $form['#node'] = $node;
  return $form;
}