migrate.provision.inc 2.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php

/**
 * Restore command implementation
 *
 * This command when called will 
 *   1. Make a backup of the current site, before modifications are made.
 *   2. Temporarily disable the site by causing apache to redirect to a help page. Restarting apache is required.
 *   3. Extract the backup that is being migrated to to a temporary folder in the sites directory.
 *   4. Create a new database, belonging to the site's user, and switch it around with the current site's database.
 *   5. Import the old database and site.php details.
 *   6. Switch around the sites directory of the current site and the backup being migrated.
 *   7. Regenerate configuration files.
 *   8. TODO: diagnostic to test that everything is ok?
 *   9. Remove the temporary redirect and restart apache so the previous site is available again.
 *   10. Remove the extranuous db and duplicate site directory.
 *
 * If at any time an error occurs, before step 9. It should reverse all the changes it has made,
 * and leave the current site directory and database in the right place, and remove all cruft that
 * was created by this process.
 */

/**
 * Make sure we have a valid site being migrated, and that the file being migrated from exists
 */
function provision_drupal_provision_migrate_validate(&$data, $url = null, $platform = null) {
  _provision_drupal_url_required();
  _provision_drupal_valid_installed_site();

  $exists = provision_path("exists", $platform . '/drush.php', TRUE,
      dt("Found platform at @path"),
      dt("Could not find platform at @path"),
      PROVISION_FRAMEWORK_ERROR);
}

/**
 * Make a backup before making any changes, and add extract the file we are restoring from
 */
function provision_drupal_provision_pre_migrate(&$data, $url, $platform) {
  provision_invoke('backup', &$data, $url);
}

/**
 * Remove the extracted site directory
 */
function provision_provision_pre_migrate_rollback(&$data, $url, $platform) {
  $success =  provision_path("unlink", $data['backup_file'], TRUE, dt('Removed unused migration site package'), dt('Could not remove unused migration site package'));
  if ($success) {
    unset($data['backup_file']);
  }
}

/**
 * Switch the migrate directories around now that we have the new db installed
 */
function provision_drupal_provision_migrate(&$data, $url, $platform) {
57
  $cmd = sprintf("%s provision deploy %s %s --root=%s --backend=1", $_SERVER['argv'][0], $url, $data['backup_file'], $platform);
58 59 60 61 62 63 64 65 66 67 68 69 70
  provision_exec($cmd,$data);
}


/**
 * Delete the old site directory and recreate the settings file
 */
function provision_drupal_provision_post_migrate(&$data, $url) {
  $data['installed'] = FALSE;
  _provision_recursive_delete(PROVISION_SITES_PATH ."/$url");
}