I would like to have a function like PHP's version_compare()
which let me compare version and consider minor/major version numbers.
My method should look like
function my_version_compare($new_version, $old_version, $operator, $only_minor = false){
...
return (bool) $do_update;
}
a major version update is from 2.1
to 2.2
for instance while a minor is from 2.1
to 2.1.1
my_version_compare('2.2', '2.1', '>', false); //true
my_version_compare('2.2', '2.1', '>', true); //false
my_version_compare('2.1.1', '2.1', '>', false); //true
my_version_compare('2.1.1', '2.1', '>', true); //true
Basically I like to let the users decide if an auto update should be made on minor versions only or in any case
What I currently have works just with 2.x
to 3.x
updates:
function my_version_compare($new_version, $old_version, $operator, $only_minor = false){
if($only_minor){
return (bool) version_compare($new_version, $old_version, $operator)
&& !version_compare(intval($new_version), intval($old_version), $operator);
}else{
return (bool) version_compare($new_version, $old_version, $operator);
}
}
version_compare()
can handle and doing it from scratch is often not future proof