Skip to content

Commit

Permalink
Check for max PHP version
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>
  • Loading branch information
snipe committed Jul 5, 2023
1 parent 35039cd commit a9d175a
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions upgrade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');

$required_php_min = '7.4.0';
$php_min_works = '7.4.0';
$php_max_wontwork = '8.2.0';


if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) {
echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n";
Expand Down Expand Up @@ -123,34 +125,35 @@

if ($env_bad !='') {

echo "\n--------------------- !! ERROR !! ----------------------\n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!!! .ENV FILE ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "Your .env file is misconfigured. Upgrade cannot continue.\n";
echo "--------------------------------------------------------\n\n";
echo $env_bad;
echo "\n\n--------------------------------------------------------\n";
echo "ABORTING THE INSTALLER \n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!! ABORTING THE UPGRADER !!!!!!!!!!!!!!!!!!!!!!\n";
echo "Please correct the issues above in ".getcwd()."/.env and try again.\n";
echo "--------------------------------------------------------\n";
exit;
}


echo "\n--------------------------------------------------------\n";
echo "STEP 2: Checking PHP requirements: \n";
echo "STEP 2: Checking PHP requirements: (Required PHP >=". $php_min_works. " - <".$php_max_wontwork.") \n";
echo "--------------------------------------------------------\n\n";

if (version_compare(PHP_VERSION, $required_php_min, '<')) {
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "This version of PHP (".PHP_VERSION.") is not compatible with Snipe-IT.\n";
echo "Snipe-IT requires PHP version ".$required_php_min." or greater. Please upgrade \n";
echo "your version of PHP (web/php-fcgi and cli) and try running this script again.\n\n\n";
exit;
if ((version_compare(phpversion(), $php_min_works, '>=')) && (version_compare(phpversion(), $php_max_wontwork, '<'))) {

} else {
echo "Current PHP version: (" . PHP_VERSION . ") is at least ".$required_php_min." - continuing... \n";
echo "√ Current PHP version: (" . phpversion() . ") is at least " . $php_min_works . " and less than ".$php_max_wontwork."! Continuing... \n";
echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path'));
}

} else {
echo "!!!!!!!!!!!!!!!!!!!!!!!!! PHP VERSION ERROR !!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "This version of PHP (".phpversion().") is NOT compatible with Snipe-IT.\n";
echo "Snipe-IT requires PHP versions between ".$php_min_works." and ".$php_max_wontwork.".\n";
echo "Please install a compatible version of PHP and re-run this script again. \n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!! ABORTING THE UPGRADER !!!!!!!!!!!!!!!!!!!!!!\n";
exit;
}

echo "Checking Required PHP extensions... \n\n";

Expand Down

0 comments on commit a9d175a

Please sign in to comment.