You are here

function acquia_agent_migrate_form in Acquia Connector 6.2

Same name and namespace in other branches
  1. 7.2 acquia_agent/acquia_agent.pages.inc \acquia_agent_migrate_form()

Migration start form

1 string reference to 'acquia_agent_migrate_form'
acquia_agent_migrate_page in acquia_agent/acquia_agent.pages.inc
Migrate site to Acquia Cloud

File

acquia_agent/acquia_agent.pages.inc, line 90
Acquia Agent configuration page.

Code

function acquia_agent_migrate_form(&$form_state) {
  $identifier = acquia_agent_settings('acquia_identifier');
  $key = acquia_agent_settings('acquia_key');
  $data = acquia_agent_call('acquia.agent.cloud.migration.environments', array(
    'identifier' => $identifier,
  ), $identifier, $key, variable_get('acquia_network_address', 'https://rpc.acquia.com'));
  $error = NULL;
  if ($errno = xmlrpc_errno()) {
    acquia_agent_report_xmlrpc_error();
    drupal_goto('admin/settings/acquia-agent');
  }
  elseif (!$data || empty($data['result'])) {
    $error = t('Server error, unable to retrieve environments for migration');
  }
  else {

    // Response is in $data['result'].
    $result = $data['result'];
    if (!empty($result['is_error'])) {
      $error = t('Server error, unable to retrieve environments for migration');
    }
    elseif (!empty($result['body']['error'])) {
      $error = $result['body']['error'];
    }
    elseif (empty($result['body']['environments'])) {
      $error = t('Server error, unable to retrieve environments for migration');
    }
  }
  if ($error) {
    drupal_set_message($error, 'error');
    drupal_goto('admin/settings/acquia-agent');
  }
  foreach ($result['body']['environments'] as $stage => $env) {
    $result['body']['environments'][$stage]['secret'] = base64_decode($env['secret']);
  }
  $form['envs'] = array(
    '#type' => 'value',
    '#value' => $result['body']['environments'],
  );
  $envs = array();
  foreach (array_keys($result['body']['environments']) as $env) {
    $envs[$env] = drupal_ucfirst($env);
  }
  if (count($result['body']['environments']) > 1) {
    $form['environment'] = array(
      '#type' => 'select',
      '#title' => t('Select environment for migration'),
      '#options' => $envs,
      '#description' => t('Select which environment your site should be migrated to.
        Please note that only environments that are running trunk or branch can
        be overwritten by migration. Environments running a tag are not included.'),
    );
  }
  else {
    $form['environment'] = array(
      '#value' => t('<p>Available environment for migration: %env</p>', array(
        '%env' => array_pop($envs),
      )),
    );
  }
  $form['migrate_files'] = array(
    '#type' => 'checkbox',
    '#title' => t('Migrate files directory'),
    '#description' => t('Include files directory and all files in migration. If you are experiencing migration errors it is recommended you do not send the files directory.'),
    '#default_value' => variable_get('acquia_migrate_files', 1),
  );
  $form['reduce_db_size'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reduce database export size'),
    '#description' => t('Reduce the database export size by excluding the data from cache, session, and watchdog tables. If you are experiencing migration errors this is recommended. Table structure will still be exported.'),
    '#default_value' => 0,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Migrate'),
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#submit' => array(
      'acquia_agent_migrate_cancel_submit',
    ),
  );
  return $form;
}