[Koha-bugs] [Bug 29008] Warning when checking Koha version in plugins

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Nov 2 16:41:50 CET 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29008

--- Comment #7 from Martin Renvoize <martin.renvoize at ptfs-europe.com> ---
As an example..

I have 

```
use version;

sub _version_check {
    my ( $self, $minversion ) = @_;

    my $kohaversion = Koha::version();
    return ( version->parse($kohaversion) > version->parse($minversion) );
}
```

Which is what I've found to be most reliable to date.

In the past I've have

```
sub _version_check {
    my ( $self, $minversion ) = @_;

    $minversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;

    my $kohaversion = Koha::version();

    # remove the 3 last . to have a Perl number
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;

    return ( $kohaversion > $minversion );
}
```

The core one is

```
sub _version_compare {                                                          
    my @args = @_;                                                              

    if ( $args[0]->isa('Koha::Plugins::Base') ) {                               
        shift @args;                                                            
    }                                                                           

    my $ver1 = shift @args || 0;
    my $ver2 = shift @args || 0;

    my @v1 = split /[.+:~-]/, $ver1;
    my @v2 = split /[.+:~-]/, $ver2;

    for ( my $i = 0 ; $i < max( scalar(@v1), scalar(@v2) ) ; $i++ ) {

        # Add missing version parts if one string is shorter than the other
        # i.e. 0 should be lt 0.2.1 and not equal, so we append .0
        # 0.0.0 <=> 0.2.1 = -1
        push( @v1, 0 ) unless defined( $v1[$i] );
        push( @v2, 0 ) unless defined( $v2[$i] );
        if ( int( $v1[$i] ) > int( $v2[$i] ) ) {
            return 1;
        }
        elsif ( int( $v1[$i] ) < int( $v2[$i] ) ) {
            return -1;
        }
    }
    return 0;
}
```

And they're all different from what you're doing here...

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list