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