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; |