View | Details | Raw Unified | Return to bug 13068
Collapse All | Expand All

(-)a/installer/data/mysql/updatedatabase.pl (-1 / +99 lines)
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 8800-8808 if ( CheckVersion($DBversion) ) { Link Here
8800
    SetVersion($DBversion);
8811
    SetVersion($DBversion);
8801
}
8812
}
8802
8813
8814
#FIXME Will be fixed with the first db rev new style
8815
#The first dbrev should look like this:
8816
#ExecDBRev( $aupd, '13068', 'Refined dbrev', '13068.pl', '3.17.00.028');
8817
8818
# This point marks the end of the approved database revisions.
8819
# The following line runs proposed patches found in atomicupdate. On a
8820
# production system, it will [should] not find any.
8821
RunRemainingAtomicUpdates( $aupd );
8803
8822
8804
=head1 FUNCTIONS
8823
=head1 FUNCTIONS
8805
8824
8825
=head2 RunRemainingAtomicUpdates
8826
8827
=cut
8828
8829
sub RunRemainingAtomicUpdates {
8830
    my ( $atomicupd ) = @_;
8831
    my $loc = $atomicupd->{location};
8832
    my @updates = glob( $loc .'/*');
8833
    foreach my $upd ( @updates ) {
8834
        $upd =~ s/$loc\///;
8835
        if( exists $atomicupd->{skipfiles}->{$upd} ) {
8836
        #Skip files that belong to official db revisions
8837
print "Skipping $upd\n";
8838
           next;
8839
        }
8840
        if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) {
8841
        #Skip files that have recently been applied
8842
        #Note that an official db rev erases this list
8843
print "Remember $upd\n";
8844
           next;
8845
        }
8846
        if( $upd !~ /\.(txt|sql|pl)$/ ) {
8847
            print "Unsupported file format: $upd\n";
8848
            next;
8849
        }
8850
        ExecDBRev( $atomicupd, '', '', $upd, 'XXX' );
8851
   }
8852
}
8853
8854
=head2 ExecDBRev
8855
8856
=cut
8857
8858
sub ExecDBRev {
8859
    my ( $atomicupd, $bugno, $descr, $file, $version ) = @_;
8860
8861
    my $devrun = $version=~/XXX$/;
8862
    $atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file;
8863
    return 0 if !CheckVersion($version);
8864
8865
    my $rv;
8866
    if( $file =~ /\.txt$/ ) {
8867
    #This dbrev prints some warning
8868
        my $contents= read_file( $atomicupd->{location}. "/$file" );
8869
        print $contents;
8870
        $rv = 1;
8871
    } elsif( $file =~ /\.pl$/ ) {
8872
    #Run perl script
8873
        $rv = do $atomicupd->{location}. "/$file";
8874
        if( !$rv ) {
8875
            print "ERROR: $@\n" if $@;
8876
            print "ERROR: $!\n" if $!;
8877
            $rv = 1 if !$! && !$@; #apparently, the file does not end with 1;
8878
        }
8879
    } elsif( $file =~ /\.sql$/ ) {
8880
    #Run sql file via installer
8881
        my $installer = C4::Installer->new();
8882
        $rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1;
8883
        #Note: load_sql already warns
8884
    } else {
8885
        print "DB rev $version contains unsupported file $file\n";
8886
        $rv = 0;
8887
    }
8888
8889
    if( $devrun ) {
8890
        print "Dev upgrade $file done\n";
8891
        _atomic_memory( $atomicupd, $file ) if $rv;
8892
    } else {
8893
        _atomic_memory( $atomicupd ); #Official db rev clears the atomic pref
8894
        SetVersion($version);
8895
        print "Upgrade to $version done (Bug $bugno - $descr)\n";
8896
    }
8897
}
8898
8899
sub _atomic_memory {
8900
    my ( $atomicupd, $upd ) = @_;
8901
    $atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": '';
8902
    C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} );
8903
}
8904
8806
=head2 TableExists($table)
8905
=head2 TableExists($table)
8807
8906
8808
=cut
8907
=cut
8809
- 

Return to bug 13068