From 17ce37efdb3e42c52efbf7ac575fa2fd883f2b6b Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Tue, 4 Jan 2022 11:40:56 +0100 Subject: [PATCH 1/2] Support dotenv 2.x 3.x 5.x --- README.md | 4 ++++ bin/craft-copy-env.php | 13 ++++++++----- bin/craft-copy-import-db.php | 13 ++++++++----- composer.json | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e4fb19e..be12ca0 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ cd your/craft-project composer config platform --unset composer require fortrabbit/craft-copy -W +# With the latest version of composer (2.2 or higher) you we see this prompt: +# Do you trust "fortrabbit/craft-auto-migrate" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] +# Confirm with `y` + # Install and enable the plugin with Craft CMS php craft plugin/install copy ``` diff --git a/bin/craft-copy-env.php b/bin/craft-copy-env.php index a3880c0..a04011d 100755 --- a/bin/craft-copy-env.php +++ b/bin/craft-copy-env.php @@ -13,12 +13,15 @@ // Composer autoloader require_once $root . '/vendor/autoload.php'; -// dotenv? 3.x vs 2.x +// dotenv? 5.x vs 3.x vs 2.x if (file_exists($root . '/.env')) { - $dotenv = (method_exists('\Dotenv\Dotenv', 'create')) - ? \Dotenv\Dotenv::create($root) - : new \Dotenv\Dotenv($root); - $dotenv->load(); + if (method_exists('\Dotenv\Dotenv', 'createUnsafeImmutable')) { + \Dotenv\Dotenv::createUnsafeImmutable($root)->safeLoad(); + } elseif (method_exists('\Dotenv\Dotenv', 'create')) { + \Dotenv\Dotenv::create($root)->load(); + } else { + (new \Dotenv\Dotenv($root))->load(); + } } // ENV basics diff --git a/bin/craft-copy-import-db.php b/bin/craft-copy-import-db.php index cebca33..eb2ccd0 100755 --- a/bin/craft-copy-import-db.php +++ b/bin/craft-copy-import-db.php @@ -18,12 +18,15 @@ define('CRAFT_BASE_PATH', $root); define('YII_DEBUG', false); -// dotenv? 3.x vs 2.x +// dotenv? 5.x vs 3.x vs 2.x if (file_exists($root . '/.env')) { - $dotenv = (method_exists('\Dotenv\Dotenv', 'create')) - ? \Dotenv\Dotenv::create($root) - : new \Dotenv\Dotenv($root); - $dotenv->load(); + if (method_exists('\Dotenv\Dotenv', 'createUnsafeImmutable')) { + \Dotenv\Dotenv::createUnsafeImmutable($root)->safeLoad(); + } elseif (method_exists('\Dotenv\Dotenv', 'create')) { + \Dotenv\Dotenv::create($root)->load(); + } else { + (new \Dotenv\Dotenv($root))->load(); + } } if (count($argv) < 2 || stristr($argv[1], '.sql') == false) { diff --git a/composer.json b/composer.json index 157d30b..da1c36e 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "craftcms/plugin-installer": "^1.5.6", "ostark/yii2-artisan-bridge": "^1.3.1", "symfony/process": "^4.2 | ^5.0", - "vlucas/phpdotenv": "^2.5.1 | ^3.4.0", + "vlucas/phpdotenv": "^2.5.1 | ^3.4.0 | ^5.4", "symfony/yaml": "^4.2 | ^5.0", "fortrabbit/craft-auto-migrate":"^2.3.0" }, From 87bb4496fdb90f774f88fee246ffd99966e2ca5a Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Tue, 4 Jan 2022 12:07:44 +0100 Subject: [PATCH 2/2] 1.0.8 changelog --- CHANGELOG.md | 3 +++ README.md | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb168f..f1249d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.0.8 - 2022-01-4 +- Support dotenv version 5 + ## 1.0.7 - 2021-09-24 - Increased timeout for import script to 1000 seconds diff --git a/README.md b/README.md index be12ca0..c0a6e40 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,10 @@ cd your/craft-project composer config platform --unset composer require fortrabbit/craft-copy -W -# With the latest version of composer (2.2 or higher) you we see this prompt: +# With the latest version of composer (2.2 or higher) you may see this prompt: # Do you trust "fortrabbit/craft-auto-migrate" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] -# Confirm with `y` +# +# Confirm with `y` # Install and enable the plugin with Craft CMS php craft plugin/install copy