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

(-)a/installer/data/mysql/updatedatabase.pl (-1 / +109 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
This subroutine will run all development updates in the atomicupdate
8828
directory. It will skip the official db revisions, that have been
8829
collected in the skipfiles hash. It also skips recently applied
8830
dev updates as recorded in local pref _LocalAtomicUpdates.
8831
8832
=cut
8833
8834
sub RunRemainingAtomicUpdates {
8835
    my ( $atomicupd ) = @_;
8836
    my $loc = $atomicupd->{location};
8837
    my @updates = glob( $loc .'/*');
8838
    foreach my $upd ( sort @updates ) { #sort feels safer here
8839
        $upd =~ s/$loc\///;
8840
        if( exists $atomicupd->{skipfiles}->{$upd} ) {
8841
        #Skip files that belong to official db revisions
8842
           print "Skipping $upd as installed official db rev\n";
8843
           next;
8844
        }
8845
        if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) {
8846
        #Skip files that have recently been applied
8847
        #Note that an official db rev erases this list
8848
           print "Skipping $upd as recently applied dev update\n";
8849
           next;
8850
        }
8851
        if( $upd !~ /\.(txt|sql|pl)$/ ) {
8852
            print "Unsupported file format: $upd\n";
8853
            next;
8854
        }
8855
        ExecDBRev( $atomicupd, '', '', $upd, 'XXX' );
8856
   }
8857
}
8858
8859
=head2 ExecDBRev
8860
8861
This subroutine checks if an official db revision should still be
8862
applied. If not, it records the file in the skipfiles hash and returns.
8863
Otherwise it applies the db rev from the atomicupdate directory.
8864
The db rev can be a perl file, a sql file or a txt file.
8865
8866
=cut
8867
8868
sub ExecDBRev {
8869
    my ( $atomicupd, $bugno, $descr, $file, $version ) = @_;
8870
8871
    my $devrun = $version=~/XXX$/;
8872
    $atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file;
8873
    return 0 if !CheckVersion($version);
8874
8875
    my $rv;
8876
    if( $file =~ /\.txt$/ ) {
8877
    #This dbrev prints some warning
8878
        my $contents= read_file( $atomicupd->{location}. "/$file" );
8879
        print $contents;
8880
        $rv = 1;
8881
    } elsif( $file =~ /\.pl$/ ) {
8882
    #Run perl script
8883
        $rv = do $atomicupd->{location}. "/$file";
8884
        if( !$rv ) {
8885
            print "ERROR: $@\n" if $@;
8886
            print "ERROR: $!\n" if $!;
8887
            $rv = 1 if !$! && !$@; #apparently, the file does not end with 1;
8888
        }
8889
    } elsif( $file =~ /\.sql$/ ) {
8890
    #Run sql file via installer
8891
        my $installer = C4::Installer->new();
8892
        $rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1;
8893
        #Note: load_sql already warns
8894
    } else {
8895
        print "DB rev $version contains unsupported file $file\n";
8896
        $rv = 0;
8897
    }
8898
8899
    if( $devrun ) {
8900
        print "Dev upgrade $file done\n";
8901
        _atomic_memory( $atomicupd, $file ) if $rv;
8902
    } else {
8903
        _atomic_memory( $atomicupd ); #Official db rev clears the atomic pref
8904
        SetVersion($version);
8905
        print "Upgrade to $version done (Bug $bugno - $descr)\n";
8906
    }
8907
}
8908
8909
sub _atomic_memory {
8910
    my ( $atomicupd, $upd ) = @_;
8911
    $atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": '';
8912
    C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} );
8913
}
8914
8806
=head2 TableExists($table)
8915
=head2 TableExists($table)
8807
8916
8808
=cut
8917
=cut
8809
- 

Return to bug 13068