Lines 38-50
use C4::Context;
Link Here
|
38 |
use C4::Installer; |
38 |
use C4::Installer; |
39 |
use C4::Dates; |
39 |
use C4::Dates; |
40 |
|
40 |
|
|
|
41 |
use File::Slurp; |
41 |
use MARC::Record; |
42 |
use MARC::Record; |
42 |
use MARC::File::XML ( BinaryEncoding => 'utf8' ); |
43 |
use MARC::File::XML ( BinaryEncoding => 'utf8' ); |
43 |
|
44 |
|
|
|
45 |
use constant ATOMICUPD_PREF => '_LocalAtomicUpdates'; |
46 |
|
44 |
# FIXME - The user might be installing a new database, so can't rely |
47 |
# FIXME - The user might be installing a new database, so can't rely |
45 |
# on /etc/koha.conf anyway. |
48 |
# on /etc/koha.conf anyway. |
46 |
|
49 |
|
47 |
my $debug = 0; |
50 |
my $debug = 0; |
|
|
51 |
my $aupd = { #hash for atomic updates |
52 |
location => C4::Context->config('intranetdir')."/installer/data/mysql/atomicupdate", |
53 |
remember => C4::Context->preference(ATOMICUPD_PREF)//'', |
54 |
skipfiles => { |
55 |
'Bug-4246-Talking-Tech-itiva-phone-notifications.pl' => 1, |
56 |
'oai_sets.sql' => 1, |
57 |
}, |
58 |
}; |
48 |
|
59 |
|
49 |
my ( |
60 |
my ( |
50 |
$sth, $sti, |
61 |
$sth, $sti, |
Lines 9658-9663
if(CheckVersion($DBversion)) {
Link Here
|
9658 |
|
9669 |
|
9659 |
=head1 FUNCTIONS |
9670 |
=head1 FUNCTIONS |
9660 |
|
9671 |
|
|
|
9672 |
=head2 RunRemainingAtomicUpdates |
9673 |
|
9674 |
This subroutine will run all development updates in the atomicupdate |
9675 |
directory. It will skip the official db revisions, that have been |
9676 |
collected in the skipfiles hash. It also skips recently applied |
9677 |
dev updates as recorded in local pref _LocalAtomicUpdates. |
9678 |
|
9679 |
=cut |
9680 |
|
9681 |
sub RunRemainingAtomicUpdates { |
9682 |
my ( $atomicupd ) = @_; |
9683 |
my $loc = $atomicupd->{location}; |
9684 |
my @updates = glob( $loc .'/*'); |
9685 |
foreach my $upd ( sort @updates ) { #sort feels safer here |
9686 |
$upd =~ s/$loc\///; |
9687 |
if( exists $atomicupd->{skipfiles}->{$upd} ) { |
9688 |
next; # Skip official db revision |
9689 |
} |
9690 |
if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) { |
9691 |
#Skip files that have recently been applied |
9692 |
#Note that an official db rev erases this list |
9693 |
print "Skipping $upd as recently applied dev update\n"; |
9694 |
next; |
9695 |
} |
9696 |
if( $upd !~ /\.(txt|sql|pl)$/ ) { |
9697 |
print "Unsupported file format: $upd\n"; |
9698 |
next; |
9699 |
} |
9700 |
ExecDBRev( $atomicupd, '', '', $upd, 'XXX' ); |
9701 |
} |
9702 |
} |
9703 |
|
9704 |
=head2 ExecDBRev |
9705 |
|
9706 |
This subroutine checks if an official db revision should still be |
9707 |
applied. If not, it records the file in the skipfiles hash and returns. |
9708 |
Otherwise it applies the db rev from the atomicupdate directory. |
9709 |
The db rev can be a perl file, a sql file or a txt file. |
9710 |
|
9711 |
=cut |
9712 |
|
9713 |
sub ExecDBRev { |
9714 |
my ( $atomicupd, $bugno, $descr, $file, $version ) = @_; |
9715 |
|
9716 |
my $devrun = $version=~/XXX$/; |
9717 |
$atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file; |
9718 |
return 0 if !CheckVersion($version); |
9719 |
|
9720 |
my $rv; |
9721 |
if( $file =~ /\.txt$/ ) { |
9722 |
#This dbrev prints some warning |
9723 |
my $contents= read_file( $atomicupd->{location}. "/$file" ); |
9724 |
print $contents; |
9725 |
$rv = 1; |
9726 |
} elsif( $file =~ /\.pl$/ ) { |
9727 |
#Run perl script |
9728 |
$rv = do $atomicupd->{location}. "/$file"; |
9729 |
if( !$rv ) { |
9730 |
print "ERROR: $@\n" if $@; |
9731 |
print "ERROR: $!\n" if $! && !$@; |
9732 |
$rv = 1 if !$! && !$@; #apparently, the file does not end with 1; |
9733 |
} |
9734 |
} elsif( $file =~ /\.sql$/ ) { |
9735 |
#Run sql file via installer |
9736 |
my $installer = C4::Installer->new(); |
9737 |
$rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1; |
9738 |
#Note: load_sql already warns |
9739 |
} else { |
9740 |
print "DB rev $version contains unsupported file $file\n"; |
9741 |
$rv = 0; |
9742 |
} |
9743 |
|
9744 |
if( $devrun ) { |
9745 |
print "Dev upgrade $file done\n"; |
9746 |
_atomic_memory( $atomicupd, $file ) if $rv; |
9747 |
} else { |
9748 |
_atomic_memory( $atomicupd ); #Official db rev clears the atomic pref |
9749 |
SetVersion($version); |
9750 |
print "Upgrade to $version done (Bug $bugno - $descr)\n"; |
9751 |
} |
9752 |
} |
9753 |
|
9754 |
sub _atomic_memory { |
9755 |
my ( $atomicupd, $upd ) = @_; |
9756 |
$atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": ''; |
9757 |
C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} ); |
9758 |
} |
9759 |
|
9661 |
=head2 TableExists($table) |
9760 |
=head2 TableExists($table) |
9662 |
|
9761 |
|
9663 |
=cut |
9762 |
=cut |
Lines 9767-9770
sub CheckVersion {
Link Here
|
9767 |
} |
9866 |
} |
9768 |
} |
9867 |
} |
9769 |
|
9868 |
|
|
|
9869 |
RunRemainingAtomicUpdates( $aupd ); |
9770 |
exit; |
9870 |
exit; |
9771 |
- |
|
|