Bugzilla – Attachment 13951 Details for
Bug 9191
updatedatabase.pl must have ability to run updates only up to a particular revision
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9191: updatedatabase.pl should only run updates up to the current version
Bug-9191-updatedatabasepl-should-only-run-updates-.patch (text/plain), 5.40 KB, created by
Elliott Davis
on 2012-12-07 20:40:00 UTC
(
hide
)
Description:
Bug 9191: updatedatabase.pl should only run updates up to the current version
Filename:
MIME Type:
Creator:
Elliott Davis
Created:
2012-12-07 20:40:00 UTC
Size:
5.40 KB
patch
obsolete
>From 20acbe752443e12727fb86f1e28adfdad545a6c8 Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@cpbibliography.com> >Date: Mon, 3 Dec 2012 16:28:51 -0500 >Subject: [PATCH] Bug 9191: updatedatabase.pl should only run updates up to the current version > >Check whether a given update should be run when passed the proposed >version number. The update will always be run if the proposed version >is greater than the current database version and less than or equal to >the version returned by C4::Context->final_linear_version (initially set >to be equal to the version in kohaversion.pl). The update is also run if >the version contains XXX, though this behavior will be changed following >the adoption of non-linear updates as implemented in bug 7167. > >To test: >1) Make sure that the first example database update added by this patch > in installer/data/mysql/updatedatabase.pl has a version number one > greater than the version of Koha you have installed. >2) Set the Version syspref back one version behind your current version. >3) Navigate to the main page of the staff client, and log in to the > installer. >4) Confirm that the update page claims to have rerun the previous update > and has displayed the log message: > "Upgrade to 3.11.00.XXX done (Bug 9191: You should see this)" > but not the log message: > "Upgrade to [version number] done (Bug 9191: You shouldn't see this)" > >Note: the sample database revisions will be removed by the RM before >this patch is pushed to master. > >Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> >works great > >Signed-off-by: Elliott Davis <elliott@test.bywatersolutions.com> >Works as expected. Test plan is great. Code looks to be adherent to standards. >--- > C4/Context.pm | 12 +++++++++ > installer/data/mysql/updatedatabase.pl | 40 ++++++++++++++++++++++++++++++++ > t/db_dependent/Context.t | 17 +++++++++++++ > 3 files changed, 69 insertions(+), 0 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index bd1f235..f932bac 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -220,6 +220,18 @@ sub KOHAVERSION { > do $cgidir."/kohaversion.pl" || die "NO $cgidir/kohaversion.pl"; > return kohaversion(); > } >+ >+=head2 final_linear_version >+ >+Returns the version number of the final update to run in updatedatabase.pl. >+This number is equal to the version in kohaversion.pl >+ >+=cut >+ >+sub final_linear_version { >+ return KOHAVERSION; >+} >+ > =head2 read_config_file > > Reads the specified Koha config file. >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 676bb3e..c6fb225 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -6134,6 +6134,17 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > SetVersion ($DBversion); > } > >+if ( CheckVersion($DBversion) ) { >+ print "Upgrade to $DBversion done (Bug 9191: You shouldn't see this)\n"; >+ SetVersion($DBversion); >+} >+ >+$DBversion = "3.11.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ print "Upgrade to $DBversion done (Bug 9191: You should see this)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >@@ -6215,4 +6226,33 @@ sub SetVersion { > } > C4::Context::clear_syspref_cache(); # invalidate cached preferences > } >+ >+=head2 CheckVersion >+ >+Check whether a given update should be run when passed the proposed version >+number. The update will always be run if the proposed version is greater >+than the current database version and less than or equal to the version in >+kohaversion.pl. The update is also run if the version contains XXX, though >+this behavior will be changed following the adoption of non-linear updates >+as implemented in bug 7167. >+ >+=cut >+ >+sub CheckVersion { >+ my ($proposed_version) = @_; >+ my $version_number = TransformToNum($proposed_version); >+ >+ # The following line should be deleted when bug 7167 is pushed >+ return 1 if ( $proposed_version =~ m/XXX/ ); >+ >+ if ( C4::Context->preference("Version") < $version_number >+ && $version_number <= TransformToNum( C4::Context->final_linear_version ) ) >+ { >+ return 1; >+ } >+ else { >+ return 0; >+ } >+} >+ > exit; >diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t >index 5105e84..32ea441 100755 >--- a/t/db_dependent/Context.t >+++ b/t/db_dependent/Context.t >@@ -23,6 +23,11 @@ ok($koha = C4::Context->new, 'C4::Context->new'); > ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); > ok($ret = C4::Context->KOHAVERSION, ' (function) KOHAVERSION = ' . ($ret||'')); > ok($ret = $koha->KOHAVERSION, ' $koha->KOHAVERSION = ' . ($ret||'')); >+ok( >+ TransformVersionToNum( C4::Context->final_linear_version ) <= >+ TransformVersionToNum( C4::Context->KOHAVERSION ), >+ 'Final linear version is less than or equal to kohaversion.pl' >+); > my @keys = keys %$koha; > diag("Number of keys in \%\$koha: " . scalar @keys); > our $width = 0; >@@ -104,4 +109,16 @@ is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); > > done_testing(); > >+sub TransformVersionToNum { >+ my $version = shift; >+ >+ # remove the 3 last . to have a Perl number >+ $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >+ >+ # three X's at the end indicate that you are testing patch with dbrev >+ # change it into 999 >+ # prevents error on a < comparison between strings (should be: lt) >+ $version =~ s/XXX$/999/; >+ return $version; >+} > 1; >-- >1.7.2.5
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 9191
:
13859
|
13877
|
13878
| 13951