Skip to content

Commit

Permalink
Merge pull request #12692 from craftcms/bugfix/12687-trial-license-ke…
Browse files Browse the repository at this point in the history
…y-storage

store generated license keys in .env only if .env exists
  • Loading branch information
brandonkelly authored Feb 17, 2023
2 parents 0ad0afc + 2e0e30b commit 2f176e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed a bug where clicking on the scrollbar of a disclosure menu would close it. ([#12681](https://github.com/craftcms/cms/issues/12681))
- Fixed an error that could occur when loading the Plugin Store, if there wasn’t a `.env` file. ([#12687](https://github.com/craftcms/cms/issues/12687))

## 3.7.66 - 2023-02-14

Expand Down
7 changes: 6 additions & 1 deletion src/services/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,12 @@ public function setPluginLicenseKey(string $handle, string $licenseKey = null):

// If the license key is set to an empty environment variable, set the environment variable's value
$oldLicenseKey = $this->getStoredPluginInfo($handle)['licenseKey'] ?? null;
if (preg_match('/^\$(\w+)$/', $oldLicenseKey, $matches) && App::env($matches[1]) === '') {
// https://github.com/craftcms/cms/issues/12687 - check if the .env file exists first
if (
preg_match('/^\$(\w+)$/', $oldLicenseKey, $matches) &&
App::env($matches[1]) === '' &&
file_exists(Craft::$app->getConfig()->getDotEnvPath())
) {
Craft::$app->getConfig()->setDotEnvVar($matches[1], $normalizedLicenseKey);
} else {
// Set the plugin's license key in the project config
Expand Down

0 comments on commit 2f176e4

Please sign in to comment.