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