From ddbdb3e64aaaf1c76911eff39f46f43a07ed6506 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov 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 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. --- installer/data/mysql/updatedatabase.pl | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a6af263..f2b1124 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6114,6 +6114,18 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.005"; +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) @@ -6195,4 +6207,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->KOHAVERSION ) ) + { + return 1; + } + else { + return 0; + } +} + exit; -- 1.7.9.5