From eed6cc84c32eabab354bb515364fc897ef098003 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 15 Jan 2020 16:17:41 +0000 Subject: [PATCH] Bug 21250: DBRev 19.12.00.010 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- Koha/Schema/Result/OaiSetsMapping.pm | 20 +++++++++++-- .../data/mysql/atomicupdate/bug_21520.perl | 28 ----------------- installer/data/mysql/kohastructure.sql | 2 ++ installer/data/mysql/updatedatabase.pl | 30 +++++++++++++++++++ 5 files changed, 51 insertions(+), 31 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_21520.perl diff --git a/Koha.pm b/Koha.pm index 989ad48446..23cb34ae81 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #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 = "19.12.00.009"; +$VERSION = "19.12.00.010"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/OaiSetsMapping.pm b/Koha/Schema/Result/OaiSetsMapping.pm index e4dd532d33..2ba58edade 100644 --- a/Koha/Schema/Result/OaiSetsMapping.pm +++ b/Koha/Schema/Result/OaiSetsMapping.pm @@ -29,6 +29,18 @@ __PACKAGE__->table("oai_sets_mappings"); is_foreign_key: 1 is_nullable: 0 +=head2 rule_order + + data_type: 'integer' + is_nullable: 0 + +=head2 rule_operator + + data_type: 'varchar' + default_value: 'or' + is_nullable: 0 + size: 3 + =head2 marcfield data_type: 'char' @@ -59,6 +71,10 @@ __PACKAGE__->table("oai_sets_mappings"); __PACKAGE__->add_columns( "set_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "rule_order", + { data_type => "integer", is_nullable => 0 }, + "rule_operator", + { data_type => "varchar", default_value => "or", is_nullable => 0, size => 3 }, "marcfield", { data_type => "char", is_nullable => 0, size => 3 }, "marcsubfield", @@ -92,8 +108,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:A2fchnI85JftSuruZ1CykQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-01-15 16:27:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:70uqCB/wqEodblvsbKKVvA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_21520.perl b/installer/data/mysql/atomicupdate/bug_21520.perl deleted file mode 100644 index ccf3178164..0000000000 --- a/installer/data/mysql/atomicupdate/bug_21520.perl +++ /dev/null @@ -1,28 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - $dbh->do( "ALTER TABLE oai_sets_mappings ADD COLUMN rule_order INT AFTER set_id, ADD COLUMN rule_operator VARCHAR(3) AFTER rule_order" ); - $dbh->do( "UPDATE oai_sets_mappings SET rule_operator='or'" ); - my $sets = $dbh->selectall_arrayref("SELECT * from oai_sets_mappings ORDER BY set_id", { Slice => {} }); - my $i = 0; - my $previous_set_id; - for my $set ( @{$sets}) { - my $set_id = $set->{set_id}; - - if ($previous_set_id && $previous_set_id != $set_id) { - $i = 0; - } - - if ($i == 0) { - $dbh->do("UPDATE oai_sets_mappings SET rule_operator=NULL WHERE set_id=? LIMIT 1", {}, $set_id); - } - - $dbh->do("UPDATE oai_sets_mappings SET rule_order=? WHERE set_id=? AND rule_order IS NULL LIMIT 1", {}, $i, $set_id); - - $i++; - $previous_set_id = $set_id; - } - - # Always end with this (adjust the bug info) - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 21520 - Add rule_order and rule_operator fields to oai_sets_mappings table)\n"; -} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 56d5d27d5a..da0d740346 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1219,6 +1219,8 @@ CREATE TABLE `oai_sets_descriptions` ( DROP TABLE IF EXISTS `oai_sets_mappings`; CREATE TABLE `oai_sets_mappings` ( `set_id` int(11) NOT NULL, + `rule_order` int NOT NULL, + `rule_operator` varchar(3) NOT NULL default 'or', `marcfield` char(3) NOT NULL, `marcsubfield` char(1) NOT NULL, `operator` varchar(8) NOT NULL default 'equal', diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e45c39836c..61eb449ed8 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -20485,6 +20485,36 @@ INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, print "Upgrade to $DBversion done (Bug 23354 - Add point of sale permissions)\n"; } +$DBversion = '19.12.00.010'; +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'oai_sets_mappings', 'rule_order' ) ) { + $dbh->do( "ALTER TABLE oai_sets_mappings ADD COLUMN rule_order INT AFTER set_id, ADD COLUMN rule_operator VARCHAR(3) AFTER rule_order" ); + $dbh->do( "UPDATE oai_sets_mappings SET rule_operator='or'" ); + my $sets = $dbh->selectall_arrayref("SELECT * from oai_sets_mappings ORDER BY set_id", { Slice => {} }); + my $i = 0; + my $previous_set_id; + for my $set ( @{$sets}) { + my $set_id = $set->{set_id}; + + if ($previous_set_id && $previous_set_id != $set_id) { + $i = 0; + } + + if ($i == 0) { + $dbh->do("UPDATE oai_sets_mappings SET rule_operator=NULL WHERE set_id=? LIMIT 1", {}, $set_id); + } + + $dbh->do("UPDATE oai_sets_mappings SET rule_order=? WHERE set_id=? AND rule_order IS NULL LIMIT 1", {}, $i, $set_id); + + $i++; + $previous_set_id = $set_id; + } + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 21520 - Add rule_order and rule_operator fields to oai_sets_mappings table)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.39.5