deploy.provision.inc 4.07 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
<?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 deployd 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 deployd.
 *   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 deployd, and that the file being deployd from exists
 */
26
function provision_drupal_provision_deploy_validate($url = null, $backup_file = null) {
27
28
29
  _provision_drupal_url_required();

  $exists = provision_path("exists", $backup_file, TRUE,
30
      dt("Deploying site from @path"),
31
      dt("Could not find backup file @path"),
32
      'PROVISION_BACKUP_NOT_FOUND');
33
  if ($exists) {
34
    drush_set_option('backup_file', $backup_file);
35
36
37
38
39
40
  }
}

/**
 * Make a backup before making any changes, and add extract the file we are restoring from
 */
41
42
function provision_drupal_provision_pre_deploy($url, $backup_file) {
  $extracted = provision_path("extract", drush_get_option('backup_file'), drush_get_option('sites_path') ."/$url", 
43
44
    dt('Successfully extracted the contents of @path'),
    dt('Failed to extract the contents of @path'),
45
    'PROVISION_BACKUP_EXTRACTION_FAILED');
46
  if ($extracted) {
47
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
Adrian Rossouw's avatar
Adrian Rossouw committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    $site_packages = drush_get_context('packages', array(), 'site');
    $profiles = array_keys($site_packages['profiles']);
    $profile = $profiles[0];

    $drupal_packages = drush_get_context('packages', array(), 'drupal');

    $merged_modules = array_merge($drupal_packages['base']['modules'], $drupal_packages['profiles'][$profile]['modules']);
    foreach ($site_packages['modules'] as $name => $module) {
      if ($module['status'] == 1) {
        if (!array_key_exists($name, $merged_modules)) {
          drush_log(dt("Could not find a version of the !name module", array('!name' => $name)), 'warning');
        }
        else {
          if ($module['schema_version'] > $merged_modules[$name]['schema_version']) {
            drush_set_error('PROVISION_SCHEMA_UPGRADE_FAILURE', 
              dt("The version of the !name module found on this platform has a lower Schema version than the one the site has installed", 
              array('!name' => $name)));
          }
          else {
            drush_log(dt("Found a valid version of the !name module with schema version !schema_version", 
              array('!name' => $name, '!schema_version' => $merged_modules[$name]['schema_version'])));
          }
        }
      }
    }
73
74
75
76
77
78
  }
}

/**
 * Remove the extracted site directory
 */
79
function provision_drupal_provision_pre_deploy_rollback($url) {
80
  _provision_recursive_delete(drush_get_option('sites_path') ."/$url");
81
82
83
84
85
}

/**
 * Switch the deploy directories around now that we have the new db installed
 */
86
function provision_drupal_provision_deploy($url) {
87
  // make sure it has the latest site data available
88
  _provision_drupal_create_settings_file($url);
89
90
91
}

// Luckily this is reversable =)
92
93
function provision_drupal_provision_deploy_rollback($url) {
  provision_drupal_provision_deploy($url);
94
95
}

96
97
98
function provision_drupal_provision_post_deploy($url) {
  provision_invoke('update', $url);
  provision_platform_include(dirname(__FILE__), 'deploy');
Adrian Rossouw's avatar
Adrian Rossouw committed
99
  drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
100
}