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

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

Return to bug 13068