9 public static function isDrush() {
10 return PHP_SAPI
=== 'cli' && function_exists('drush_main');
18 public static function getDrupalSiteDir($cmsPath) {
19 if (function_exists('conf_path')) {
20 return basename(conf_path());
22 elseif (class_exists('Drupal')) {
23 return basename(\Drupal
::service('site.path'));
26 throw new \
Exception('Cannot detect path under Drupal "sites/".');
27 // The old 'install/index.php' system duplicated the conf_path() logic so that it could work pre-boot.
28 // With civicrm-setup, the CMS should always be booted first, so we should never go down this path.
29 // For the moment, the code is kept below in case it turns out we do need this for some reason.
39 // The SCRIPT_FILENAME check was copied over from the 'install/index.php' system.
40 // It probably doesn't make sense in the context of civicrm-setup b/c we don't know what the SCRIPT will be
41 // and instead rely on $model inputs.
43 $sites = DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR;
44 $modules = DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;
45 preg_match("/" . preg_quote($sites, DIRECTORY_SEPARATOR) .
46 "([\-a-zA-Z0-9_.]+)" .
47 preg_quote($modules, DIRECTORY_SEPARATOR) . "/",
48 $_SERVER['SCRIPT_FILENAME'], $matches
50 $siteDir = isset($matches[1]) ? $matches[1] : 'default';
52 if (strtolower($siteDir) == 'all') {
53 // For this case - use drupal's way of finding out multi-site directory
54 $uri = explode(DIRECTORY_SEPARATOR, $_SERVER['SCRIPT_FILENAME']);
55 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
56 for ($i = count($uri) - 1; $i > 0; $i--) {
57 for ($j = count($server); $j > 0; $j--) {
58 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
59 if (file_exists($cmsPath . DIRECTORY_SEPARATOR .
60 'sites' . DIRECTORY_SEPARATOR . $dir