Пример #1
0
 /**
  * @param $currentVersion
  *
  * @return array|bool
  */
 public function getReleaseToUpgradeTo($currentVersion)
 {
     $currentVersion = new version($currentVersion);
     $releases = $this->getAllReleases();
     $releases = $this->filterPreReleasesAndDrafts($releases);
     $releases = $this->filterReleasesWithoutZipAsset($releases);
     if (count($releases) == 0) {
         return false;
     }
     // Sort by highest / biggest release first.
     usort($releases, function ($a, $b) {
         return version::rcompare($a['tag_name'], $b['tag_name']);
     });
     // Now we need to check whether we already installed the biggest available patch update.
     // I.e. if C1.C2.C3 is the currently installed version, check if there is a version C1.C2.X where X
     // is bigger than C3. If so, always update to this version first, regardless of higher available
     // versions.
     $highestPatchRelease = $this->getHighestPatchRelease($currentVersion, $releases);
     if ($highestPatchRelease === false) {
         // Somehow not even the currently installed version could be found in the GitHub releases.
         return false;
     }
     if (!version::eq($this->getVersionFromRelease($highestPatchRelease), $currentVersion)) {
         // The currently installed version is not equal to the highest patch version.
         // So upgrade to this one first.
         return $highestPatchRelease;
     }
     // If we reach this point, we already have the highest patch version installed.
     // Search for the highest C1.(C2+1).X version then.
     $highestPatchReleaseOfNextMinorVersion = $this->getHighestPatchReleaseOfNextMinorVersion($currentVersion, $releases);
     if ($highestPatchReleaseOfNextMinorVersion === false) {
         // No new version available apparently.
         return false;
     }
     return $highestPatchReleaseOfNextMinorVersion;
 }