Skip to content

Commit

Permalink
store generated license keys in .env only if .env exists
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Feb 17, 2023
1 parent 0ad0afc commit 640c362
Showing 1 changed file with 6 additions and 1 deletion.
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 640c362

Please sign in to comment.