verify.provision.inc 4.96 KB
Newer Older
1 2 3 4 5 6 7
<?php

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

drumm's avatar
drumm committed
13
    _provision_drupal_create_settings_file();
14
    provision_drupal_push_site();
15

drumm's avatar
drumm committed
16 17
    drush_errors_on();
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
18
  }
19 20 21 22 23 24
}


/**
 * implementation of provision_verify
 */
25
function drush_provision_drupal_pre_provision_verify() {
drumm's avatar
drumm committed
26
  if (d()->type === 'server') {
drumm's avatar
drumm committed
27

28 29
    $config_root = dirname(d()->config_path);
    provision_file()->create_dir($config_root, dt('Provision configuration root'), 0711);
30
    provision_file()->create_dir(d()->config_path, dt('Provision configuration'), 0711);
31
    provision_file()->create_dir(d()->clients_path, dt('Provision client home'), 0711);
32
    if (d()->name == '@server_master') {
33
      provision_file()->create_dir(d()->backup_path, dt('Backup'), 0700);
34 35 36 37
      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
        // open_basedir restrictions
38
        $config = new Provision_Config_Global_Settings(d()->name);
39 40 41 42 43 44 45
        $config->write();
      }
    }
    else {
      if (provision_file()->exists(d()->include_path)) {
        d()->service('http')->sync(d()->include_path);
      }
46
    }
47
  }
drumm's avatar
drumm committed
48
  elseif (d()->type === 'platform') {
49 50
    // create a platform from a makefile, if it doesnt already exist and the makefile does.
    if (!provision_file()->exists(d()->root)->status() && !empty(d()->makefile)) {
mig5's avatar
mig5 committed
51
      drush_log(dt("Platform path does not exist, fetching from drush makefile"));
52 53
      $arguments = array();
      $options = array();
54
      // propagate working-copy args downward
55
      if (drush_get_option('working-copy') || !empty(d()->make_working_copy)) {
56
        $options[] = '--working-copy';
57
      }
58 59 60
      $arguments[] = d()->makefile;
      $arguments[] = d()->root;
      drush_invoke_process('@none', "make", $arguments, $options);
61
      if (drush_get_error()) {
62
        return drush_set_error("DRUSH_MAKE_FAILED",
63
          "Could not download platform using drush make. No platform present");
64 65 66
      }
    }

67 68 69 70 71
    // 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
72
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
73 74 75 76 77
    // If we couldn't bootstrap, there's no sense in continuing past this point.
    if(drush_get_error()) {
      return drush_set_error("DRUSH_INVALID_DRUPAL_ROOT",
        "Drush could not bootstrap this platform. Please check the platform directory exists and is readable.");
    }
78
    provision_file()->writable(d()->root . '/sites')
79 80
      ->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');
81

82 83 84 85 86 87 88 89 90
    // 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');
91
    drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => drush_drupal_version())));
92
    drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal');
93
    provision_drupal_push_site();
94
  }
drumm's avatar
drumm committed
95
  elseif (d()->type === 'site') {
96
    drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
97
    // This is the actual drupal provisioning requirements.
98 99
    _provision_drupal_create_directories();
    _provision_drupal_maintain_aliases();
100
    _provision_drupal_ensure_htaccess_update();
101
    // Requires at least the database settings to complete.
102 103 104

    _provision_drupal_create_settings_file();

105 106 107 108 109 110 111
    if (function_exists('hosting_get_features')) {
      // We're verifying the hostmaster site, so record a list of enabled
      // Hosting Features.
      $aegir_drushrc = new Provision_Config_Drushrc_Aegir();
      $aegir_drushrc->write();
    }

112
    provision_drupal_push_site();
113 114 115 116 117 118
  }
}

/**
 * Implementation of hook_provision_post_verify
 */
119
function drush_provision_drupal_post_provision_verify() {
drumm's avatar
drumm committed
120
  if (d()->type === 'site') {
121
    _provision_drupal_rebuild_caches();
122
    drush_set_option('installed', TRUE, 'site');
123 124

    _provision_client_create_symlink();
125
    drush_include_engine('drupal', 'cron_key');
126 127 128
  }
}