Skip to content

Commit

Permalink
Fix bug with remote minimum PHP version determination
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 18, 2018
1 parent 39783df commit 4259d01
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
26 changes: 26 additions & 0 deletions system/src/Grav/Common/GPM/Remote/GravCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GravCore extends AbstractPackageCollection

private $version;
private $date;
private $min_php;

/**
* @param bool $refresh
Expand All @@ -37,6 +38,7 @@ public function __construct($refresh = false, $callback = null)
$this->data = json_decode($this->raw, true);
$this->version = isset($this->data['version']) ? $this->data['version'] : '-';
$this->date = isset($this->data['date']) ? $this->data['date'] : '-';
$this->min_php = isset($this->data['min_php']) ? $this->data['min_php'] : null;

if (isset($this->data['assets'])) {
foreach ((array)$this->data['assets'] as $slug => $data) {
Expand Down Expand Up @@ -92,6 +94,11 @@ public function getDate()
return $this->date;
}

/**
* Determine if this version of Grav is eligible to be updated
*
* @return mixed
*/
public function isUpdatable()
{
return version_compare(GRAV_VERSION, $this->getVersion(), '<');
Expand All @@ -107,6 +114,25 @@ public function getVersion()
return $this->version;
}

/**
* Returns the minimum PHP version
*
* @return null|string
*/
public function getMinPHPVersion()
{
// If non min set, assume current PHP version
if (is_null($this->min_php)) {
$this->min_php = phpversion();
}
return $this->min_php;
}

/**
* Is this installation symlinked?
*
* @return bool
*/
public function isSymlink()
{
return is_link(GRAV_ROOT . DS . 'index.php');
Expand Down
20 changes: 19 additions & 1 deletion system/src/Grav/Common/GPM/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Upgrader
*/
private $remote;

private $min_php;

/**
* Creates a new GPM instance with Local and Remote packages available
*
Expand Down Expand Up @@ -89,17 +91,33 @@ public function getChangelog($diff = null)
}

/**
* Make sure this meets minimum PHP requirements
*
* @return bool
*/
public function meetsRequirements()
{
if (version_compare(PHP_VERSION, GRAV_PHP_MIN, '<')) {
$current_php_version = phpversion();
if (version_compare($current_php_version, $this->minPHPVersion(), '<')) {
return false;
}

return true;
}

/**
* Get minimum PHP version from remote
*
* @return null
*/
public function minPHPVersion()
{
if (is_null($this->min_php)) {
$this->min_php = $this->remote->getMinPHPVersion();
}
return $this->min_php;
}

/**
* Checks if the currently installed Grav is upgradable to a newer version
*
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Console/Gpm/SelfupgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ protected function serve()
if (!$this->upgrader->meetsRequirements()) {
$this->output->writeln("<red>ATTENTION:</red>");
$this->output->writeln(" Grav has increased the minimum PHP requirement.");
$this->output->writeln(" You are currently running PHP <red>" . PHP_VERSION . "</red>, but PHP <green>" . GRAV_PHP_MIN . "</green> is required.");
$this->output->writeln(" Additional information: <white>http://getgrav.org/blog/changing-php-requirements-to-5.5</white>");
$this->output->writeln(" You are currently running PHP <red>" . phpversion() . "</red>, but PHP <green>" . $this->upgrader->minPHPVersion() . "</green> is required.");
$this->output->writeln(" Additional information: <white>http://getgrav.org/blog/changing-php-requirements</white>");
$this->output->writeln("");
$this->output->writeln("Selfupgrade aborted.");
$this->output->writeln("");
Expand Down

0 comments on commit 4259d01

Please sign in to comment.