Skip to content

Commit

Permalink
@web => $DEFAULT_SITE_URL
Browse files Browse the repository at this point in the history
Resolves #3559
  • Loading branch information
brandonkelly committed Dec 29, 2018
1 parent 8247da3 commit 242da3a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- Added the System Messages utility for editing system messages, replacing the Settings → Email → System Messages page. ([#3421](https://github.com/craftcms/cms/issues/3421))
- The web and CLI installers no longer suggest `@web` for the site URL, and now attempt to save the entered site URL as a `DEFAULT_SITE_URL` environment variable in `.env`. ([#3559](https://github.com/craftcms/cms/issues/3559))

### Fixed
- Fixed a bug where preset structure UIDs were not preserved when saving structure sections. ([#3525](https://github.com/craftcms/cms/issues/3525))
Expand Down
11 changes: 10 additions & 1 deletion src/console/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use craft\migrations\Install;
use craft\models\Site;
use Seld\CliPrompt\CliPrompt;
use yii\base\Exception;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\helpers\Console;
Expand Down Expand Up @@ -123,9 +124,17 @@ public function actionCraft(): int
$email = $this->email ?: $this->prompt('Email:', ['required' => true, 'validator' => [$this, 'validateEmail']]);
$password = $this->password ?: $this->_passwordPrompt();
$siteName = $this->siteName ?: $this->prompt('Site name:', ['required' => true, 'validator' => [$this, 'validateSiteName']]);
$siteUrl = $this->siteUrl ?: $this->prompt('Site URL:', ['required' => true, 'default' => '@web', 'validator' => [$this, 'validateSiteUrl']]);
$siteUrl = $this->siteUrl ?: $this->prompt('Site URL:', ['required' => true, 'default' => getenv('DEFAULT_SITE_URL') ?: null, 'validator' => [$this, 'validateSiteUrl']]);
$language = $this->language ?: $this->prompt('Site language:', ['validator' => [$this, 'validateLanguage'], 'default' => 'en-US']);

// Try to save the site URL to a DEFAULT_SITE_URL environment variable
try {
Craft::$app->getConfig()->setDotEnvVar('DEFAULT_SITE_URL', $siteUrl);
$siteUrl = '$DEFAULT_SITE_URL';
} catch (Exception $e) {
// that's fine, we'll just store the entered URL
}

$site = new Site([
'name' => $siteName,
'handle' => 'default',
Expand Down
16 changes: 13 additions & 3 deletions src/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use craft\models\Site;
use craft\web\assets\installer\InstallerAsset;
use craft\web\Controller;
use yii\base\Exception;
use yii\base\Response;
use yii\web\BadRequestHttpException;

Expand Down Expand Up @@ -94,7 +95,7 @@ public function actionIndex()
$words = preg_split('/[\-_\.]+/', $server);
array_pop($words);
$defaultSystemName = implode(' ', array_map('ucfirst', $words));
$defaultSiteUrl = '@web';
$defaultSiteUrl = getenv('DEFAULT_SITE_URL') ?: Craft::getAlias('@web');

$iconsPath = Craft::getAlias('@app/icons');
$dbIcon = $showDbScreen ? file_get_contents($iconsPath . DIRECTORY_SEPARATOR . 'database.svg') : null;
Expand Down Expand Up @@ -235,14 +236,14 @@ public function actionInstall(): Response
$this->requireAcceptsJson();

$request = Craft::$app->getRequest();
$configService = Craft::$app->getConfig();

// Should we set the new DB config values?
if ($request->getBodyParam('db-driver') !== null) {
// Set and save the new DB config values
$dbConfig = Craft::$app->getConfig()->getDb();
$this->_populateDbConfig($dbConfig, 'db-');

$configService = Craft::$app->getConfig();
$configService->setDotEnvVar('DB_DRIVER', $dbConfig->driver);
$configService->setDotEnvVar('DB_SERVER', $dbConfig->server);
$configService->setDotEnvVar('DB_USER', $dbConfig->user);
Expand All @@ -263,12 +264,21 @@ public function actionInstall(): Response

$email = $request->getBodyParam('account-email');
$username = $request->getBodyParam('account-username', $email);
$siteUrl = $request->getBodyParam('site-baseUrl');

// Try to save the site URL to a DEFAULT_SITE_URL environment variable
try {
$configService->setDotEnvVar('DEFAULT_SITE_URL', $siteUrl);
$siteUrl = '$DEFAULT_SITE_URL';
} catch (Exception $e) {
// that's fine, we'll just store the entered URL
}

$site = new Site([
'name' => $request->getBodyParam('site-name'),
'handle' => 'default',
'hasUrls' => true,
'baseUrl' => $request->getBodyParam('site-baseUrl'),
'baseUrl' => $siteUrl,
'language' => $request->getBodyParam('site-language'),
]);

Expand Down

0 comments on commit 242da3a

Please sign in to comment.