From 640c3621887901451e97640e84da74b39d235896 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 17 Feb 2023 11:42:29 +0000 Subject: [PATCH] store generated license keys in .env only if .env exists --- src/services/Plugins.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/Plugins.php b/src/services/Plugins.php index d35504ff5c5..aee8a75266c 100644 --- a/src/services/Plugins.php +++ b/src/services/Plugins.php @@ -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