Skip to content

Commit

Permalink
Add remote requirements checking to upgrade.php
Browse files Browse the repository at this point in the history
quoted from #14127
    There is a race condition in the upgrade.php file where it can't
    currently know the hard requirements for the version it's upgrading to
    until it does a git pull. By that time, it will have pulled new source
    code that possibly relies on an incompatible version of php, leaving you
    with a broken installation.

    Example: You're running v6.2.x on PHP 7.4, which is fine. v7 requires
    PHP 8.1 or 8.2, but we couldn't know that when we released v6. or v5 for
    that matter. We could change the requirements in the most-recent v6
    version of upgrade.php, but that doesn't help anyone who doesn't upgrade
    first to the most recent v6.

With this change, we implement fetching and incorporating the
requirements data from the remote file.

It's just fetching/decoding a couple of json values that replace the
hard-coded version requirements.

We move the branch checking higher than the php version checking so that
we can use the defined/overridden $branch to decide what branch to pull
the requirements from.
  • Loading branch information
Jeremy Price committed Jan 12, 2024
1 parent 25c9f8e commit 3260557
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions upgrade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');

$php_min_works = '7.4.0';
$php_max_wontwork = '8.2.0';
$app_environment = 'develop';

// 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';


// Fetching most current upgrade requirements from github. Read more here: https://github.com/snipe/snipe-it/pull/14127
$remote_requirements_file = "https://raw.githubusercontent.com/snipe/snipe-it/$branch/.upgrade_requirements.json";
$upgrade_requirements = json_decode(file_get_contents($remote_requirements_file), true);

if (! $upgrade_requirements) {
die("\nERROR: Failed to retrieve remote requirements from $remote_requirements_file\nExiting.\n\n");
}

$php_min_works = $upgrade_requirements['php_min_version'];
$php_max_wontwork = $upgrade_requirements['php_max_wontwork'];
// done fetching requirements


if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) {
Expand All @@ -17,12 +33,6 @@
}


$app_environment = 'develop';

// 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 "--------------------------------------------------------\n";
echo "WELCOME TO THE SNIPE-IT UPGRADER! \n";
echo "--------------------------------------------------------\n\n";
Expand Down

0 comments on commit 3260557

Please sign in to comment.