View source
<?php
function hosting_migrate_hosting_tasks($node) {
$options = array();
if ($node->type == 'site') {
if ($node->site_status == HOSTING_SITE_ENABLED) {
$options['migrate'] = array(
'title' => t('Migrate'),
'description' => t('Move the site to a new platform.'),
'weight' => 7,
);
}
}
return $options;
}
function hosting_migrate_perm() {
return array(
'create migrate task',
);
}
function theme_hosting_task_migrate_form(&$form) {
$node = $form['#node'];
$packages = $form['#packages'];
$headers = array();
$rows = array();
$headers[] = t("Type");
$headers[] = t("Package");
$errors = array();
$warnings = array();
foreach (array_keys($packages[$node->platform]) as $package) {
$row = array();
$row[] = array(
'class' => 'hosting-package-name',
'data' => $packages[$node->platform][$package]->package_type,
);
$row[] = array(
'class' => 'hosting-package-name',
'data' => $packages[$node->platform][$package]->title,
);
foreach (array_keys($packages) as $platform) {
if (array_key_exists($package, $packages[$platform])) {
$comparison = hosting_package_instance_version_compare($packages[$node->platform][$package], $packages[$platform][$package]);
$display = $packages[$platform][$package]->version;
if ($packages[$platform][$package]->schema_version) {
$display .= " (" . $packages[$platform][$package]->schema_version . ")";
}
if ($comparison > 0) {
$row[] = array(
'class' => 'hosting-package-upgrade',
'data' => $display,
);
}
elseif ($comparison == 0) {
$row[] = array(
'class' => 'hosting-package-same',
'data' => $display,
);
}
else {
$row[] = array(
'class' => 'hosting-package-downgrade',
'data' => $display,
);
$errors[$platform] = TRUE;
}
}
else {
$row[] = array(
'class' => 'hosting-package-missing',
'data' => t("Missing"),
);
$warnings[$platform] = TRUE;
}
}
$rows[] = $row;
}
foreach (array_keys($packages) as $platform) {
$header = array();
$header['class'] = 'hosting-package-upgrade';
if ($platform == $node->platform) {
$header['class'] = 'hosting-package-same';
}
elseif (array_key_exists($platform, $errors)) {
$header['class'] = 'hosting-package-downgrade';
$form['radios'][$platform]['parameters']['target_platform']['#attributes']['disabled'] = 'disabled';
}
elseif (array_key_exists($platform, $warnings)) {
$header['class'] = 'hosting-package-missing';
}
$header['data'] = drupal_render($form['radios'][$platform]['parameters']['target_platform']);
$headers[] = $header;
}
$output .= "<div id='hosting-package-comparison'>" . theme('table', $headers, $rows) . "</div>";
$output .= drupal_render($form);
return $output;
}
function hosting_task_migrate_form_validate($form_id, $form_values, $form, $site) {
if (!$form_values['parameters']['target_platform']) {
form_set_error('parameters][target_platform', t('You need to select a valid platform to migrate your site to.'));
}
if ($form_values['parameters']['target_platform'] == $site->platform) {
form_set_error('parameters][target_platform', t('You may not select your current platform to migrate your site to.'));
}
}
function hosting_task_migrate_form($node) {
$site_instances = hosting_package_instances_load(array(
'rid' => $node->nid,
'i.status' => 1,
));
$site_platform = node_load($node->platform);
$cols = array();
$packages = array();
$form['radios']['#tree'] = false;
$form['radios'][$node->platform]['parameters']['#tree'] = TRUE;
$form['radios'][$node->platform]['parameters']['target_platform'] = array(
'#type' => 'radio',
'#title' => t('Current'),
'#default_value' => $node->platform,
'#disabled' => TRUE,
"#return_value" => $node->platform,
);
foreach ($site_instances as $instance) {
$packages[$node->platform][$instance->package_id] = $instance;
}
$profile_platform_instances = hosting_package_instances_load(array(
'r.type' => 'platform',
'n.nid' => $node->profile,
));
if (sizeof($profile_platform_instances) <= 1) {
$form['no_targets'] = array(
'#value' => t('<br />There are no platforms that can meet the depdendencies for this site'),
);
return $form;
}
foreach ($profile_platform_instances as $profile_instance) {
if ($profile_instance->rid != $node->platform) {
$platform = node_load($profile_instance->rid);
if ($platform->web_server == $site_platform->web_server) {
$form['radios'][$platform->nid]['parameters']['#tree'] = TRUE;
$form['radios'][$platform->nid]['parameters']['target_platform'] = array(
'#type' => 'radio',
'#title' => $platform->title,
"#return_value" => $platform->nid,
);
$platform_instances = hosting_package_instances_load(array(
'rid' => $profile_instance->iid,
));
foreach ($platform_instances as $instance) {
$packages[$platform->nid][$instance->package_id] = $instance;
}
}
}
}
$form['#node'] = $node;
$form['#packages'] = $packages;
$form['#theme'] = 'hosting_task_migrate_form';
return $form;
$table = array();
if (sizeof($options)) {
$form['target_platform'] = array(
'#type' => 'radios',
'#title' => t('Migrate to'),
'#options' => $options,
'#required' => TRUE,
);
}
else {
$form['target_text'] = array(
'#type' => 'item',
'#value' => t('<strong>No valid platforms to migrate to.</strong>'),
);
}
return $form;
}