verify.provision.inc 6.05 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 13 14 15

      _provision_drupal_create_settings_file($url);
     drush_errors_on();
     drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
16 17
  }

18 19 20 21 22 23 24 25
  // 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
  _provision_drupal_valid_site();
}


/**
 * implementation of provision_verify
 */
26
function drush_provision_drupal_provision_verify($url = null) {
27
  if (PROVISION_CONTEXT_PLATFORM) {
28
    _provision_create_dir(drush_get_option('config_path'), dt('Provision configuration'), 0711);
29 30 31 32 33 34 35 36 37 38 39
    _provision_create_dir(drush_get_option('config_path') . '/includes', dt('Provision PHP configuration'), 0711);
    if (!provision_path('exists', drush_get_option('config_path') .  '/includes/global.inc', TRUE, dt("Global configuration file exists"))) {
      # create an empty global.inc so the include doesn't fail with
      # open_basedir restrictions
      if (!$file = fopen(drush_get_option('config_path') .  '/includes/global.inc', 'a')) {
        drush_set_error('PROVISION_FRAMEWORK_ERROR', dt('Cannot create global settings configuration'));
      } else {
        fwrite($file, "<?php # global settings.php");
        fclose($file);
      }
    }
40
    _provision_create_dir(drush_get_option('backup_path'), dt('Backup'), 0700);
41
    provision_path("writable", drush_get_option('sites_path'), TRUE, dt("Drupal sites directory is writable by the provisioning script"),
42
      dt("Drupal sites directory 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
  }
  else {
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($url);
56 57 58 59 60 61 62
  }
}


/**
 * Implementation of hook_provision_post_verify
 */
63
function drush_provision_drupal_post_provision_verify($url = NULL) {
64
  if (PROVISION_CONTEXT_SITE) {
65
    _provision_drupal_rebuild_caches($url);
66
    drush_set_option('aliases', drush_get_option('aliases'), 'site');
67
    drush_set_option('redirection', drush_get_option('redirection'), 'site');
68
    drush_set_option('installed', TRUE, 'site');
69 70 71
  }
}

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
/**
 * Inject the relevant .htacces configuration into the global apache configuration
 */
function provision_drupal_provision_apache_dir_config($data = null) {
  return <<<EOF
#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

145 146 147 148 149 150 151 152
  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
153 154 155 156 157 158
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

159 160 161
  # allow files to be accessed without /sites/fqdn/
  RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

162 163 164 165 166 167
  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
168 169 170 171

# Do not read the platform's .htaccess
AllowOverride none

172
EOF;
173
}