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

(-)a/installer/data/mysql/updatedatabase.pl (-1 / +100 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 9581-9586 if ( CheckVersion($DBversion) ) { Link Here
9581
9592
9582
=head1 FUNCTIONS
9593
=head1 FUNCTIONS
9583
9594
9595
=head2 RunRemainingAtomicUpdates
9596
9597
This subroutine will run all development updates in the atomicupdate
9598
directory. It will skip the official db revisions, that have been
9599
collected in the skipfiles hash. It also skips recently applied
9600
dev updates as recorded in local pref _LocalAtomicUpdates.
9601
9602
=cut
9603
9604
sub RunRemainingAtomicUpdates {
9605
    my ( $atomicupd ) = @_;
9606
    my $loc = $atomicupd->{location};
9607
    my @updates = glob( $loc .'/*');
9608
    foreach my $upd ( sort @updates ) { #sort feels safer here
9609
        $upd =~ s/$loc\///;
9610
        if( exists $atomicupd->{skipfiles}->{$upd} ) {
9611
           next;  # Skip official db revision
9612
        }
9613
        if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) {
9614
        #Skip files that have recently been applied
9615
        #Note that an official db rev erases this list
9616
           print "Skipping $upd as recently applied dev update\n";
9617
           next;
9618
        }
9619
        if( $upd !~ /\.(txt|sql|pl)$/ ) {
9620
            print "Unsupported file format: $upd\n";
9621
            next;
9622
        }
9623
        ExecDBRev( $atomicupd, '', '', $upd, 'XXX' );
9624
   }
9625
}
9626
9627
=head2 ExecDBRev
9628
9629
This subroutine checks if an official db revision should still be
9630
applied. If not, it records the file in the skipfiles hash and returns.
9631
Otherwise it applies the db rev from the atomicupdate directory.
9632
The db rev can be a perl file, a sql file or a txt file.
9633
9634
=cut
9635
9636
sub ExecDBRev {
9637
    my ( $atomicupd, $bugno, $descr, $file, $version ) = @_;
9638
9639
    my $devrun = $version=~/XXX$/;
9640
    $atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file;
9641
    return 0 if !CheckVersion($version);
9642
9643
    my $rv;
9644
    if( $file =~ /\.txt$/ ) {
9645
    #This dbrev prints some warning
9646
        my $contents= read_file( $atomicupd->{location}. "/$file" );
9647
        print $contents;
9648
        $rv = 1;
9649
    } elsif( $file =~ /\.pl$/ ) {
9650
    #Run perl script
9651
        $rv = do $atomicupd->{location}. "/$file";
9652
        if( !$rv ) {
9653
            print "ERROR: $@\n" if $@;
9654
            print "ERROR: $!\n" if $!;
9655
            $rv = 1 if !$! && !$@; #apparently, the file does not end with 1;
9656
        }
9657
    } elsif( $file =~ /\.sql$/ ) {
9658
    #Run sql file via installer
9659
        my $installer = C4::Installer->new();
9660
        $rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1;
9661
        #Note: load_sql already warns
9662
    } else {
9663
        print "DB rev $version contains unsupported file $file\n";
9664
        $rv = 0;
9665
    }
9666
9667
    if( $devrun ) {
9668
        print "Dev upgrade $file done\n";
9669
        _atomic_memory( $atomicupd, $file ) if $rv;
9670
    } else {
9671
        _atomic_memory( $atomicupd ); #Official db rev clears the atomic pref
9672
        SetVersion($version);
9673
        print "Upgrade to $version done (Bug $bugno - $descr)\n";
9674
    }
9675
}
9676
9677
sub _atomic_memory {
9678
    my ( $atomicupd, $upd ) = @_;
9679
    $atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": '';
9680
    C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} );
9681
}
9682
9584
=head2 TableExists($table)
9683
=head2 TableExists($table)
9585
9684
9586
=cut
9685
=cut
Lines 9690-9693 sub CheckVersion { Link Here
9690
    }
9789
    }
9691
}
9790
}
9692
9791
9792
RunRemainingAtomicUpdates( $aupd );
9693
exit;
9793
exit;
9694
- 

Return to bug 13068