Skip to content

A free open source IT asset/license management system

Added php version check to upgrade.php

snipe84f20b62878f
diff --git a/upgrade.php b/upgrade.php
index 3c7889b455..44a7e6679a 100644
--- a/upgrade.php
+++ b/upgrade.php
@@ -1,6 +1,8 @@
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
+$required_version = '7.1.3';
+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
echo "Skipping user check as it is not supported on Windows\n";
} else {
@@ -13,7 +15,9 @@ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
}
-($argv[1]) ? $branch = $argv[1] : $branch = 'master';
+// Check if a branch or tag was passed in the command line,
+// otherwise just use master
+(array_key_exists('1', $argv)) ? $branch = $argv[1] : $branch = 'master';
echo "Welcome to the Snipe-IT upgrader.\n\n";
echo "Please note that this script will not download the latest Snipe-IT \n";
@@ -28,20 +32,38 @@ echo "!! https://snipe-it.readme.io/docs/upgrading-to-v4\n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "--------------------------------------------------------\n";
-echo "STEP 1: Backing up database: \n";
+echo "STEP 1: Checking PHP requirements: \n";
+echo "--------------------------------------------------------\n\n";
+
+echo "Current PHP version: " . PHP_VERSION . "\n\n";
+
+if (version_compare(PHP_VERSION, $required_version, '<')) {
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+ echo "This version of PHP is not compatible with Snipe-IT.\n";
+ echo "Snipe-IT requires PHP version ".$required_version." or greater. Please upgrade \n";
+ echo "your server's version of PHP (mod and cli) and try running this script again.\n\n\n";
+ exit;
+
+} else {
+ echo "PHP version: " . PHP_VERSION . " is at least ".$required_version." - continuing... \n\n";
+}
+
+
+echo "--------------------------------------------------------\n";
+echo "STEP 2: Backing up database: \n";
echo "--------------------------------------------------------\n\n";
$backup = shell_exec('php artisan snipeit:backup');
echo '-- '.$backup."\n\n";
echo "--------------------------------------------------------\n";
-echo "STEP 2: Putting application into maintenance mode: \n";
+echo "STEP 3: Putting application into maintenance mode: \n";
echo "--------------------------------------------------------\n\n";
$down = shell_exec('php artisan down');
echo '-- '.$down."\n\n";
echo "--------------------------------------------------------\n";
-echo "STEP 3: Pulling latest from Git (".$branch." branch): \n";
+echo "STEP 4: Pulling latest from Git (".$branch." branch): \n";
echo "--------------------------------------------------------\n\n";
$git_version = shell_exec('git --version');
@@ -61,7 +83,7 @@ if ((strpos('git version', $git_version)) === false) {
echo "--------------------------------------------------------\n";
-echo "Step 4: Cleaning up old cached files:\n";
+echo "Step 5: Cleaning up old cached files:\n";
echo "--------------------------------------------------------\n\n";
@@ -97,7 +119,7 @@ echo '-- '.$view_clear;
echo "\n";
echo "--------------------------------------------------------\n";
-echo "Step 5: Updating composer dependencies:\n";
+echo "Step 6: Updating composer dependencies:\n";
echo "(This may take an moment.)\n";
echo "--------------------------------------------------------\n\n";
@@ -119,7 +141,7 @@ echo $composer."\n\n";
echo "--------------------------------------------------------\n";
-echo "Step 6: Migrating database:\n";
+echo "Step 7: Migrating database:\n";
echo "--------------------------------------------------------\n\n";
$migrations = shell_exec('php artisan migrate --force');
@@ -127,7 +149,7 @@ echo '-- '.$migrations."\n\n";
echo "--------------------------------------------------------\n";
-echo "Step 7: Checking for OAuth keys:\n";
+echo "Step 8: Checking for OAuth keys:\n";
echo "--------------------------------------------------------\n\n";
@@ -141,7 +163,7 @@ if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-p
echo "--------------------------------------------------------\n";
-echo "Step 8: Caching routes and config:\n";
+echo "Step 9: Caching routes and config:\n";
echo "--------------------------------------------------------\n\n";
$config_cache = shell_exec('php artisan config:cache');
$route_cache = shell_exec('php artisan route:cache');