Bugzilla – Attachment 117084 Details for
Bug 25078
Update DB process - wrap each DBRev inside a transaction and better error handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25078: [POC] Move each DBrev to a file
Bug-25078-POC-Move-each-DBrev-to-a-file.patch (text/plain), 15.52 KB, created by
Jonathan Druart
on 2021-02-19 13:10:15 UTC
(
hide
)
Description:
Bug 25078: [POC] Move each DBrev to a file
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-02-19 13:10:15 UTC
Size:
15.52 KB
patch
obsolete
>From ee7fde516cca171f4c6c95a0aa733c74df0aec55 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 19 Feb 2021 13:10:40 +0100 >Subject: [PATCH] Bug 25078: [POC] Move each DBrev to a file > >--- > C4/Installer.pm | 70 +++++++---- > Koha/Installer/DBRev/201200000.pm | 13 +++ > Koha/Installer/DBRev/201200001.pm | 22 ++++ > Koha/Installer/DBRev/201200002.pm | 19 +++ > Koha/Installer/DBRev/201200003.pm | 19 +++ > Koha/Installer/DBRev/201200004.pm | 19 +++ > Koha/Installer/DBRev/201200005.pm | 19 +++ > Koha/Installer/DBRev/201200006.pm | 19 +++ > Koha/Installer/DBRev/201200007.pm | 19 +++ > Koha/Installer/DBRev/201200008.pm | 21 ++++ > Koha/Installer/DBRev/201200009.pm | 17 +++ > installer/data/mysql/updatedatabase.pl | 109 +----------------- > installer/install.pl | 1 - > .../prog/en/modules/installer/step3.tt | 4 +- > 14 files changed, 237 insertions(+), 134 deletions(-) > create mode 100644 Koha/Installer/DBRev/201200000.pm > create mode 100644 Koha/Installer/DBRev/201200001.pm > create mode 100644 Koha/Installer/DBRev/201200002.pm > create mode 100644 Koha/Installer/DBRev/201200003.pm > create mode 100644 Koha/Installer/DBRev/201200004.pm > create mode 100644 Koha/Installer/DBRev/201200005.pm > create mode 100644 Koha/Installer/DBRev/201200006.pm > create mode 100644 Koha/Installer/DBRev/201200007.pm > create mode 100644 Koha/Installer/DBRev/201200008.pm > create mode 100644 Koha/Installer/DBRev/201200009.pm > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 24aada3e7f..6e6dbb42d2 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -31,7 +31,7 @@ use vars qw(@ISA @EXPORT); > BEGIN { > require Exporter; > @ISA = qw( Exporter ); >- push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists TransformToNum CheckVersion update ); >+ push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists TransformToNum CheckVersion update get_db_entries ); > }; > > =head1 NAME >@@ -684,43 +684,63 @@ sub TableExists { # Could be renamed table_exists for consistency > return 0; > } > >-sub execute_entry { >- my ( $DBversion, $bug_number, $description, $sub ) = @_; >+sub version_from_module { >+ my $module = shift; >+ return unless $module =~ m|^(\d{2})(\d{2})(\d{2})(\d{3})$|; >+ return sprintf "%s.%s.%s.%s", $1, $2, $3, $4; >+} >+sub get_db_entries { >+ my $DBRev_dir = C4::Context->config('intranetdir') . '/Koha/Installer/DBRev'; >+ opendir my $dh, $DBRev_dir or die "Cannot open $DBRev_dir dir ($!)"; >+ my @db_revs = sort map { s|\.pm$||; $_ } grep { ! /^\./ } readdir $dh; >+ my @need_update; >+ for my $db_rev ( @db_revs ) { >+ my $version = version_from_module( $db_rev ); >+ >+ unless ( $version ) { >+ warn "Invalid db_rev found: " . $db_rev; >+ next >+ } > >- my $error; >- try { >- Koha::Database->schema->txn_do($sub); >- } catch { >- $error = $_; >- }; >+ next unless CheckVersion( $version ); > >- return $error; >+ push @need_update, $db_rev; >+ } >+ return \@need_update; > } > >+use Module::Load::Conditional qw(can_load); >+ > sub update { >- my ( $db_entries ) = @_; >+ my ( $modules ) = @_; > > my ( @done, @errors ); >- for my $db_entry ( @$db_entries ) { >- >- my $version = $db_entry->{version}; >- next unless CheckVersion( $version ); >- >- my $error = execute_entry( >- $version, >- $db_entry->{bug_number}, >- $db_entry->{description}, >- $db_entry->{sub} >- ); >- >- $db_entry->{time} = POSIX::strftime("%H:%M:%S",localtime); >+ for my $module_name ( @$modules ) { >+ >+ my $module = "Koha::Installer::DBRev::$module_name"; >+ die "cannot load $module" unless can_load( modules => { $module => undef }, verbose => 1 ); >+ >+ my $error; >+ try { >+ $module->update(); >+ } catch { >+ $error = $_; >+ }; >+ >+ my $db_entry = { >+ bug_number => $module->bug_number, >+ description => $module->description, >+ version => version_from_module($module_name), >+ time => POSIX::strftime( "%H:%M:%S", localtime ), >+ }; > $db_entry->{output} = output_version( { %$db_entry, done => !$error } ); >+ > if ( $error ) { > push @errors, { %$db_entry, error => $error }; > last; # We stop the update if an error occurred! > } > >- SetVersion($version); >+ SetVersion($db_entry->{version}); > push @done, $db_entry; > } > return { success => \@done, error => \@errors }; >diff --git a/Koha/Installer/DBRev/201200000.pm b/Koha/Installer/DBRev/201200000.pm >new file mode 100644 >index 0000000000..e1b8e86d83 >--- /dev/null >+++ b/Koha/Installer/DBRev/201200000.pm >@@ -0,0 +1,13 @@ >+package Koha::Installer::DBRev::201200000; >+ >+sub update { >+} >+ >+sub bug_number { >+} >+ >+sub description { >+ q{Sorry, this is my first life, I am still learning!}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200001.pm b/Koha/Installer/DBRev/201200001.pm >new file mode 100644 >index 0000000000..f0e16638dc >--- /dev/null >+++ b/Koha/Installer/DBRev/201200001.pm >@@ -0,0 +1,22 @@ >+package Koha::Installer::DBRev::201200001; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{ >+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+ ('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo') >+ } >+ ); >+ >+} >+ >+sub bug_number { 27252 } >+sub description { >+ q{Add ElasticsearchCrossFields system preference}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200002.pm b/Koha/Installer/DBRev/201200002.pm >new file mode 100644 >index 0000000000..2398655b73 >--- /dev/null >+++ b/Koha/Installer/DBRev/201200002.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200002; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences SET `type` = 'Choice' WHERE `variable` = 'UsageStatsCountry'} >+ ); >+ >+} >+ >+sub bug_number { 27251 } >+sub description { >+ q{Set type for UsageStatsCountry to Choice} >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200003.pm b/Koha/Installer/DBRev/201200003.pm >new file mode 100644 >index 0000000000..d5c8ff5d83 >--- /dev/null >+++ b/Koha/Installer/DBRev/201200003.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200003; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences SET `type` = 'Choice' WHERE `variable` = 'Mana'} >+ ); >+ >+} >+ >+sub bug_number { 27349 } >+sub description { >+ q{Update type for Mana system preference to Choice}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200004.pm b/Koha/Installer/DBRev/201200004.pm >new file mode 100644 >index 0000000000..a5cd294f42 >--- /dev/null >+++ b/Koha/Installer/DBRev/201200004.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200004; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences set variable="TaxRates" WHERE variable="gist"} >+ ); >+ >+} >+ >+sub bug_number { 27485 } >+sub description { >+ q{Rename system preference 'gist' to 'TaxRates'}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200005.pm b/Koha/Installer/DBRev/201200005.pm >new file mode 100644 >index 0000000000..24043abf5f >--- /dev/null >+++ b/Koha/Installer/DBRev/201200005.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200005; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences set variable="OPACLanguages" WHERE variable="opaclanguages"} >+ ); >+ >+} >+ >+sub bug_number { 27491 } >+sub description { >+ q{Rename system preference 'opaclanguages' to 'OPACLanguages'}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200006.pm b/Koha/Installer/DBRev/201200006.pm >new file mode 100644 >index 0000000000..22a8eca22c >--- /dev/null >+++ b/Koha/Installer/DBRev/201200006.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200006; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences SET variable="OPACComments" WHERE variable="reviewson" } >+ ); >+ >+} >+ >+sub bug_number { 27487 } >+sub description { >+ q{Rename system preference 'reviewson' to 'OPACComments'}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200007.pm b/Koha/Installer/DBRev/201200007.pm >new file mode 100644 >index 0000000000..ea9190d009 >--- /dev/null >+++ b/Koha/Installer/DBRev/201200007.pm >@@ -0,0 +1,19 @@ >+package Koha::Installer::DBRev::201200007; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do( >+ q{UPDATE systempreferences set variable="CSVDelimiter" WHERE variable="delimiter"} >+ ); >+ >+} >+ >+sub bug_number { 27486 } >+sub description { >+ q{Renaming system preference 'delimiter' to 'CSVDelimiter'}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200008.pm b/Koha/Installer/DBRev/201200008.pm >new file mode 100644 >index 0000000000..1a10a7e21f >--- /dev/null >+++ b/Koha/Installer/DBRev/201200008.pm >@@ -0,0 +1,21 @@ >+package Koha::Installer::DBRev::201200008; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do(q{ >+ UPDATE systempreferences >+ SET options = "claim_returned|batchmod|moredetail|cronjob|additem|pendingreserves|onpayment" >+ WHERE variable = "MarkLostItemsAsReturned"; >+ }); >+ >+} >+ >+sub bug_number { 25552 } >+sub description { >+ q{Add missing Claims Returned option to MarkLostItemsAsReturned}; >+} >+ >+1; >diff --git a/Koha/Installer/DBRev/201200009.pm b/Koha/Installer/DBRev/201200009.pm >new file mode 100644 >index 0000000000..74f312fafd >--- /dev/null >+++ b/Koha/Installer/DBRev/201200009.pm >@@ -0,0 +1,17 @@ >+package Koha::Installer::DBRev::201200009; >+ >+use C4::Context; >+ >+sub update { >+ my $dbh = C4::Context->dbh; >+ >+ $dbh->do(q{ALTER TABLE Foo}); >+ >+} >+ >+sub bug_number { 42424 } >+sub description { >+ q{Testing failure}; >+} >+ >+1; >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 2028342832..2e62d70cd3 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -23421,114 +23421,9 @@ if( CheckVersion( $DBversion ) ) { > NewVersion( $DBversion, "", "Koha 20.11.00 release" ); > } > >-our $db_entries = [ >- { >- version => '20.12.00.000', >- bug_number => undef, >- description => "Sorry, this is my first life, I am still learning!", >- }, >- { >- version => '20.12.00.001', >- bug_number => 27252, >- description => "Add ElasticsearchCrossFields system preference", >- sub => sub { >- $dbh->do( >- q{ >- INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >- ('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo') >- } >- ); >- } >- }, >- { >- version => '20.12.00.002', >- bug_number => 27351, >- description => "Set type for UsageStatsCountry to Choice", >- sub => sub { >- $dbh->do( >-q{UPDATE systempreferences SET `type` = 'Choice' WHERE `variable` = 'UsageStatsCountry'} >- ); >- } >- }, >- { >- version => '20.12.00.003', >- bug_number => 27349, >- description => "Update type for Mana system preference to Choice", >- sub => sub { >- $dbh->do( >-q{UPDATE systempreferences SET `type` = 'Choice' WHERE `variable` = 'Mana'} >- ); >- } >- }, >- { >- version => '20.12.00.004', >- bug_number => 27485, >- description => "Rename system preference 'gist' to 'TaxRates'", >- sub => sub { >- $dbh->do( >-q{UPDATE systempreferences set variable="TaxRates" WHERE variable="gist"} >- ); >- }, >- }, >- >- { >- version => '20.12.00.005', >- bug_number => 27491, >- description => "Rename system preference 'opaclanguages' to 'OPACLanguages'", >- sub => sub { >- $dbh->do( >-q{UPDATE systempreferences set variable="OPACLanguages" WHERE variable="opaclanguages"} >- ); >- } >- }, >- { >- version => '20.12.00.006', >- bug_number => 27487, >- description => "Rename system preference 'reviewson' to 'OPACComments'", >- sub => sub { >- $dbh->do( >- q{UPDATE systempreferences SET variable="OPACComments" WHERE variable="reviewson" } >- ); >- } >- }, >- { >- version => '20.12.00.007', >- bug_number => 27486, >- description => "Renaming system preference 'delimiter' to 'CSVDelimiter'", >- sub => sub { >- $dbh->do( >- q{UPDATE systempreferences set variable="CSVDelimiter" WHERE variable="delimiter"} >- ); >- } >- }, >- { >- version => '20.12.00.008', >- bug_number => 25552, >- description => "Add missing Claims Returned option to MarkLostItemsAsReturned", >- sub => sub { >- $dbh->do(q{ >- UPDATE systempreferences >- SET options = "claim_returned|batchmod|moredetail|cronjob|additem|pendingreserves|onpayment" >- WHERE variable = "MarkLostItemsAsReturned"; >- }); >- } >- }, >- { >- version => '20.12.00.009', >- bug_number => 42424, >- description => "Testing failure", >- sub => sub { >- $dbh->do(q{ALTER TABLE foo}); >- } >- }, >- >-]; >- >- >-sub get_db_entries { return $db_entries; } >- > unless ( $ENV{HTTP_HOST} ) { # Is that correct? >- my $report = update( $db_entries ); >+ my $modules = C4::Installer::get_db_entries; >+ my $report = update( $modules ); > > for my $s ( @{ $report->{success} } ) { > say $s->{output}; >diff --git a/installer/install.pl b/installer/install.pl >index 2386625e27..3fbf0472fe 100755 >--- a/installer/install.pl >+++ b/installer/install.pl >@@ -397,7 +397,6 @@ elsif ( $step && $step == 3 ) { > my $updatedatabase_path = C4::Context->config("intranetdir") > . "/installer/data/$info{dbms}/updatedatabase.pl"; > >- eval { require $updatedatabase_path }; > my $db_entries = get_db_entries(); > my $report = update( $db_entries ); > >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 53b42fbb0c..e730a119e7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt >@@ -270,8 +270,10 @@ > [% END %] > [% UNLESS error %] > <p>Everything went okay. Update done.</p> >+ <p><a href="install.pl?step=3&op=finished" class="btn btn-primary">Continue to log in to Koha</a></p> >+ [% ELSE %] >+ <p><a href="install.pl?step=3&op=updatestructure" class="btn btn-primary">Try again</a></p> > [% END %] >- <p><a href="install.pl?step=3&op=finished" class="btn btn-primary">Continue to log in to Koha</a></p> > [% END # / IF updatestructure %] > </div> <!-- / #installer-step3 --> > </div> <!-- / .row --> >-- >2.20.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 25078
:
102521
|
116032
|
116033
|
116034
|
116208
|
116209
|
117084
|
121909
|
121910
|
121911
|
121982
|
121983
|
121984
|
122208
|
122322
|
122323
|
122324
|
122325
|
122326
|
122329
|
122665
|
122666
|
122667
|
122668
|
122669
|
122670
|
122671
|
122679
|
122680
|
122875
|
123356
|
123357
|
123358
|
123359
|
123360
|
123361
|
123362
|
123363
|
123364
|
123365
|
123366
|
123367
|
123850
|
123851
|
123853
|
123937
|
124269