verify.provision.inc 5.47 KB
Newer Older
1 2 3
<?php

/**
helmo's avatar
helmo committed
4 5 6 7 8 9
 * @file
 * Code related to verify tasks.
 */

/**
 * Provision verify command.
10 11 12
 *
 * Disable an enabled and installed site
 */
13
function drush_provision_drupal_provision_verify_validate() {
drumm's avatar
drumm committed
14
  if (d()->type === 'site') {
15 16
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
    provision_prepare_environment();
17

drumm's avatar
drumm committed
18
    _provision_drupal_create_settings_file();
19
    provision_drupal_push_site();
20

drumm's avatar
drumm committed
21 22
    drush_errors_on();
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
23
  }
24 25 26 27
}


/**
helmo's avatar
helmo committed
28
 * Implements drush_hook_pre_COMMAND().
29
 */
30
function drush_provision_drupal_pre_provision_verify() {
drumm's avatar
drumm committed
31
  if (d()->type === 'server') {
drumm's avatar
drumm committed
32

33 34
    $config_root = dirname(d()->config_path);
    provision_file()->create_dir($config_root, dt('Provision configuration root'), 0711);
35
    provision_file()->create_dir(d()->config_path, dt('Provision configuration'), 0711);
36
    provision_file()->create_dir(d()->clients_path, dt('Provision client home'), 0711);
37
    if (d()->name == '@server_master') {
38
      provision_file()->create_dir(d()->backup_path, dt('Backup'), 0700);
39 40 41
      provision_file()->create_dir(d()->include_path, dt('Provision PHP configuration'), 0711);
      if (!provision_file()->exists(d()->include_path . '/global.inc')->succeed('Global configuration file exists')->status()) {
        // Create an empty global.inc so the include doesn't fail with
helmo's avatar
helmo committed
42
        // open_basedir restrictions.
43
        $config = new Provision_Config_Global_Settings(d()->name);
44 45 46 47 48 49 50
        $config->write();
      }
    }
    else {
      if (provision_file()->exists(d()->include_path)) {
        d()->service('http')->sync(d()->include_path);
      }
51
    }
52
  }
drumm's avatar
drumm committed
53
  elseif (d()->type === 'platform') {
helmo's avatar
helmo committed
54
    // Create a platform from a makefile, if it doesnt already exist and the makefile does.
55
    if (!provision_file()->exists(d()->root)->status() && !empty(d()->makefile)) {
mig5's avatar
mig5 committed
56
      drush_log(dt("Platform path does not exist, fetching from drush makefile"));
57 58
      $arguments = array();
      $options = array();
helmo's avatar
helmo committed
59
      // Propagate working-copy args downward.
60
      if (drush_get_option('working-copy') || !empty(d()->make_working_copy)) {
61
        $options[] = '--working-copy';
62
      }
63 64
      $arguments[] = d()->makefile;
      $arguments[] = d()->root;
65 66 67 68 69
      
      // Change current directory to makefile's directory until Drush fixes this bug: https://github.com/drush-ops/drush/issues/2482
      // @TODO: Remove this once is committed.
      chdir(dirname(d()->makefile));
      
70
      drush_invoke_process('@none', "make", $arguments, $options);
71
      if (drush_get_error()) {
72
        return drush_set_error("DRUSH_MAKE_FAILED",
73
          "Could not download platform using drush make. No platform present");
74 75 76
      }
    }

77 78 79 80 81
    // Re-set the ROOT PATH for Drush.
    // In cases where we just build the platform Drush would have cleared this value.
    // See Drush commit 3b74d40b1228f022464b92243c16127eb613c2df
    drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', d()->root);

Adrian Rossouw's avatar
Adrian Rossouw committed
82
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
83
    // If we couldn't bootstrap, there's no sense in continuing past this point.
84 85
    if (drush_get_error()) {
      $errors = drush_get_error_log();
86
      return drush_set_error("DRUSH_INVALID_DRUPAL_ROOT",
87 88 89 90
        dt("Drush could not bootstrap the platform at @path. Please check the platform directory exists and is readable. The errors were: @errors", array(
          '@path' => d()->root,
          '@errors' => implode('|', $errors)
        )));
91
    }
92
    provision_file()->writable(d()->root . '/sites')
93 94
      ->succeed('Drupal sites directory @path is writable by the provisioning script')
      ->fail('Drupal sites directory @path is not writable by the provisioning script', 'PROVISION_SITES_DIR_NOT_WRITABLE');
95

96 97 98 99 100 101 102 103 104
    // Ensure sites.php file exists for Drupal 8 and above.
    $sitesfile = "sites/sites.php";
    if (drush_drupal_major_version() >= 8 && !file_exists($sitesfile)) {
      if (!drush_op('copy', 'sites/example.sites.php', $sitesfile) && !drush_get_context('DRUSH_SIMULATE')) {
        return drush_set_error(dt('Failed to copy sites/sites.php to @sitesfile', array('@sitesfile' => $sitesfile)));
      }
    }

    drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal');
105
    drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => drush_drupal_version())));
106
    drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal');
107
    provision_drupal_push_site();
108
  }
drumm's avatar
drumm committed
109
  elseif (d()->type === 'site') {
110
    drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
111
    // This is the actual drupal provisioning requirements.
112 113
    _provision_drupal_create_directories();
    _provision_drupal_maintain_aliases();
114
    _provision_drupal_ensure_htaccess_update();
115
    // Requires at least the database settings to complete.
116 117 118

    _provision_drupal_create_settings_file();

119 120
    // If this is the hostmaster site, save the ~/.drush/drushrc.php file.
    if (d()->root == d('@hostmaster')->root && d()->uri == d('@hostmaster')->uri) {
121 122 123 124
      $aegir_drushrc = new Provision_Config_Drushrc_Aegir();
      $aegir_drushrc->write();
    }

125
    provision_drupal_push_site(drush_get_option('override_slave_authority', FALSE));
126 127 128 129
  }
}

/**
helmo's avatar
helmo committed
130
 * Implements drush_hook_provision_post_COMMAND().
131
 */
132
function drush_provision_drupal_post_provision_verify() {
drumm's avatar
drumm committed
133
  if (d()->type === 'site') {
134
    _provision_drupal_rebuild_caches();
135
    drush_set_option('installed', TRUE, 'site');
136 137

    _provision_client_create_symlink();
138
    drush_include_engine('drupal', 'cron_key');
139 140
  }
}