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 8869-8874
if ( CheckVersion($DBversion) ) {
Link Here
|
8869 |
|
8880 |
|
8870 |
=head1 FUNCTIONS |
8881 |
=head1 FUNCTIONS |
8871 |
|
8882 |
|
|
|
8883 |
=head2 RunRemainingAtomicUpdates |
8884 |
|
8885 |
This subroutine will run all development updates in the atomicupdate |
8886 |
directory. It will skip the official db revisions, that have been |
8887 |
collected in the skipfiles hash. It also skips recently applied |
8888 |
dev updates as recorded in local pref _LocalAtomicUpdates. |
8889 |
|
8890 |
=cut |
8891 |
|
8892 |
sub RunRemainingAtomicUpdates { |
8893 |
my ( $atomicupd ) = @_; |
8894 |
my $loc = $atomicupd->{location}; |
8895 |
my @updates = glob( $loc .'/*'); |
8896 |
foreach my $upd ( sort @updates ) { #sort feels safer here |
8897 |
$upd =~ s/$loc\///; |
8898 |
if( exists $atomicupd->{skipfiles}->{$upd} ) { |
8899 |
next; # Skip official db revision |
8900 |
} |
8901 |
if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) { |
8902 |
#Skip files that have recently been applied |
8903 |
#Note that an official db rev erases this list |
8904 |
print "Skipping $upd as recently applied dev update\n"; |
8905 |
next; |
8906 |
} |
8907 |
if( $upd !~ /\.(txt|sql|pl)$/ ) { |
8908 |
print "Unsupported file format: $upd\n"; |
8909 |
next; |
8910 |
} |
8911 |
ExecDBRev( $atomicupd, '', '', $upd, 'XXX' ); |
8912 |
} |
8913 |
} |
8914 |
|
8915 |
=head2 ExecDBRev |
8916 |
|
8917 |
This subroutine checks if an official db revision should still be |
8918 |
applied. If not, it records the file in the skipfiles hash and returns. |
8919 |
Otherwise it applies the db rev from the atomicupdate directory. |
8920 |
The db rev can be a perl file, a sql file or a txt file. |
8921 |
|
8922 |
=cut |
8923 |
|
8924 |
sub ExecDBRev { |
8925 |
my ( $atomicupd, $bugno, $descr, $file, $version ) = @_; |
8926 |
|
8927 |
my $devrun = $version=~/XXX$/; |
8928 |
$atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file; |
8929 |
return 0 if !CheckVersion($version); |
8930 |
|
8931 |
my $rv; |
8932 |
if( $file =~ /\.txt$/ ) { |
8933 |
#This dbrev prints some warning |
8934 |
my $contents= read_file( $atomicupd->{location}. "/$file" ); |
8935 |
print $contents; |
8936 |
$rv = 1; |
8937 |
} elsif( $file =~ /\.pl$/ ) { |
8938 |
#Run perl script |
8939 |
$rv = do $atomicupd->{location}. "/$file"; |
8940 |
if( !$rv ) { |
8941 |
print "ERROR: $@\n" if $@; |
8942 |
print "ERROR: $!\n" if $!; |
8943 |
$rv = 1 if !$! && !$@; #apparently, the file does not end with 1; |
8944 |
} |
8945 |
} elsif( $file =~ /\.sql$/ ) { |
8946 |
#Run sql file via installer |
8947 |
my $installer = C4::Installer->new(); |
8948 |
$rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1; |
8949 |
#Note: load_sql already warns |
8950 |
} else { |
8951 |
print "DB rev $version contains unsupported file $file\n"; |
8952 |
$rv = 0; |
8953 |
} |
8954 |
|
8955 |
if( $devrun ) { |
8956 |
print "Dev upgrade $file done\n"; |
8957 |
_atomic_memory( $atomicupd, $file ) if $rv; |
8958 |
} else { |
8959 |
_atomic_memory( $atomicupd ); #Official db rev clears the atomic pref |
8960 |
SetVersion($version); |
8961 |
print "Upgrade to $version done (Bug $bugno - $descr)\n"; |
8962 |
} |
8963 |
} |
8964 |
|
8965 |
sub _atomic_memory { |
8966 |
my ( $atomicupd, $upd ) = @_; |
8967 |
$atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": ''; |
8968 |
C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} ); |
8969 |
} |
8970 |
|
8872 |
=head2 TableExists($table) |
8971 |
=head2 TableExists($table) |
8873 |
|
8972 |
|
8874 |
=cut |
8973 |
=cut |
Lines 8978-8981
sub CheckVersion {
Link Here
|
8978 |
} |
9077 |
} |
8979 |
} |
9078 |
} |
8980 |
|
9079 |
|
|
|
9080 |
RunRemainingAtomicUpdates( $aupd ); |
8981 |
exit; |
9081 |
exit; |
8982 |
- |
|
|