Bugzilla – Attachment 127998 Details for
Bug 27880
Store each database migrations state in database
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27880: Store each database migrations state in database
Bug-27880-Store-each-database-migrations-state-in-.patch (text/plain), 30.46 KB, created by
Julian Maurice
on 2021-11-25 10:41:39 UTC
(
hide
)
Description:
Bug 27880: Store each database migrations state in database
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2021-11-25 10:41:39 UTC
Size:
30.46 KB
patch
obsolete
>From acf2182628f256a9554d595bd27b50978e912949 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Mon, 5 Oct 2020 10:03:14 +0200 >Subject: [PATCH] Bug 27880: Store each database migrations state in database > >This patch is the continuation of bug 25078. It improves it by >decorrelating database migrations from Koha version number, which allows >to prevent that a database migration is executed twice, even if present >in two different stable releases. > >Database migrations are regular Perl scripts that return migration >metadata and code in a hashref. >Their filename is meaningful. It should always start with a timestamp >(in the form YYYYMMDDHHMMSS), which is used for executing migrations in >the correct order. It should also contain a short description. > >Once a migration has been successfully executed, its name is stored into >a new table `executed_migrations`. This is how we avoid executing a >migration twice. > >With this new system, the 'Version' system preference becomes useless, >as well as the 4th part of the Koha version. A good part of the patch is >about adapting the code to these changes. > >Test plan: >1. Apply patch and restart starman >2. Go to the staff interface, you should be redirected to the installer >3. Enter your credentials, click on "Continue to the next step" until > you arrive at the "Update database" step >4. You should now see the following message: > Pending migrations: > > 20201002135449-create-executed-migrations-table.pl > Click on "Update your database" > >5. Now you should see > Update report : > > Migration done: > 20201002135449-create-executed-migrations-table.pl (Create table executed_migrations) > > Everything went okay. Update done. > >6. Log into Koha >7. Verify that the About page shows the correct version >8. Verify that the 'Help' link in the top right corner redirects to the > correct version of the manual > >9. Now, do a fresh install and verify that the executed_migrations table > exists and is not empty at the end of the install process >--- > C4/Auth.pm | 41 +++---------- > C4/Context.pm | 15 ++++- > C4/Installer.pm | 28 --------- > Koha.pm | 13 ++-- > Koha/Manual.pm | 3 +- > Koha/Migrations.pm | 44 ++++++++++++++ > Koha/SharedContent.pm | 5 +- > Koha/Template/Plugin/Asset.pm | 2 +- > Koha/Template/Plugin/Koha.pm | 3 +- > installer/data/mysql/kohastructure.sql | 11 ++++ > ...135449-create-executed-migrations-table.pl | 15 +++++ > installer/data/mysql/updatedatabase.pl | 27 +++++++++ > installer/install.pl | 37 ++++-------- > installer/onboarding.pl | 2 +- > .../prog/en/modules/installer/step3.tt | 9 ++- > opac/maintenance.pl | 12 ++-- > plugins/plugins-home.pl | 6 +- > t/00-checkdatabase-version.t | 60 ------------------- > t/Context.t | 11 ---- > t/Koha_Template_Plugin_Koha.t | 8 +-- > t/db_dependent/Context.t | 13 ---- > .../Koha/REST/Plugin/PluginRoutes.t | 6 +- > 22 files changed, 164 insertions(+), 207 deletions(-) > create mode 100644 Koha/Migrations.pm > create mode 100644 installer/data/mysql/migrations/20201002135449-create-executed-migrations-table.pl > delete mode 100755 t/00-checkdatabase-version.t > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 1cfeed48cc..e4c3295c37 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -30,6 +30,7 @@ use C4::Context; > use C4::Templates; # to get the template > use C4::Languages; > use C4::Search::History; >+use C4::Installer; > use Koha; > use Koha::Logger; > use Koha::Caches; >@@ -47,6 +48,7 @@ use Encode; > use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib ); > use Net::CIDR; > use C4::Log qw( logaction ); >+use Koha::Migrations; > > # use utf8; > >@@ -595,7 +597,6 @@ sub get_template_and_user { > OPACPrivacy => C4::Context->preference("OPACPrivacy"), > OPACFinesTab => C4::Context->preference("OPACFinesTab"), > OpacTopissue => C4::Context->preference("OpacTopissue"), >- 'Version' => C4::Context->preference('Version'), > hidelostitems => C4::Context->preference("hidelostitems"), > mylibraryfirst => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '', > opacbookbag => "" . C4::Context->preference("opacbookbag"), >@@ -729,7 +730,6 @@ has authenticated. > sub _version_check { > my $type = shift; > my $query = shift; >- my $version; > > # If version syspref is unavailable, it means Koha is being installed, > # and so we must redirect to OPAC maintenance page or to the WebInstaller >@@ -739,7 +739,7 @@ sub _version_check { > print $query->redirect("/cgi-bin/koha/maintenance.pl"); > safe_exit; > } >- unless ( $version = C4::Context->preference('Version') ) { # assignment, not comparison >+ unless ( C4::Installer::TableExists('systempreferences') ) { > if ( $type ne 'opac' ) { > warn "Install required, redirecting to Installer"; > print $query->redirect("/cgi-bin/koha/installer/install.pl"); >@@ -750,17 +750,8 @@ sub _version_check { > safe_exit; > } > >- # check that database and koha version are the same >- # there is no DB version, it's a fresh install, >- # go to web installer >- # there is a DB version, compare it to the code version >- my $kohaversion = Koha::version(); >- >- # remove the 3 last . to have a Perl number >- $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >- Koha::Logger->get->debug("kohaversion : $kohaversion"); >- if ( $version < $kohaversion ) { >- my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion"; >+ if (Koha::Migrations->pending_migrations > 0) { >+ my $warning = "Database update needed, redirecting to %s"; > if ( $type ne 'opac' ) { > warn sprintf( $warning, 'Installer' ); > print $query->redirect("/cgi-bin/koha/installer/install.pl?step=1&op=updatestructure"); >@@ -1440,15 +1431,7 @@ sub check_api_auth { > my $dbh = C4::Context->dbh; > my $timeout = _timeout_syspref(); > >- unless ( C4::Context->preference('Version') ) { >- >- # database has not been installed yet >- return ( "maintenance", undef, undef ); >- } >- my $kohaversion = Koha::version(); >- $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >- if ( C4::Context->preference('Version') < $kohaversion ) { >- >+ if ( Koha::Migrations->pending_migrations > 0 ) { > # database in need of version update; assume that > # no API should be called while databsae is in > # this condition. >@@ -1644,17 +1627,9 @@ sub check_cookie_auth { > my $skip_version_check = $params->{skip_version_check}; # Only for checkauth > > unless ( $skip_version_check ) { >- unless ( C4::Context->preference('Version') ) { >- >- # database has not been installed yet >- return ( "maintenance", undef ); >- } >- my $kohaversion = Koha::version(); >- $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >- if ( C4::Context->preference('Version') < $kohaversion ) { >- >+ if ( Koha::Migrations->pending_migrations > 0 ) { > # database in need of version update; assume that >- # no API should be called while databsae is in >+ # no API should be called while database is in > # this condition. > return ( "maintenance", undef ); > } >diff --git a/C4/Context.pm b/C4/Context.pm >index 241589e7b5..70ba2ca213 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -313,6 +313,12 @@ sub preference { > > $var = lc $var; > >+ if ($var eq 'version') { >+ my $version = Koha::version(); >+ $version =~ s/^(\d+)\.(\d+)\.(\d+)$/$1.$2$3/; >+ return $version; >+ } >+ > if ($use_syspref_cache) { > my $syspref_cache = Koha::Caches->get_instance('syspref'); > my $cached_var = $syspref_cache->get_from_cache("syspref_$var"); >@@ -799,7 +805,6 @@ Gets various version info, for core Koha packages, Currently called from carp ha > sub get_versions { > my %versions; > $versions{kohaVersion} = Koha::version(); >- $versions{kohaDbVersion} = C4::Context->preference('version'); > $versions{osVersion} = join(" ", POSIX::uname()); > $versions{perlVersion} = $]; > { >@@ -975,7 +980,13 @@ This method returns a boolean representing the install status of the Koha instan > > sub needs_install { > my ($self) = @_; >- return ($self->preference('Version')) ? 0 : 1; >+ eval { >+ my $dbh = $self->dbh; >+ local $dbh->{PrintError} = 0; >+ local $dbh->{RaiseError} = 1; >+ $dbh->do('SELECT * FROM systempreferences WHERE 1 = 0'); >+ }; >+ return $@ ? 1 : 0; > } > > __END__ >diff --git a/C4/Installer.pm b/C4/Installer.pm >index ff9c2b170f..450b8f8437 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -50,7 +50,6 @@ C4::Installer > my $list; > #fill $list with list of sql files > my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list); >- $installer->set_version_syspref(); > $installer->set_marcflavour_syspref('MARC21'); > > =head1 DESCRIPTION >@@ -445,33 +444,6 @@ sub set_marcflavour_syspref { > $request->execute; > } > >-=head2 set_version_syspref >- >- $installer->set_version_syspref(); >- >-Set or update the 'Version' system preference to the current >-Koha software version. >- >-=cut >- >-sub set_version_syspref { >- my $self = shift; >- >- my $kohaversion = Koha::version(); >- # remove the 3 last . to have a Perl number >- $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >- if (C4::Context->preference('Version')) { >- warn "UPDATE Version"; >- my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'"); >- $finish->execute($kohaversion); >- } else { >- warn "INSERT Version"; >- my $finish=$self->{'dbh'}->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')"); >- $finish->execute($kohaversion); >- } >- C4::Context->clear_syspref_cache(); >-} >- > =head2 set_languages_syspref > > $installer->set_languages_syspref(); >diff --git a/Koha.pm b/Koha.pm >index c10423fae3..fc839d8c06 100644 >--- a/Koha.pm >+++ b/Koha.pm >@@ -22,14 +22,11 @@ use Modern::Perl; > > use vars qw{ $VERSION }; > >-#the kohaversion is divided in 4 parts : >-# - #1 : the major number. 3 atm >-# - #2 : the functional release. 00 atm >-# - #3 : the subnumber, moves only on a public release >-# - #4 : the developer version. The 4th number is the database subversion. >-# used by developers when the database changes. updatedatabase take care of the changes itself >-# and is automatically called by Auth.pm when needed. >-$VERSION = "21.06.00.049"; >+#the kohaversion is divided in 3 parts : >+# - #1 : the year of release >+# - #2 : the month of release (05 or 11 for stable releases, 06 or 12 for development branch) >+# - #3 : the maintenance release number >+$VERSION = "21.12.00"; > > sub version { > return $VERSION; >diff --git a/Koha/Manual.pm b/Koha/Manual.pm >index 30a815545e..503f7cb8d0 100644 >--- a/Koha/Manual.pm >+++ b/Koha/Manual.pm >@@ -3,9 +3,10 @@ package Koha::Manual; > use Modern::Perl; > > use C4::Context; >+use Koha; > > sub _get_help_version { >- my $help_version = C4::Context->preference("Version"); >+ my $help_version = Koha::version(); > if ( $help_version =~ m|^(\d+)\.(\d{2}).*$| ) { > my $version = $1; > my $major = $2; >diff --git a/Koha/Migrations.pm b/Koha/Migrations.pm >new file mode 100644 >index 0000000000..a4a6782d52 >--- /dev/null >+++ b/Koha/Migrations.pm >@@ -0,0 +1,44 @@ >+package Koha::Migrations; >+ >+use Modern::Perl; >+ >+use C4::Context; >+ >+sub pending_migrations { >+ my ($self) = @_; >+ >+ my $dbh = C4::Context->dbh; >+ >+ my @pending_migrations; >+ my $executed_migrations = {}; >+ eval { >+ $executed_migrations = $dbh->selectall_hashref('SELECT * FROM executed_migrations', 'name'); >+ }; >+ >+ opendir(my $dh, $self->migrations_dir); >+ foreach my $file (sort readdir $dh) { >+ next if $file !~ /\.pl$/; >+ next if (exists ($executed_migrations->{$file})); >+ push @pending_migrations, $file; >+ } >+ closedir($dh); >+ >+ return @pending_migrations; >+} >+ >+# Only needed for installer >+sub mark_all_migrations_as_executed { >+ my ($self) = @_; >+ >+ my $dbh = C4::Context->dbh; >+ >+ foreach my $migration ($self->pending_migrations) { >+ $dbh->do('INSERT INTO executed_migrations (name) VALUES (?)', {}, $migration); >+ } >+} >+ >+sub migrations_dir { >+ return C4::Context->config('intranetdir') . '/installer/data/mysql/migrations'; >+} >+ >+1; >diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm >index 0c5e406caf..1b22fce0b5 100644 >--- a/Koha/SharedContent.pm >+++ b/Koha/SharedContent.pm >@@ -25,6 +25,7 @@ use LWP::UserAgent; > use Koha::Serials; > use Koha::Reports; > use C4::Context; >+use Koha; > > =head1 NAME > >@@ -144,11 +145,9 @@ sub prepare_entity_data { > $mana_email = C4::Context->preference('KohaAdminEmailAddress') > if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); > >- my %versions = C4::Context::get_versions(); >- > my $mana_info = { > language => $lang, >- kohaversion => $versions{'kohaVersion'}, >+ kohaversion => Koha::version(), > exportemail => $mana_email > }; > >diff --git a/Koha/Template/Plugin/Asset.pm b/Koha/Template/Plugin/Asset.pm >index 0afe209805..5df335f4e5 100644 >--- a/Koha/Template/Plugin/Asset.pm >+++ b/Koha/Template/Plugin/Asset.pm >@@ -142,7 +142,7 @@ sub url { > ); > > my $version = Koha::version; >- $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2$3$4/; >+ $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2${3}000/; > foreach my $dir (@dirs) { > my $abspath = File::Spec->catfile($root, $dir, $filename); > if (-e $abspath) { >diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm >index 5ed58a95ad..9c94c3bdc7 100644 >--- a/Koha/Template/Plugin/Koha.pm >+++ b/Koha/Template/Plugin/Koha.pm >@@ -57,14 +57,13 @@ sub Preference { > > sub Version { > my $version_string = Koha::version(); >- my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string ); >+ my ( $major, $minor, $maintenance ) = split( '\.', $version_string ); > > return { > major => $major, > minor => $minor, > release => $major . "." . $minor, > maintenance => $major . "." . $minor . "." . $maintenance, >- development => ( $development ne '000' ) ? $development : undef, > }; > } > >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index d5768b9e9c..02df513ace 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2583,6 +2583,17 @@ CREATE TABLE `edifact_messages` ( > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > /*!40101 SET character_set_client = @saved_cs_client */; > >+-- >+-- Structure for table executed_migrations >+-- >+ >+DROP TABLE IF EXISTS `executed_migrations`; >+CREATE TABLE `executed_migrations` ( >+ `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, >+ `executed_at` timestamp NOT NULL DEFAULT current_timestamp(), >+ PRIMARY KEY (`name`) >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+ > -- > -- Table structure for table `export_format` > -- >diff --git a/installer/data/mysql/migrations/20201002135449-create-executed-migrations-table.pl b/installer/data/mysql/migrations/20201002135449-create-executed-migrations-table.pl >new file mode 100644 >index 0000000000..1f896e8bfc >--- /dev/null >+++ b/installer/data/mysql/migrations/20201002135449-create-executed-migrations-table.pl >@@ -0,0 +1,15 @@ >+use Modern::Perl; >+ >+{ >+ description => 'Create table executed_migrations', >+ up => sub { >+ my ($dbh) = @_; >+ $dbh->do(q{ >+ CREATE TABLE IF NOT EXISTS `executed_migrations` ( >+ `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, >+ `executed_at` timestamp NOT NULL DEFAULT current_timestamp(), >+ PRIMARY KEY (`name`) >+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci >+ }); >+ }, >+} >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 40cc2b2248..3652589049 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -41,6 +41,7 @@ use C4::Installer; > use Koha::Database; > use Koha; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Migrations; > > use MARC::Record; > use MARC::File::XML ( BinaryEncoding => 'utf8' ); >@@ -24307,4 +24308,30 @@ unless ( $ENV{HTTP_HOST} ) { # Is that correct? > > } > >+my $insert_migration_sth = $dbh->prepare('INSERT INTO executed_migrations (name) VALUES (?)'); >+ >+my $migrations_dir = Koha::Migrations->migrations_dir; >+foreach my $file (Koha::Migrations->pending_migrations) { >+ my $migration = do $migrations_dir . '/' . $file; >+ unless ($migration) { >+ if ($@) { >+ warn "Could not compile $file: $@"; >+ } elsif ($!) { >+ warn "Could not do $file: $!"; >+ } else { >+ warn "Could not run $file"; >+ } >+ next; >+ } >+ >+ eval { >+ $migration->{up}->($dbh); >+ $insert_migration_sth->execute($file); >+ say sprintf('Migration done: %s (%s)', $file, $migration->{description}); >+ }; >+ if ($@) { >+ die sprintf('Migration failed %s (%s): %s', $file, $migration->{description}, $@); >+ } >+} >+ > exit; >diff --git a/installer/install.pl b/installer/install.pl >index 063832569c..d0e3fec18e 100755 >--- a/installer/install.pl >+++ b/installer/install.pl >@@ -32,6 +32,7 @@ use C4::Installer; > use C4::Installer::PerlModules; > > use Koha; >+use Koha::Migrations; > > my $query = CGI->new; > my $step = $query->param('step'); >@@ -227,7 +228,7 @@ elsif ( $step && $step == 3 ) { > exit; > } > elsif ( $op && $op eq 'finish' ) { >- $installer->set_version_syspref(); >+ Koha::Migrations->mark_all_migrations_as_executed(); > > my $langchoice = $query->param('fwklanguage'); > $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice); >@@ -383,11 +384,10 @@ elsif ( $step && $step == 3 ) { > > my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() ); > my $logdir = C4::Context->config('logdir'); >- my $dbversion = C4::Context->preference('Version'); > my $kohaversion = Koha::version; > $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; > >- my $filename_suffix = join '_', $now, $dbversion, $kohaversion; >+ my $filename_suffix = join '_', $now, $kohaversion; > my ( $logfilepath, $logfilepath_errors ) = ( > chk_log( $logdir, "updatedatabase_$filename_suffix" ), > chk_log( $logdir, "updatedatabase-error_$filename_suffix" ) >@@ -485,19 +485,14 @@ elsif ( $step && $step == 3 ) { > # we have tables, propose to select files to upload or updatedatabase > # > $template->param( "count" => $count, "default" => 1 ); >- # >- # 1st part of step 3 : check if there is a databaseversion systempreference >- # if there is, then we just need to upgrade >- # if there is none, then we need to install the database >- # >- if ( C4::Context->preference('Version') ) { >- my $dbversion = C4::Context->preference('Version'); >- $dbversion =~ /(.*)\.(..)(..)(...)/; >- $dbversion = "$1.$2.$3.$4"; >+ >+ # 1st part of step 3 : check if we need to install the database >+ # if not, then we just need to upgrade >+ unless ( C4::Context->needs_install() ) { > $template->param( > "upgrading" => 1, >- "dbversion" => $dbversion, > "kohaversion" => Koha::version(), >+ "pending_migrations" => [ Koha::Migrations->pending_migrations ], > ); > } > } >@@ -509,18 +504,10 @@ else { > # using opendir + language Hash > my $languages_loop = getTranslatedLanguages('intranet'); > $template->param( installer_languages_loop => $languages_loop ); >- if ($dbh) { >- my $rq = >- $dbh->prepare( >- "SELECT * from systempreferences WHERE variable='Version'"); >- if ( $rq->execute ) { >- my ($version) = $rq->fetchrow; >- if ($version) { >- print $query->redirect( >- "/cgi-bin/koha/installer/install.pl?step=3"); >- exit; >- } >- } >+ if (!C4::Context->needs_install) { >+ print $query->redirect( >+ "/cgi-bin/koha/installer/install.pl?step=3"); >+ exit; > } > } > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/installer/onboarding.pl b/installer/onboarding.pl >index 727bc93eea..314ea6b894 100755 >--- a/installer/onboarding.pl >+++ b/installer/onboarding.pl >@@ -35,7 +35,7 @@ use Koha::CirculationRules; > #Setting variables > my $input = CGI->new; > >-unless ( C4::Context->preference('Version') ) { >+if ( C4::Context->needs_install ) { > print $input->redirect("/cgi-bin/koha/installer/install.pl"); > exit; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt >index b3b92fdace..4f2764831f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt >@@ -314,7 +314,14 @@ > [% IF ( default ) %] > [% IF ( upgrading ) %] > <h2>Web installer › Update database</h2> >- <p>We are upgrading from Koha [% dbversion | html %] to [% kohaversion | html %]</p> >+ <p> >+ Pending migrations: >+ <ul> >+ [% FOREACH migration IN pending_migrations %] >+ <li>[% migration | html %]</li> >+ [% END %] >+ </ul> >+ </p> > <p><a href="install.pl?step=3&op=updatestructure" class="btn btn-primary">Update your database</a></p> > [% ELSE %] > <h2>Web installer › Install basic configuration settings</h2> >diff --git a/opac/maintenance.pl b/opac/maintenance.pl >index c7924921c3..6a17f93402 100755 >--- a/opac/maintenance.pl >+++ b/opac/maintenance.pl >@@ -19,22 +19,18 @@ use Modern::Perl; > > use CGI qw ( -utf8 ); > use C4::Auth; >+use C4::Context; > use C4::Output qw( output_html_with_http_headers ); > use C4::Templates qw/gettemplate/; > > use Koha; >+use Koha::Migrations; > > my $query = CGI->new; > my $template = C4::Templates::gettemplate( 'maintenance.tt', 'opac', $query ); > >-my $koha_db_version = C4::Context->preference('Version'); >-my $kohaversion = Koha::version(); >-# Strip dots from version >-$kohaversion =~ s/\.//g if defined $kohaversion; >-$koha_db_version =~ s/\.//g if defined $koha_db_version; >- >-if ( !defined $koha_db_version || # DB not populated >- $kohaversion > $koha_db_version || # Update needed >+if ( C4::Context->needs_install() || # DB not populated >+ Koha::Migrations->pending_migrations > 0 || # Update needed > C4::Context->preference('OpacMaintenance') ) { # Maintenance mode enabled > output_html_with_http_headers $query, '', $template->output; > } >diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl >index da892ba1f2..05871c0b04 100755 >--- a/plugins/plugins-home.pl >+++ b/plugins/plugins-home.pl >@@ -45,8 +45,12 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > > if ($plugins_enabled) { > >+ my $koha_version = Koha::version(); >+ if ($koha_version =~ /^(\d+)\.(\d+)\.(\d+)/) { >+ $koha_version = "$1.$2$3"; >+ } > $template->param( >- koha_version => C4::Context->preference("Version"), >+ koha_version => $koha_version, > method => $method, > ); > >diff --git a/t/00-checkdatabase-version.t b/t/00-checkdatabase-version.t >deleted file mode 100755 >index 9e94cbe50f..0000000000 >--- a/t/00-checkdatabase-version.t >+++ /dev/null >@@ -1,60 +0,0 @@ >-# Copyright 2010 Chris Cormack >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use strict; >-use warnings; >- >-use Test::More; >-use File::Spec; >-use File::Find; >-use IO::File; >- >-my @files =('kohaversion.pl','installer/data/mysql/updatedatabase.pl'); >- >-foreach my $file (@files){ >- next unless -f $file; >- my @name_parts = File::Spec->splitpath($file); >- my %dirs = map { $_ => 1 } File::Spec->splitdir($name_parts[1]); >- next if exists $dirs{'.git'}; >- >- my $fh = IO::File->new($file, 'r'); >- my $xxx_found = 0; >- my $line = 0; >- while (<$fh>) { >- $line++; >- if (/XXX/i) { >- #two lines are an exception for updatedatabase (routine SetVersion and TransferToNum) >- next >- if $file =~ /updatedatabase/ >- && ( /s\/XXX\$\/999\/;/ >- || /\$_\[0\]=~ \/XXX\$\/;/ >- || /version contains XXX/ >- || /\$proposed_version =~ m\/XXX\// ); >- $xxx_found = 1; >- last; >- } >- } >- close $fh; >- if ($xxx_found) { >- fail("$file has no XXX in it"); >- diag("XXX found in line $line"); >- } else { >- pass("$file has no XXX in it"); >- } >-} >- >-done_testing(); >diff --git a/t/Context.t b/t/Context.t >index 156ae778bb..4c4adbb74f 100755 >--- a/t/Context.t >+++ b/t/Context.t >@@ -52,17 +52,6 @@ subtest 'yaml_preference() tests' => sub { > $context->unmock( 'preference' ); > }; > >-subtest 'needs_install() tests' => sub { >- >- plan tests => 2; >- >- t::lib::Mocks::mock_preference( 'Version', '3.0.0' ); >- is( C4::Context->needs_install, 0, 'Preference is defined, no need to install' ); >- >- t::lib::Mocks::mock_preference( 'Version', undef ); # the behaviour when ->preference fails to fetch >- is( C4::Context->needs_install, 1, "->preference(Version) is not defined, need to install" ); >-}; >- > my $context = Test::MockModule->new('C4::Context'); > my $userenv = {}; > >diff --git a/t/Koha_Template_Plugin_Koha.t b/t/Koha_Template_Plugin_Koha.t >index 13079a9753..282f7a96d9 100755 >--- a/t/Koha_Template_Plugin_Koha.t >+++ b/t/Koha_Template_Plugin_Koha.t >@@ -48,15 +48,13 @@ subtest "Koha::Template::Plugin::Koha::Version tests" => sub { > $major = $rnd->randregex('\d'); > $minor = $rnd->randregex('\d\d'); > $maintenance = $rnd->randregex('\d\d'); >- $development = $rnd->randregex('\d\d\d'); >- my $version = "$major.$minor.$maintenance.$development"; >+ my $version = "$major.$minor.$maintenance"; > my $res = Koha::Template::Plugin::Koha::Version( $version ); > is_deeply( $res, { > major => $major, > minor => $minor, > release => $major . "." . $minor, > maintenance => $major . "." . $minor . "." . $maintenance, >- development => $development > }, "Correct development version"); > > >@@ -64,15 +62,13 @@ subtest "Koha::Template::Plugin::Koha::Version tests" => sub { > $major = $rnd->randregex('\d'); > $minor = $rnd->randregex('\d\d'); > $maintenance = $rnd->randregex('\d\d'); >- $development = "000"; >- $version = "$major.$minor.$maintenance.$development"; >+ $version = "$major.$minor.$maintenance"; > $res = Koha::Template::Plugin::Koha::Version( $version ); > is_deeply( $res, { > major => $major, > minor => $minor, > release => $major . "." . $minor, > maintenance => $major . "." . $minor . "." . $maintenance, >- development => undef > }, "Correct maintenance version"); > > }; >diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t >index 433510b2cb..2c480b18b7 100755 >--- a/t/db_dependent/Context.t >+++ b/t/db_dependent/Context.t >@@ -132,16 +132,3 @@ my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); > is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' ); > > 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; >-} >diff --git a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >index 9c6db7b89b..e4bd26391a 100755 >--- a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >+++ b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >@@ -214,8 +214,8 @@ subtest 'needs_install use case tests' => sub { > my $plugins = Koha::Plugins->new; > $plugins->InstallPlugins; > >- # mock Version before initializing the API class >- t::lib::Mocks::mock_preference('Version', undef); >+ my $c4_context = Test::MockModule->new('C4::Context'); >+ $c4_context->mock('needs_install', sub { 1 }); > # initialize Koha::REST::V1 after mocking > > my $t = Test::Mojo->new('Koha::REST::V1'); >@@ -228,7 +228,7 @@ subtest 'needs_install use case tests' => sub { > 'Plugin enabled, route not defined as C4::Context->needs_install is true' > ); > >- t::lib::Mocks::mock_preference('Version', '3.0.0'); >+ $c4_context->mock('needs_install', sub { 0 }); > > $schema->resultset('PluginData')->delete; > $plugins->InstallPlugins; >-- >2.30.2
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 27880
:
117835
|
127998
|
153006
|
153007