Bugzilla – Attachment 34071 Details for
Bug 13068
New feature for DB update and sandbox
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13068: Counterpatch using atomicupdate directory
Bug-13068-Counterpatch-using-atomicupdate-director.patch (text/plain), 5.94 KB, created by
Paul Poulain
on 2014-12-02 17:40:39 UTC
(
hide
)
Description:
Bug 13068: Counterpatch using atomicupdate directory
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2014-12-02 17:40:39 UTC
Size:
5.94 KB
patch
obsolete
>From cdb1a73b13ed9ab45e59c049af66e7effd41b179 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Tue, 14 Oct 2014 11:49:36 +0200 >Subject: [PATCH] Bug 13068: Counterpatch using atomicupdate directory > >This patch makes a distinction between atomicupdates belonging to an >official db revision and development updates. >It also keeps track of the dev updates since the last official db rev. >(This is done via a local pref; so easily accessible if needed.) > >The db revs can be txt files, perl scripts or sql files. >Sql files are run via the installer. > >A new db revision is now only a matter of dropping a file in atomicupdates >for the developer. The RM only adds one line to updatedatabase like: > ExecDBRev( $aupd, '13068', 'Refined dbrev', '13068.pl', '3.17.00.028'); >This line should follow the last dbrev and preceed the call to >RunRemainingAtomicUpdates. > >Test plan: >[1] Add a few lines calling ExecDBRev to updatedatabase with corresponding > files in atomicupdate like (insert the correct version!!): > ExecDBRev( $aupd, '13068', 'My test', '13068.pl', '3.17.00.028'); > Do not forget to update kohaversion.pl accordingly. > Add some other files in atomicupdate as dev updates. >[2] Run updatestructure and check if all db revs and dev updates are run. > Run updatestructure again. Nothing should be run now. > Clear/delete the _LocalAtomicUpdates pref. > Run updatestructure again. Only dev updates should be run. > Reset the database version. You could edit Version in local preferences. > Run updatestructure and check if all db revs and dev updates are run. > Edit _LocalAtomicUpdates and remove one filename. > Run updatestructure again. Only one dev update should be run. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Paul Poulain <paul.poulain@biblibre.com> >--- > installer/data/mysql/updatedatabase.pl | 100 +++++++++++++++++++++++++++++++++ > 1 file changed, 100 insertions(+) > >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 97cbf9f..bc4f4a0 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -38,13 +38,24 @@ use C4::Context; > use C4::Installer; > use C4::Dates; > >+use File::Slurp; > use MARC::Record; > use MARC::File::XML ( BinaryEncoding => 'utf8' ); > >+use constant ATOMICUPD_PREF => '_LocalAtomicUpdates'; >+ > # FIXME - The user might be installing a new database, so can't rely > # on /etc/koha.conf anyway. > > my $debug = 0; >+my $aupd = { #hash for atomic updates >+ location => C4::Context->config('intranetdir')."/installer/data/mysql/atomicupdate", >+ remember => C4::Context->preference(ATOMICUPD_PREF)//'', >+ skipfiles => { >+ 'Bug-4246-Talking-Tech-itiva-phone-notifications.pl' => 1, >+ 'oai_sets.sql' => 1, >+ }, >+}; > > my ( > $sth, $sti, >@@ -9581,6 +9592,94 @@ if ( CheckVersion($DBversion) ) { > > =head1 FUNCTIONS > >+=head2 RunRemainingAtomicUpdates >+ >+This subroutine will run all development updates in the atomicupdate >+directory. It will skip the official db revisions, that have been >+collected in the skipfiles hash. It also skips recently applied >+dev updates as recorded in local pref _LocalAtomicUpdates. >+ >+=cut >+ >+sub RunRemainingAtomicUpdates { >+ my ( $atomicupd ) = @_; >+ my $loc = $atomicupd->{location}; >+ my @updates = glob( $loc .'/*'); >+ foreach my $upd ( sort @updates ) { #sort feels safer here >+ $upd =~ s/$loc\///; >+ if( exists $atomicupd->{skipfiles}->{$upd} ) { >+ next; # Skip official db revision >+ } >+ if( $atomicupd->{remember} =~ /(^|;)$upd;/ ) { >+ #Skip files that have recently been applied >+ #Note that an official db rev erases this list >+ print "Skipping $upd as recently applied dev update\n"; >+ next; >+ } >+ if( $upd !~ /\.(txt|sql|pl)$/ ) { >+ print "Unsupported file format: $upd\n"; >+ next; >+ } >+ ExecDBRev( $atomicupd, '', '', $upd, 'XXX' ); >+ } >+} >+ >+=head2 ExecDBRev >+ >+This subroutine checks if an official db revision should still be >+applied. If not, it records the file in the skipfiles hash and returns. >+Otherwise it applies the db rev from the atomicupdate directory. >+The db rev can be a perl file, a sql file or a txt file. >+ >+=cut >+ >+sub ExecDBRev { >+ my ( $atomicupd, $bugno, $descr, $file, $version ) = @_; >+ >+ my $devrun = $version=~/XXX$/; >+ $atomicupd->{skipfiles}->{$file} = 1 if !$devrun && $file; >+ return 0 if !CheckVersion($version); >+ >+ my $rv; >+ if( $file =~ /\.txt$/ ) { >+ #This dbrev prints some warning >+ my $contents= read_file( $atomicupd->{location}. "/$file" ); >+ print $contents; >+ $rv = 1; >+ } elsif( $file =~ /\.pl$/ ) { >+ #Run perl script >+ $rv = do $atomicupd->{location}. "/$file"; >+ if( !$rv ) { >+ print "ERROR: $@\n" if $@; >+ print "ERROR: $!\n" if $!; >+ $rv = 1 if !$! && !$@; #apparently, the file does not end with 1; >+ } >+ } elsif( $file =~ /\.sql$/ ) { >+ #Run sql file via installer >+ my $installer = C4::Installer->new(); >+ $rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1; >+ #Note: load_sql already warns >+ } else { >+ print "DB rev $version contains unsupported file $file\n"; >+ $rv = 0; >+ } >+ >+ if( $devrun ) { >+ print "Dev upgrade $file done\n"; >+ _atomic_memory( $atomicupd, $file ) if $rv; >+ } else { >+ _atomic_memory( $atomicupd ); #Official db rev clears the atomic pref >+ SetVersion($version); >+ print "Upgrade to $version done (Bug $bugno - $descr)\n"; >+ } >+} >+ >+sub _atomic_memory { >+ my ( $atomicupd, $upd ) = @_; >+ $atomicupd->{remember}= $upd? $atomicupd->{remember}."$upd;": ''; >+ C4::Context->set_preference( ATOMICUPD_PREF, $atomicupd->{remember} ); >+} >+ > =head2 TableExists($table) > > =cut >@@ -9690,4 +9789,5 @@ sub CheckVersion { > } > } > >+RunRemainingAtomicUpdates( $aupd ); > exit; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13068
:
32173
|
32174
|
32175
|
32177
|
32178
|
32179
|
32180
|
32185
|
32294
|
32300
|
32398
|
32399
|
32525
|
32526
|
32658
|
32659
|
32784
|
32785
|
32839
|
32840
|
32841
|
32842
|
32843
|
32919
|
32921
|
33859
|
34070
|
34071
|
34072
|
34949
|
34950
|
34951
|
34960
|
34998
|
35000
|
35001
|
35002
|
35003
|
35366
|
35367
|
35368
|
35370
|
36716
|
36717
|
36718
|
36719
|
36779
|
36780
|
36781
|
36792
|
37061
|
37062
|
37063
|
37064
|
37065
|
37066
|
37075
|
37076
|
37491