View | Details | Raw Unified | Return to bug 34088
Collapse All | Expand All

(-)a/C4/Installer.pm (-17 / +4 lines)
Lines 29-34 use DBI; Link Here
29
use C4::Context;
29
use C4::Context;
30
use Koha::Schema;
30
use Koha::Schema;
31
use Koha;
31
use Koha;
32
use Koha::Installer;
32
33
33
use vars qw(@ISA @EXPORT);
34
use vars qw(@ISA @EXPORT);
34
BEGIN {
35
BEGIN {
Lines 823-839 sub generate_output_db_entry { Link Here
823
}
824
}
824
825
825
sub get_atomic_updates {
826
sub get_atomic_updates {
826
    my @atomic_upate_files;
827
    my $atomic_updates = Koha::Installer::get_atomic_updates();
827
    # if there is anything in the atomicupdate, read and execute it.
828
    return $atomic_updates;
828
    my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/';
829
    opendir( my $dirh, $update_dir );
830
    foreach my $file ( sort readdir $dirh ) {
831
        next if $file !~ /\.(perl|pl)$/;  #skip other files
832
        next if $file eq 'skeleton.perl' || $file eq 'skeleton.pl'; # skip the skeleton files
833
834
        push @atomic_upate_files, $file;
835
    }
836
    return \@atomic_upate_files;
837
}
829
}
838
830
839
sub run_atomic_updates {
831
sub run_atomic_updates {
Lines 929-940 to a number, with just 1 . Link Here
929
921
930
sub TransformToNum {
922
sub TransformToNum {
931
    my $version = shift;
923
    my $version = shift;
932
    # remove the 3 last . to have a Perl number
924
    $version = Koha::Installer::TransformToNum($version);
933
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
934
    # three X's at the end indicate that you are testing patch with dbrev
935
    # change it into 999
936
    # prevents error on a < comparison between strings (should be: lt)
937
    $version =~ s/XXX$/999/;
938
    return $version;
925
    return $version;
939
}
926
}
940
927
(-)a/Koha/Installer.pm (+79 lines)
Line 0 Link Here
1
package Koha::Installer;
2
3
use Modern::Perl;
4
5
require Koha;
6
require Koha::Database;
7
require Koha::Config;
8
9
sub needs_update {
10
    my $needs_update = 1;
11
    my $dbh          = Koha::Database::dbh();
12
    my $sql          = "SELECT value FROM systempreferences WHERE variable = 'Version'";
13
    my $sth          = $dbh->prepare($sql);
14
    $sth->execute();
15
    my $row          = $sth->fetchrow_arrayref();
16
    my $db_version   = $row->[0];
17
    my $koha_version = Koha->version;
18
    my $code_version = TransformToNum($koha_version);
19
20
    if ( $db_version == $code_version ) {
21
        $needs_update = 0;
22
    }
23
24
    #NOTE: We apply atomic updates even when the DB and code versions align
25
    my $atomic_updates = get_atomic_updates();
26
    if (@$atomic_updates) {
27
        $needs_update = 1;
28
    }
29
30
    return $needs_update;
31
}
32
33
=head2 TransformToNum
34
35
Transform the Koha version from a 4 parts string
36
to a number, with just 1 .
37
38
=cut
39
40
sub TransformToNum {
41
    my $version = shift;
42
43
    # remove the 3 last . to have a Perl number
44
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
45
46
    # three X's at the end indicate that you are testing patch with dbrev
47
    # change it into 999
48
    # prevents error on a < comparison between strings (should be: lt)
49
    $version =~ s/XXX$/999/;
50
    return $version;
51
}
52
53
=head2 get_atomic_updates
54
55
Get atomic database updates
56
57
=cut
58
59
sub get_atomic_updates {
60
    my @atomic_upate_files;
61
62
    my $conf_fname  = Koha::Config->guess_koha_conf;
63
    my $config      = Koha::Config->get_instance($conf_fname);
64
    my $intranetdir = $config->{config}->{intranetdir};
65
66
    # if there is anything in the atomicupdate, read and execute it.
67
    my $update_dir = $intranetdir . '/installer/data/mysql/atomicupdate/';
68
    opendir( my $dirh, $update_dir );
69
    my @stuff = sort readdir $dirh;
70
    foreach my $file (@stuff) {
71
        next if $file !~ /\.(perl|pl)$/;                               #skip other files
72
        next if $file eq 'skeleton.perl' || $file eq 'skeleton.pl';    # skip the skeleton files
73
74
        push @atomic_upate_files, $file;
75
    }
76
    return \@atomic_upate_files;
77
}
78
79
1;
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 27-32 Link Here
27
27
28
# NOTE: Please keep the version in kohaversion.pl up-to-date!
28
# NOTE: Please keep the version in kohaversion.pl up-to-date!
29
29
30
BEGIN {
31
    use Koha::Installer;
32
    if ( !Koha::Installer->needs_update ) {
33
       exit;
34
    }
35
}
36
30
use Modern::Perl;
37
use Modern::Perl;
31
38
32
use feature 'say';
39
use feature 'say';
33
- 

Return to bug 34088