Skip to content

Commit

Permalink
Closed #3291
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Jan 2, 2019
1 parent 518911b commit 3878d16
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Changed
- `craft\helpers\ArrayHelper::filterByValue()` now defaults its `$value` argument to `true`.
- Craft now checks whether it should use an existing `project.yaml` file when being installed. ([#3291](https://github.com/craftcms/cms/issues/3291))

### 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
105 changes: 64 additions & 41 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
use craft\helpers\App;
use craft\helpers\Json;
use craft\helpers\StringHelper;
use craft\helpers\ProjectConfig as ProjectConfigHelper;
use craft\mail\transportadapters\Sendmail;
use craft\models\FieldGroup;
use craft\models\Info;
use craft\models\Site;
use craft\models\SiteGroup;
use craft\services\ProjectConfig;
use craft\services\Sites;

/**
* Installation Migration
Expand Down Expand Up @@ -52,6 +54,11 @@ class Install extends Migration
*/
public $site;

/**
* @var bool Whether an existing configuration exists.
*/
private $_configExists = false;

// Public Methods
// =========================================================================

Expand All @@ -63,6 +70,9 @@ public function safeUp()
$this->createTables();
$this->createIndexes();
$this->addForeignKeys();

$this->_configExists = Craft::$app->getConfig()->getGeneral()->useProjectConfigFile && file_exists(Craft::$app->getPath()->getConfigPath() . '/' . ProjectConfig::CONFIG_FILENAME);

$this->insertDefaultData();

// Craft, you are installed now.
Expand Down Expand Up @@ -92,35 +102,43 @@ public function safeUp()
Craft::$app->getUser()->login($user);
}

// Save the default system settings
echo ' > save the system settings ...';
Craft::$app->getProjectConfig()->set('system', [
'edition' => App::editionHandle(Craft::Solo),
'name' => $this->site->name,
'live' => true,
'schemaVersion' => Craft::$app->schemaVersion,
'timeZone' => 'America/Los_Angeles',
]);
echo " done\n";
if ($this->_configExists) {
// Save the default system settings
echo ' > applying existing project config ...';
Craft::$app->getProjectConfig()->applyYamlChanges();

// Save the default email settings
echo ' > save the email settings ...';
Craft::$app->getProjectConfig()->set('email', [
'fromEmail' => $this->email,
'fromName' => $this->site->name,
'transportType' => Sendmail::class
]);
echo " done\n";
} else {
// Save the default system settings
echo ' > save the system settings ...';
Craft::$app->getProjectConfig()->set('system', [
'edition' => App::editionHandle(Craft::Solo),
'name' => $this->site->name,
'live' => true,
'schemaVersion' => Craft::$app->schemaVersion,
'timeZone' => 'America/Los_Angeles',
]);
echo " done\n";

// Save the default email settings
echo ' > save the email settings ...';
Craft::$app->getProjectConfig()->set('email', [
'fromEmail' => $this->email,
'fromName' => $this->site->name,
'transportType' => Sendmail::class
]);
echo " done\n";

// Save the default user settings
echo ' > save the user settings ...';
Craft::$app->getProjectConfig()->set('user', [
'requireEmailVerification' => true,
'allowPublicRegistration' => false,
'defaultGroup' => null,
'photoVolumeUid' => null,
'photoSubpath' => ''
]);
}

// Save the default user settings
echo ' > save the user settings ...';
Craft::$app->getProjectConfig()->set('user', [
'requireEmailVerification' => true,
'allowPublicRegistration' => false,
'defaultGroup' => null,
'photoVolumeUid' => null,
'photoSubpath' => ''
]);
echo " done\n";
}

Expand Down Expand Up @@ -1030,21 +1048,26 @@ public function insertDefaultData()
]));
echo " done\n";

// Add the "Common" field group
Craft::$app->getFields()->saveGroup(new FieldGroup([
'name' => 'Common',
]));
if ($this->_configExists) {
ProjectConfigHelper::ensureAllSitesProcessed();
} else {
// Add the "Common" field group
Craft::$app->getFields()->saveGroup(new FieldGroup([
'name' => 'Common',
]));

// Add the initial site group
$sitesService = Craft::$app->getSites();
$siteGroup = new SiteGroup([
'name' => $this->site->name,
]);
$sitesService->saveGroup($siteGroup);
// Add the initial site group
$sitesService = Craft::$app->getSites();
$siteGroup = new SiteGroup([
'name' => $this->site->name,
]);
$sitesService->saveGroup($siteGroup);

// Add the default site
$this->site->groupId = $siteGroup->id;
$this->site->primary = true;

// Add the default site
$this->site->groupId = $siteGroup->id;
$this->site->primary = true;
Craft::$app->getSites()->saveSite($this->site);
Craft::$app->getSites()->saveSite($this->site);
}
}
}

0 comments on commit 3878d16

Please sign in to comment.