diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 6243bf54..c249cf36 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -61,7 +61,7 @@ * type of CMS is being used. * (Default: NULL) * - env: string|NULL. The environment variable which may contain the path to - * civicrm.settings.php. Set NULL to disable. + * civicrm.settings.php (or the token "Auto"). Set NULL to disable environment-checking. * (Default: CIVICRM_SETTINGS) * - httpHost: string|NULL. For multisite, the HTTP hostname. * - prefetch: bool. Whether to load various caches. @@ -324,7 +324,7 @@ public function getCivicrmSettingsPhp($options) { if (defined('CIVICRM_CONFDIR') && file_exists(CIVICRM_CONFDIR . '/civicrm.settings.php')) { $settings = CIVICRM_CONFDIR . '/civicrm.settings.php'; } - elseif (!empty($options['env']) && getenv($options['env']) && file_exists(getenv($options['env']))) { + elseif (!empty($options['env']) && getenv($options['env']) && getenv($options['env']) !== 'Auto' && file_exists(getenv($options['env']))) { $settings = getenv($options['env']); } elseif (!empty($options['settingsFile']) && file_exists($options['settingsFile'])) { diff --git a/src/CmsBootstrap.php b/src/CmsBootstrap.php index 371b6a0e..561f8527 100644 --- a/src/CmsBootstrap.php +++ b/src/CmsBootstrap.php @@ -111,6 +111,10 @@ public function bootCms() { 'path' => '/' . parse_url($cmsExpr, PHP_URL_HOST) . parse_url($cmsExpr, PHP_URL_PATH), ); $cms['path'] = preg_replace(';^//+;', '/', $cms['path']); + if ($cms['type'] === 'Auto') { + $isAutoPath = (trim($cms['path'], '/') === '.'); + $cms = $this->findCmsRoot($isAutoPath ? $this->getSearchDir() : $cms['path']); + } if (!isset($this->options['user']) && parse_url($cmsExpr, PHP_URL_USER)) { $this->options['user'] = parse_url($cmsExpr, PHP_URL_USER); } @@ -126,7 +130,7 @@ public function bootCms() { $cms = $this->findCmsRoot($this->getSearchDir()); } - $this->writeln("CMS: " . json_encode($this->options, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), OutputInterface::VERBOSITY_DEBUG); + $this->writeln("CMS: " . json_encode($cms, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), OutputInterface::VERBOSITY_DEBUG); if (empty($cms['path']) || empty($cms['type']) || !file_exists($cms['path'])) { $cmsJson = json_encode($cms, JSON_UNESCAPED_SLASHES); throw new \Exception("Failed to parse or find a CMS $cmsJson");