You are here

function _acquia_purge_get_domains_add_acloud in Acquia Purge 6

Expand the list of domains being gathered by those defined in Acquia Cloud.

@returns Void, data will be added by reference. @warning The current implementation of this function is subject to change. @TODO

Parameters

array $domains: A reference to the array of currently gathered domain names.

1 call to _acquia_purge_get_domains_add_acloud()
_acquia_purge_get_domains in ./acquia_purge.module
Get a list of defined domains that we can purge for.

File

./acquia_purge.module, line 522
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function _acquia_purge_get_domains_add_acloud(&$domains) {
  $detected_domains = array();

  // This implementation is very dirty, admitted. Only possible way as of this
  // writing as there is no API level exposure of it. These files are generated
  // automatically so risks of changes are small.
  if (file_exists('/etc/apache2/conf.d')) {
    $site_name = _acquia_purge_get_site_name();
    $server_name = shell_exec("grep -r 'ServerName' /etc/apache2/conf.d/{$site_name}*.conf");
    foreach (explode('ServerName', $server_name) as $testable) {
      foreach (explode(' ', trim($testable)) as $domain) {
        $detected_domains[] = $domain;
      }
    }
    $server_alias = shell_exec("grep -r 'ServerAlias' /etc/apache2/conf.d/{$site_name}*.conf");
    foreach (explode('ServerAlias', $server_alias) as $testable) {
      foreach (explode(' ', trim($testable)) as $domain) {
        $detected_domains[] = $domain;
      }
    }
  }

  // Remove the acquia-sites.com domain if we have found more then 1 domain. The
  // less domains found, the faster the end user experience will be.
  if (count($detected_domains) > 1) {
    foreach ($detected_domains as $i => $detected_domain) {
      if (strpos($detected_domain, 'acquia-sites.com') !== FALSE) {
        unset($detected_domains[$i]);
      }
    }
  }

  // Register all detected domain names.
  foreach ($detected_domains as $i => $detected_domain) {
    _acquia_purge_get_domains_add($detected_domain, $domains);
  }
}