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 8838-8845
if ( CheckVersion($DBversion) ) {
Link Here
|
8838 |
SetVersion($DBversion); |
8849 |
SetVersion($DBversion); |
8839 |
} |
8850 |
} |
8840 |
|
8851 |
|
|
|
8852 |
#FIXME Will be fixed with the first db rev new style |
8853 |
#The first dbrev should look like this: |
8854 |
#ExecDBRev( $aupd, '13068', 'Refined dbrev', '13068.pl', '3.17.00.031'); |
8855 |
|
8856 |
# This point marks the end of the approved database revisions. |
8857 |
# The following line runs proposed patches found in atomicupdate. On a |
8858 |
# production system, it will [should] not find any. |
8859 |
RunRemainingAtomicUpdates( $aupd ); |
8860 |
|
8841 |
=head1 FUNCTIONS |
8861 |
=head1 FUNCTIONS |
8842 |
|
8862 |
|
|
|
8863 |
=head2 RunRemainingAtomicUpdates |
8864 |
|
8865 |
This subroutine will run all development updates in the atomicupdate |
8866 |
directory. It will skip the official db revisions, that have been |
8867 |
collected in the skipfiles hash. It also skips recently applied |
8868 |
dev updates as recorded in local pref _LocalAtomicUpdates. |
8869 |
|
8870 |
=cut |
8871 |
|
8872 |
sub RunRemainingAtomicUpdates { |
8873 |
my ( $atomicupd ) = @_; |
8874 |
my $loc = $atomicupd->{location}; |
8875 |
my @updates = glob( $loc .'/*'); |
8876 |
foreach my $upd ( sort @updates ) { #sort feels safer here |
8877 |
$upd =~ s/$loc\///; |
8878 |
if( exists $atomicupd->{skipfiles}->{$upd} ) { |
8879 |
#Skip files that belong to official db revisions |
8880 |
print "Skipping $upd as installed official db rev\n"; |
8881 |
next; |
8882 |
} |
8883 |
if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) { |
8884 |
#Skip files that have recently been applied |
8885 |
#Note that an official db rev erases this list |
8886 |
print "Skipping $upd as recently applied dev update\n"; |
8887 |
next; |
8888 |
} |
8889 |
if( $upd !~ /\.(txt|sql|pl)$/ ) { |
8890 |
print "Unsupported file format: $upd\n"; |
8891 |
next; |
8892 |
} |
8893 |
ExecDBRev( $atomicupd, '', '', $upd, 'XXX' ); |
8894 |
} |
8895 |
} |
8896 |
|
8897 |
=head2 ExecDBRev |
8898 |
|
8899 |
This subroutine checks if an official db revision should still be |
8900 |
applied. If not, it records the file in the skipfiles hash and returns. |
8901 |
Otherwise it applies the db rev from the atomicupdate directory. |
8902 |
The db rev can be a perl file, a sql file or a txt file. |
8903 |
|
8904 |
=cut |
8905 |
|
8906 |
sub ExecDBRev { |
8907 |
my ( $atomicupd, $bugno, $descr, $file, $version ) = @_; |
8908 |
|
8909 |
my $devrun = $version=~/XXX$/; |
8910 |
$atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file; |
8911 |
return 0 if !CheckVersion($version); |
8912 |
|
8913 |
my $rv; |
8914 |
if( $file =~ /\.txt$/ ) { |
8915 |
#This dbrev prints some warning |
8916 |
my $contents= read_file( $atomicupd->{location}. "/$file" ); |
8917 |
print $contents; |
8918 |
$rv = 1; |
8919 |
} elsif( $file =~ /\.pl$/ ) { |
8920 |
#Run perl script |
8921 |
$rv = do $atomicupd->{location}. "/$file"; |
8922 |
if( !$rv ) { |
8923 |
print "ERROR: $@\n" if $@; |
8924 |
print "ERROR: $!\n" if $!; |
8925 |
$rv = 1 if !$! && !$@; #apparently, the file does not end with 1; |
8926 |
} |
8927 |
} elsif( $file =~ /\.sql$/ ) { |
8928 |
#Run sql file via installer |
8929 |
my $installer = C4::Installer->new(); |
8930 |
$rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1; |
8931 |
#Note: load_sql already warns |
8932 |
} else { |
8933 |
print "DB rev $version contains unsupported file $file\n"; |
8934 |
$rv = 0; |
8935 |
} |
8936 |
|
8937 |
if( $devrun ) { |
8938 |
print "Dev upgrade $file done\n"; |
8939 |
_atomic_memory( $atomicupd, $file ) if $rv; |
8940 |
} else { |
8941 |
_atomic_memory( $atomicupd ); #Official db rev clears the atomic pref |
8942 |
SetVersion($version); |
8943 |
print "Upgrade to $version done (Bug $bugno - $descr)\n"; |
8944 |
} |
8945 |
} |
8946 |
|
8947 |
sub _atomic_memory { |
8948 |
my ( $atomicupd, $upd ) = @_; |
8949 |
$atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": ''; |
8950 |
C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} ); |
8951 |
} |
8952 |
|
8843 |
=head2 TableExists($table) |
8953 |
=head2 TableExists($table) |
8844 |
|
8954 |
|
8845 |
=cut |
8955 |
=cut |
8846 |
- |
|
|