Last active
April 6, 2016 11:58
-
-
Save esolitos/9027c8e33429a822df24552a740f70dc to your computer and use it in GitHub Desktop.
Drush Alias File for PROJECT.dev Folder Names within multisites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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