Skip to content

Instantly share code, notes, and snippets.

@esolitos
Last active April 6, 2016 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esolitos/9027c8e33429a822df24552a740f70dc to your computer and use it in GitHub Desktop.
Save esolitos/9027c8e33429a822df24552a740f70dc to your computer and use it in GitHub Desktop.
Drush Alias File for PROJECT.dev Folder Names within multisites
<?php
$all = $platforms = array();
// Use standard linux 'PATH' style, so if you need more entries separate them using a column ':' char
// For example: '/path/to/platforms/container' OR '/path/to/platforms/container:/path/to/another/location'
// This dorectory will contain one or more drupal roots directories
$platforms_path = '/var/www/platforms';
$paths = explode(':', $platforms_path);
foreach($paths as $path) {
$drupal_root = new DirectoryIterator($path);
while ($drupal_root->valid()) {
// Skip symlinked platforms and dir w/out s sites in it.
if ( !$drupal_root->isLink() && is_dir($drupal_root->getPathname() . '/sites') ) {
$platforms[] = $drupal_root->getPathname();
}
$drupal_root->next();
}
}
foreach($platforms as $drupal) {
$site = new DirectoryIterator($drupal . '/sites');
while ($site->valid()) {
// Look for directories containing a 'settings.php' file
if ( $site->isDir() && !$site->isDot() ) {
// Skip the "default" site directory anche check if settings.php does exist
if ( $site->getBasename() != 'default' && file_exists($site->getPathname() . '/settings.php')) {
// Add site alias
$basename = $aliasname = $site->getBasename();
// If the site contains already `local.` as prefix, just discard it
$matches = [];
if( preg_match('/^local\.(.+)/i', $basename, $matches) ){
$aliasname = $matches[1];
}
$aliases[$aliasname] = array(
'uri' => $basename,
'root' => $drupal,
);
}
}
$site->next();
}
}
// Get all site aliases
foreach ($aliases as $name => $definition) {
$all[] = '@' . $name;
}
// 'All' alias group
$aliases['all'] = array(
'site-list' => $all,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment