From 8d9cdf9c15f6fb8e993ad881fa7aaee50ad6ff4d Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 May 2022 19:56:42 -0700 Subject: [PATCH 1/3] Check for APP_ENV Signed-off-by: snipe --- upgrade.php | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/upgrade.php b/upgrade.php index 92d75f3a28..89c00a4981 100644 --- a/upgrade.php +++ b/upgrade.php @@ -15,6 +15,7 @@ if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_get } +$app_environment = 'develop'; // Check if a branch or tag was passed in the command line, // otherwise just use master @@ -58,6 +59,26 @@ foreach ($env as $line_num => $line) { $env_value = trim($env_value); + + /** + * We set this $app_environment here to determine which version of composer to use, --no-dev or with dev dependencies. + * This doesn't actually *change* anything in the .env file, but if the user is running this with + * APP_ENV set to anything OTHER than production, they'll get an error when they try to dump-autoload + * because the Dusk service provider only tries to load if the app is not in production mode. + * + * It's 100% okay if they're not in production mode, but this will avoid any confusion as they get + * erroneous errors using this upgrader if they are not in production mode when they run this script. + * + * We use this further down in the composer section of this upgrader. + */ + + if ($env_key == "APP_ENV") { + if ($env_value == 'production') { + $app_environment = 'production'; + } + } + + if ($env_key == 'APP_KEY') { if (($env_value=='') || (strlen($env_value) < 20)) { $env_bad .= "✘ APP_KEY ERROR in your .env on line #'.$show_line_num.': Your APP_KEY should not be blank. Run `php artisan key:generate` to generate one.\n"; @@ -354,12 +375,26 @@ if (file_exists('composer.phar')) { echo $composer_update."\n\n"; $composer_dump = shell_exec('php composer.phar dump'); - $composer = shell_exec('php composer.phar install --no-dev --prefer-source'); + + // Use --no-dev only if we are in production mode. + // This will cause errors otherwise, if the user is in develop or local for their APP_ENV + if ($app_environment == 'production') { + $composer = shell_exec('php composer.phar install --no-dev --prefer-source'); + } else { + $composer = shell_exec('php composer.phar install --prefer-source'); + } } else { + echo "-- We couldn't find a local composer.phar. No worries, trying globally.\n\n"; $composer_dump = shell_exec('composer dump'); - $composer = shell_exec('composer install --no-dev --prefer-source'); + + if ($app_environment == 'production') { + $composer = shell_exec('composer install --no-dev --prefer-source'); + } else { + $composer = shell_exec('composer install --prefer-source'); + } + } echo $composer_dump."\n"; From 94a337fc9efd1f0a8f5d12d3c378db018bedf7aa Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 May 2022 20:03:10 -0700 Subject: [PATCH 2/3] Rearrange a few thing Signed-off-by: snipe --- upgrade.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/upgrade.php b/upgrade.php index 89c00a4981..8d002e442e 100644 --- a/upgrade.php +++ b/upgrade.php @@ -365,7 +365,7 @@ echo "--------------------------------------------------------\n"; echo "STEP 8: Updating composer dependencies:\n"; echo "(This may take a moment.)\n"; echo "--------------------------------------------------------\n\n"; - +echo "-- Running the app in ".$app_environment." mode.\n"; // Composer install if (file_exists('composer.phar')) { @@ -374,7 +374,7 @@ if (file_exists('composer.phar')) { $composer_update = shell_exec('php composer.phar self-update'); echo $composer_update."\n\n"; - $composer_dump = shell_exec('php composer.phar dump'); + // Use --no-dev only if we are in production mode. // This will cause errors otherwise, if the user is in develop or local for their APP_ENV @@ -383,18 +383,23 @@ if (file_exists('composer.phar')) { } else { $composer = shell_exec('php composer.phar install --prefer-source'); } + $composer_dump = shell_exec('php composer.phar dump'); + + } else { - echo "-- We couldn't find a local composer.phar. No worries, trying globally.\n\n"; - $composer_dump = shell_exec('composer dump'); - if ($app_environment == 'production') { $composer = shell_exec('composer install --no-dev --prefer-source'); } else { $composer = shell_exec('composer install --prefer-source'); } + echo "-- We couldn't find a local composer.phar. No worries, trying globally.\n"; + $composer_dump = shell_exec('composer dump'); + + + } echo $composer_dump."\n"; From fa2a3e4b03ed670af32560277da3aa3f425241e6 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 May 2022 20:08:04 -0700 Subject: [PATCH 3/3] Added a line break Signed-off-by: snipe --- upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade.php b/upgrade.php index 8d002e442e..3c0ec4cbdb 100644 --- a/upgrade.php +++ b/upgrade.php @@ -134,7 +134,7 @@ if ($env_bad !='') { } -echo "--------------------------------------------------------\n"; +echo "\n--------------------------------------------------------\n"; echo "STEP 2: Checking PHP requirements: \n"; echo "--------------------------------------------------------\n\n";