summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Beaupré2011-03-11 23:03:35 (GMT)
committerAntoine Beaupré2011-03-11 23:03:35 (GMT)
commitd8b98d2845d06b696545daf6b9c3faa83b7cca0a (patch)
tree6106618711d51c6d68a2dcfa9c68774cea7337ef
parente93c2e54d98933b72148207ebc2e8541d1712149 (diff)
parente1bd1a94655a1d94d671aebefb73541f68a2a924 (diff)
Merge branch 'master' into 6.x-1.x
-rw-r--r--platform/provision_drupal.drush.inc135
-rw-r--r--platform/provision_drupal_sites.tpl.php41
2 files changed, 133 insertions, 43 deletions
diff --git a/platform/provision_drupal.drush.inc b/platform/provision_drupal.drush.inc
index 86a3c65..abc3177 100644
--- a/platform/provision_drupal.drush.inc
+++ b/platform/provision_drupal.drush.inc
@@ -339,32 +339,6 @@ function provision_drupal_find_sites() {
return $sites;
}
-/**
- * Retrieve a list of aliases for the curent site.
- */
-function provision_drupal_find_aliases() {
- $aliases = array();
- if (d()->type === 'site') {
- if ($dir = opendir(d()->root . "/sites")) {
- while (FALSE !== ($subdir = readdir($dir))) {
- // skip internal directory pointers
- if ($subdir != '.' && $subdir != '..') {
- $path = d()->root . '/sites/' . $subdir;
- if (is_link($path)) {
- if (d()->uri === readlink($path)) {
- $aliases[] = $subdir;
- }
- }
- }
- }
- closedir($dir);
- }
- }
-
- return $aliases;
-}
-
-
function _provision_drupal_get_cvs_versions($files) {
foreach ($files as $modulename => $file) {
$project = array();
@@ -382,21 +356,89 @@ function _provision_drupal_get_cvs_versions($files) {
return $files;
}
+class provisionConfig_drupal_alias_store extends provisionConfig_data_store {
+ public $template = 'provision_drupal_sites.tpl.php';
+ public $description = 'Drupal sites.php file';
+ public $key = 'sites';
+ protected $mode = 0644;
+
+ function filename() {
+ return $this->root . '/sites/sites.php';
+ }
+
+ function maintain() {
+ $this->delete();
+ if (!$this->redirection) {
+ foreach ($this->aliases as $alias) {
+ $this->records[$alias] = $this->uri;
+ }
+ }
+ }
+
+ function delete() {
+ foreach ($this->find() as $alias) {
+ unset($this->records[$alias]);
+ unset($this->loaded_records[$alias]);
+ }
+ }
+
+ function find() {
+ return array_keys($this->merged_records(), $this->uri);
+ }
+}
+
+/**
+ * Retrieve a list of aliases for the curent site.
+ */
+function provision_drupal_find_aliases() {
+ $aliases = array();
+ if (d()->type === 'site') {
+ if (drush_drupal_major_version() >= 7) {
+ $config = new provisionConfig_drupal_alias_store(d()->name);
+ $aliases = $config->find();
+ } else {
+ if ($dir = opendir(d()->root . "/sites")) {
+ while (FALSE !== ($subdir = readdir($dir))) {
+ // skip internal directory pointers
+ if ($subdir != '.' && $subdir != '..') {
+ $path = d()->root . '/sites/' . $subdir;
+ if (is_link($path)) {
+ if (d()->uri === readlink($path)) {
+ $aliases[] = $subdir;
+ }
+ }
+ }
+ }
+ closedir($dir);
+ }
+ }
+ }
+
+ return $aliases;
+}
+
/**
* Create and remove symlinks for each of the possible domain aliases of an
* existing site.
*/
function _provision_drupal_maintain_aliases() {
if (d()->type === 'site') {
- _provision_drupal_delete_aliases();
-
- if (!d()->redirection) {
- foreach(d()->aliases as $alias) {
- if ($alias = trim($alias)) {
- provision_file()->symlink(d()->uri, d()->root . '/sites/' . $alias)
- ->succeed('Created symlink for alias @target')
- ->fail('Could not create symlink for alias @target');
- d()->service('http')->sync(d()->root . '/sites/' . $alias);
+ if (drush_drupal_major_version() >= 7) {
+ $config = new provisionConfig_drupal_alias_store(d()->name);
+ $config->maintain();
+ $config->write();
+ d()->service('http')->sync($config->filename());
+ } else {
+ _provision_drupal_delete_aliases();
+
+ if (!d()->redirection) {
+ foreach(d()->aliases as $alias) {
+ if ($alias = trim($alias)) {
+ provision_file()->symlink(d()->uri, d()->root . '/sites/' . $alias)
+ ->succeed('Created symlink for alias @target')
+ ->fail('Could not create symlink for alias @target');
+ d()->service('http')->sync(d()->root . '/sites/' . $alias);
+ }
}
}
}
@@ -409,14 +451,21 @@ function _provision_drupal_maintain_aliases() {
function _provision_drupal_delete_aliases() {
if (d()->type === 'site') {
- $aliases = provision_drupal_find_aliases();
-
- foreach ($aliases as $alias) {
- $path = d()->root . '/sites/' . $alias;
- provision_file()->unlink($path)
- ->succeed('Removed symlink for alias @path')
- ->fail('Could not remove symlink for alias @path');
- d()->service('http')->sync($path);
+ if (drush_drupal_major_version() >= 7) {
+ $config = new provisionConfig_drupal_alias_store(d()->name);
+ $config->delete();
+ $config->write();
+ d()->service('http')->sync($config->filename());
+ } else {
+ $aliases = provision_drupal_find_aliases();
+
+ foreach ($aliases as $alias) {
+ $path = d()->root . '/sites/' . $alias;
+ provision_file()->unlink($path)
+ ->succeed('Removed symlink for alias @path')
+ ->fail('Could not remove symlink for alias @path');
+ d()->service('http')->sync($path);
+ }
}
}
}
diff --git a/platform/provision_drupal_sites.tpl.php b/platform/provision_drupal_sites.tpl.php
new file mode 100644
index 0000000..6e6a2a0
--- /dev/null
+++ b/platform/provision_drupal_sites.tpl.php
@@ -0,0 +1,41 @@
+<?php print "<?php \n"; ?>
+/**
+ * @file
+ * Configuration file for Drupal's multi-site directory aliasing feature.
+ *
+ * Drupal searches for an appropriate configuration directory based on the
+ * website's hostname and pathname. A detailed description of the rules for
+ * discovering the configuration directory can be found in the comment
+ * documentation in 'sites/default/default.settings.php'.
+ *
+ * This file allows you to define a set of aliases that map hostnames and
+ * pathnames to configuration directories. These aliases are loaded prior to
+ * scanning for directories, and they are exempt from the normal discovery
+ * rules. The aliases are defined in an associative array named $sites, which
+ * should look similar to the following:
+ *
+ * $sites = array(
+ * 'devexample.com' => 'example.com',
+ * 'localhost.example' => 'example.com',
+ * );
+ *
+ * The above array will cause Drupal to look for a directory named
+ * "example.com" in the sites directory whenever a request comes from
+ * "example.com", "devexample.com", or "localhost/example". That is useful
+ * on development servers, where the domain name may not be the same as the
+ * domain of the live server. Since Drupal stores file paths into the database
+ * (files, system table, etc.) this will ensure the paths are correct while
+ * accessed on development servers.
+ *
+ * To use this file, copy and rename it such that its path plus filename is
+ * 'sites/sites.php'. If you don't need to use multi-site directory aliasing,
+ * then you can safely ignore this file, and Drupal will ignore it too.
+ */
+
+/**
+ * Multi-site directory aliasing:
+ *
+ * Edit the lines below to define directory aliases. Remove the leading hash
+ * signs to enable.
+ */
+$sites = <?php print var_export($records, TRUE) ?>;