use the version compare of version.froxlor.org also in froxlor, thx for the hint to byteworkshosting
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -49,14 +49,78 @@ function versionInUpdate($current_version, $version_to_check)
|
|||||||
if (!isFroxlor()) {
|
if (!isFroxlor()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$pos_a = strpos($current_version, '-svn');
|
|
||||||
$pos_b = strpos($version_to_check, '-svn');
|
return (version_compare2($current_version, $version_to_check) == -1 ? true : false);
|
||||||
// if we compare svn-versions, we have to add -svn0 to the version
|
}
|
||||||
// to compare it correctly
|
|
||||||
if($pos_a === false && $pos_b !== false)
|
/**
|
||||||
{
|
* compare of froxlor versions
|
||||||
$current_version.= '-svn9999';
|
*
|
||||||
|
* @param string $a
|
||||||
|
* @param string $b
|
||||||
|
*
|
||||||
|
* @return integer 0 if equal, 1 if a>b and -1 if b>a
|
||||||
|
*/
|
||||||
|
function version_compare2($a, $b) {
|
||||||
|
|
||||||
|
// split version into pieces and remove trailing .0
|
||||||
|
$a = explode(".", rtrim($a, ".0"));
|
||||||
|
$b = explode(".", rtrim($b, ".0"));
|
||||||
|
|
||||||
|
// -svn or -rc ?
|
||||||
|
if (stripos($a[count($a)-1], '-') !== false) {
|
||||||
|
$x = explode("-", $a[count($a)-1]);
|
||||||
|
$a[count($a)-1] = $x[0];
|
||||||
|
if (stripos($x[1], 'rc') !== false) {
|
||||||
|
$a[] = '1'; // rc > svn
|
||||||
|
// number of rc
|
||||||
|
$a[] = substr($x[1], 2);
|
||||||
|
}
|
||||||
|
else if (stripos($x[1], 'svn') !== false) {
|
||||||
|
$a[] = '0'; // svn < rc
|
||||||
|
// number of svn
|
||||||
|
$a[] = substr($x[1], 3);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// unknown version string
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// same with $b
|
||||||
|
if (stripos($b[count($b)-1], '-') !== false) {
|
||||||
|
$x = explode("-", $b[count($b)-1]);
|
||||||
|
$b[count($b)-1] = $x[0];
|
||||||
|
if (stripos($x[1], 'rc') !== false) {
|
||||||
|
$b[] = '1'; // rc > svn
|
||||||
|
// number of rc
|
||||||
|
$b[] = substr($x[1], 2);
|
||||||
|
}
|
||||||
|
else if (stripos($x[1], 'svn') !== false) {
|
||||||
|
$b[] = '0'; // svn < rc
|
||||||
|
// number of svn
|
||||||
|
$b[] = substr($x[1], 3);
|
||||||
|
}
|
||||||
|
else { echo "dafuq?!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return version_compare($current_version, $version_to_check, '<');
|
foreach ($a as $depth => $aVal) {
|
||||||
|
// iterate over each piece of A
|
||||||
|
if (isset($b[$depth])) {
|
||||||
|
// if B matches A to this depth, compare the values
|
||||||
|
if ($aVal > $b[$depth]) {
|
||||||
|
return 1; // A > B
|
||||||
|
}
|
||||||
|
else if ($aVal < $b[$depth]) {
|
||||||
|
return -1; // B > A
|
||||||
|
}
|
||||||
|
// an equal result is inconclusive at this point
|
||||||
|
} else {
|
||||||
|
// if B does not match A to this depth, then A comes after B in sort order
|
||||||
|
return 1; // so A > B
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// at this point, we know that to the depth that A and B extend to, they are equivalent.
|
||||||
|
// either the loop ended because A is shorter than B, or both are equal.
|
||||||
|
return (count($a) < count($b)) ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user