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 (+91 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
=head1 API
10
11
=head2 Class methods
12
13
=head3 needs_update
14
15
Determines if an update is needed by checking
16
the database version, the code version, and whether
17
there are any atomic updates available.
18
19
=cut
20
21
sub needs_update {
22
    my $needs_update = 1;
23
    my $dbh          = Koha::Database::dbh();
24
    my $sql          = "SELECT value FROM systempreferences WHERE variable = 'Version'";
25
    my $sth          = $dbh->prepare($sql);
26
    $sth->execute();
27
    my $row          = $sth->fetchrow_arrayref();
28
    my $db_version   = $row->[0];
29
    my $koha_version = Koha->version;
30
    my $code_version = TransformToNum($koha_version);
31
32
    if ( $db_version == $code_version ) {
33
        $needs_update = 0;
34
    }
35
36
    #NOTE: We apply atomic updates even when the DB and code versions align
37
    my $atomic_updates = get_atomic_updates();
38
    if (@$atomic_updates) {
39
        $needs_update = 1;
40
    }
41
42
    return $needs_update;
43
}
44
45
=head3 TransformToNum
46
47
Transform the Koha version from a 4 parts string
48
to a number, with just 1 .
49
50
=cut
51
52
sub TransformToNum {
53
    my $version = shift;
54
55
    # remove the 3 last . to have a Perl number
56
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
57
58
    # three X's at the end indicate that you are testing patch with dbrev
59
    # change it into 999
60
    # prevents error on a < comparison between strings (should be: lt)
61
    $version =~ s/XXX$/999/;
62
    return $version;
63
}
64
65
=head3 get_atomic_updates
66
67
Get atomic database updates
68
69
=cut
70
71
sub get_atomic_updates {
72
    my @atomic_upate_files;
73
74
    my $conf_fname  = Koha::Config->guess_koha_conf;
75
    my $config      = Koha::Config->get_instance($conf_fname);
76
    my $intranetdir = $config->{config}->{intranetdir};
77
78
    # if there is anything in the atomicupdate, read and execute it.
79
    my $update_dir = $intranetdir . '/installer/data/mysql/atomicupdate/';
80
    opendir( my $dirh, $update_dir );
81
    my @stuff = sort readdir $dirh;
82
    foreach my $file (@stuff) {
83
        next if $file !~ /\.(perl|pl)$/;                               #skip other files
84
        next if $file eq 'skeleton.perl' || $file eq 'skeleton.pl';    # skip the skeleton files
85
86
        push @atomic_upate_files, $file;
87
    }
88
    return \@atomic_upate_files;
89
}
90
91
1;
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 29-34 Link Here
29
29
30
use Modern::Perl;
30
use Modern::Perl;
31
31
32
BEGIN {
33
    use Koha::Installer;
34
    if ( !Koha::Installer->needs_update ) {
35
       exit;
36
    }
37
}
38
32
use feature 'say';
39
use feature 'say';
33
40
34
# CPAN modules
41
# CPAN modules
35
- 

Return to bug 34088