Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | namespace Civi\Setup; | |
3 | ||
4 | class DrupalUtil { | |
5 | ||
6 | /** | |
7 | * @return bool | |
8 | */ | |
9 | public static function isDrush() { | |
10 | return PHP_SAPI === 'cli' && function_exists('drush_main'); | |
11 | } | |
12 | ||
13 | /** | |
14 | * @param $cmsPath | |
15 | * | |
16 | * @return string | |
17 | */ | |
18 | public static function getDrupalSiteDir($cmsPath) { | |
19 | if (function_exists('conf_path')) { | |
20 | return basename(conf_path()); | |
21 | } | |
22 | elseif (class_exists('Drupal')) { | |
23 | return basename(\Drupal::service('site.path')); | |
24 | } | |
25 | else { | |
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. | |
30 | } | |
31 | ||
32 | /* | |
33 | static $siteDir = ''; | |
34 | ||
35 | if ($siteDir) { | |
cfb48750 | 36 | return $siteDir; |
4bcd4c62 TO |
37 | } |
38 | ||
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. | |
42 | ||
43 | $sites = DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR; | |
44 | $modules = DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR; | |
45 | preg_match("/" . preg_quote($sites, DIRECTORY_SEPARATOR) . | |
cfb48750 TO |
46 | "([\-a-zA-Z0-9_.]+)" . |
47 | preg_quote($modules, DIRECTORY_SEPARATOR) . "/", | |
48 | $_SERVER['SCRIPT_FILENAME'], $matches | |
4bcd4c62 | 49 | ); |
2e1f50d6 | 50 | $siteDir = $matches[1] ?? 'default'; |
4bcd4c62 TO |
51 | |
52 | if (strtolower($siteDir) == 'all') { | |
cfb48750 TO |
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 | |
61 | )) { | |
62 | $siteDir = $dir; | |
63 | return $siteDir; | |
64 | } | |
65 | } | |
66 | } | |
67 | $siteDir = 'default'; | |
4bcd4c62 TO |
68 | } |
69 | ||
70 | return $siteDir; | |
cfb48750 | 71 | */ |
4bcd4c62 TO |
72 | } |
73 | ||
74 | } |