verify.provision.inc 3.88 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($url = null) {
9
  if ($url) {
10 11
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
    provision_prepare_environment();
12

drumm's avatar
drumm committed
13 14 15
    _provision_drupal_create_settings_file();
    drush_errors_on();
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
16 17
  }

drumm's avatar
drumm committed
18 19
  // This will not have an effect if you are running it on a platform, just
  // tests that if a site is provided it is an existing one
20 21 22 23 24 25 26
  _provision_drupal_valid_site();
}


/**
 * implementation of provision_verify
 */
27
function drush_provision_drupal_provision_verify($url = null) {
28
  if (PROVISION_CONTEXT_SERVER) {
29 30
    provision_service('file')->create_dir(drush_get_option('config_path'), dt('Provision configuration'), 0711);
    provision_service('file')->create_dir(drush_get_option('config_path') . '/includes', dt('Provision PHP configuration'), 0711);
31
    if (!provision_service('file')->exists(drush_get_option('config_path') . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
32 33 34 35
      // Create an empty global.inc so the include doesn't fail with
      // open_basedir restrictions
      $config = new provisionConfig_global_settings(drush_get_merged_options());
      $config->write();
36
    }
37
    provision_service('file')->create_dir(drush_get_option('backup_path'), dt('Backup'), 0700);
38 39
  }
  elseif (PROVISION_CONTEXT_PLATFORM) {
40 41 42
    provision_service('file')->writable(drush_get_option('sites_path'))
      ->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');
43

44
    drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal'); 
45
    drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => VERSION)));
46
    drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal');
47
    _provision_drupal_create_directories('all');
48
  }
49
  elseif (PROVISION_CONTEXT_SITE) {
50
    drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
51
      // This is the actual drupal provisioning requirements. 
52 53
    _provision_drupal_create_directories($url);
    _provision_drupal_maintain_aliases($url);
54
    // Requires at least the database settings to complete.
55
   _provision_drupal_create_settings_file();
56 57 58
  }
}

59 60 61 62 63 64 65 66 67 68 69
class provisionConfig_global_settings extends provisionConfig {
  public $template = 'global_settings.tpl.php';
  public $description = 'Global settings.php file';

  function filename() {
    return $this->data['config_path'] . '/includes/global.inc';
  }

  function process() {
  }
}
70 71 72 73

/**
 * Implementation of hook_provision_post_verify
 */
74
function drush_provision_drupal_post_provision_verify($url = NULL) {
75
  if (PROVISION_CONTEXT_SITE) {
76
    _provision_drupal_rebuild_caches($url);
77
    drush_set_option('aliases', drush_get_option('aliases'), 'site');
78
    drush_set_option('redirection', drush_get_option('redirection'), 'site');
79
    drush_set_option('installed', TRUE, 'site');
80 81 82
  }
}

83
/**
anarcat's avatar
anarcat committed
84 85 86 87 88 89 90 91
 * Inject the relevant .htacces configuration into the global apache
 * configuration
 *
 * This basically loads the regular .htacess but adds an AllowOverride
 * none so the .htaccess are ignored, as a performance improvement.
 *
 * @see platform/provision_drupal_htaccess.tpl.php
 * @see hook_provision_apache_dir_config()
92 93
 */
function provision_drupal_provision_apache_dir_config($data = null) {
94
  $htaccess = file_get_contents(drush_get_option('publish_path') . '/.htaccess');
95
  $htaccess .= <<<EOF
anarcat's avatar
anarcat committed
96

97 98 99 100 101
<IfModule mod_rewrite.c>
  # allow files to be accessed without /sites/fqdn/
  RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]
</IfModule>

102 103
# Do not read the platform's .htaccess
AllowOverride none
anarcat's avatar
anarcat committed
104

105
EOF;
anarcat's avatar
anarcat committed
106
  # the trailing newline above is necessary
107
  return $htaccess;
108
}