From 2cb8e9755af0fdfd25bebc465f9a415d485ceea0 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 5 Oct 2018 14:49:13 +0000 Subject: [PATCH] Bug 18887: DBRev 18.06.00.036 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Branch.pm | 19 +- Koha/Schema/Result/BranchBorrowerCircRule.pm | 11 +- Koha/Schema/Result/Category.pm | 19 +- Koha/Schema/Result/CirculationRule.pm | 185 ++++++++++++++++++ Koha/Schema/Result/DefaultBorrowerCircRule.pm | 11 +- Koha/Schema/Result/Itemtype.pm | 19 +- .../data/mysql/atomicupdate/bug_18887.perl | 49 ----- installer/data/mysql/updatedatabase.pl | 43 ++++ 9 files changed, 284 insertions(+), 74 deletions(-) create mode 100644 Koha/Schema/Result/CirculationRule.pm delete mode 100644 installer/data/mysql/atomicupdate/bug_18887.perl diff --git a/Koha.pm b/Koha.pm index 5ab733cfbc..77153bbc7a 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 = "18.06.00.035"; +$VERSION = "18.06.00.036"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm index b85094bdbf..3d349cc581 100644 --- a/Koha/Schema/Result/Branch.pm +++ b/Koha/Schema/Result/Branch.pm @@ -361,6 +361,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 circulation_rules + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "circulation_rules", + "Koha::Schema::Result::CirculationRule", + { "foreign.branchcode" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 club_enrollments Type: has_many @@ -617,8 +632,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-09-06 16:28:49 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:N0tdcSAb4bMht/i0chipYQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L/zUeW5lNf5oJcZ/bES7rw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/BranchBorrowerCircRule.pm b/Koha/Schema/Result/BranchBorrowerCircRule.pm index be6cd45c00..60b02f093a 100644 --- a/Koha/Schema/Result/BranchBorrowerCircRule.pm +++ b/Koha/Schema/Result/BranchBorrowerCircRule.pm @@ -47,11 +47,6 @@ __PACKAGE__->table("branch_borrower_circ_rules"); data_type: 'integer' is_nullable: 1 -=head2 max_holds - - data_type: 'integer' - is_nullable: 1 - =cut __PACKAGE__->add_columns( @@ -63,8 +58,6 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "maxonsiteissueqty", { data_type => "integer", is_nullable => 1 }, - "max_holds", - { data_type => "integer", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -114,8 +107,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-25 15:10:08 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lgs8B3omV3Au570af/VF2g +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3PTe8JIjkpfp2+I/2wCVmg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Category.pm b/Koha/Schema/Result/Category.pm index 42865a8239..1b61c33957 100644 --- a/Koha/Schema/Result/Category.pm +++ b/Koha/Schema/Result/Category.pm @@ -251,6 +251,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 circulation_rules + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "circulation_rules", + "Koha::Schema::Result::CirculationRule", + { "foreign.categorycode" => "self.categorycode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 default_borrower_circ_rule Type: might_have @@ -267,8 +282,8 @@ __PACKAGE__->might_have( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TGAiiFICSjlKNvnfa87kFQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yvHcgnSv1RXNMXJixVtt0Q # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/CirculationRule.pm b/Koha/Schema/Result/CirculationRule.pm new file mode 100644 index 0000000000..7b26b37e4a --- /dev/null +++ b/Koha/Schema/Result/CirculationRule.pm @@ -0,0 +1,185 @@ +use utf8; +package Koha::Schema::Result::CirculationRule; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::CirculationRule + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("circulation_rules"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 branchcode + + data_type: 'varchar' + is_foreign_key: 1 + is_nullable: 1 + size: 10 + +=head2 categorycode + + data_type: 'varchar' + is_foreign_key: 1 + is_nullable: 1 + size: 10 + +=head2 itemtype + + data_type: 'varchar' + is_foreign_key: 1 + is_nullable: 1 + size: 10 + +=head2 rule_name + + data_type: 'varchar' + is_nullable: 0 + size: 32 + +=head2 rule_value + + data_type: 'varchar' + is_nullable: 0 + size: 32 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "branchcode", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, + "categorycode", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, + "itemtype", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, + "rule_name", + { data_type => "varchar", is_nullable => 0, size => 32 }, + "rule_value", + { data_type => "varchar", is_nullable => 0, size => 32 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=item * L + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint( + "branchcode", + ["branchcode", "categorycode", "itemtype", "rule_name"], +); + +=head1 RELATIONS + +=head2 branchcode + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branchcode", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +=head2 categorycode + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "categorycode", + "Koha::Schema::Result::Category", + { categorycode => "categorycode" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +=head2 itemtype + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "itemtype", + "Koha::Schema::Result::Itemtype", + { itemtype => "itemtype" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QHMqvrtX0ohJe70PHUYZ0Q + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/Koha/Schema/Result/DefaultBorrowerCircRule.pm b/Koha/Schema/Result/DefaultBorrowerCircRule.pm index 407b911b9e..72f36a9888 100644 --- a/Koha/Schema/Result/DefaultBorrowerCircRule.pm +++ b/Koha/Schema/Result/DefaultBorrowerCircRule.pm @@ -40,11 +40,6 @@ __PACKAGE__->table("default_borrower_circ_rules"); data_type: 'integer' is_nullable: 1 -=head2 max_holds - - data_type: 'integer' - is_nullable: 1 - =cut __PACKAGE__->add_columns( @@ -54,8 +49,6 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "maxonsiteissueqty", { data_type => "integer", is_nullable => 1 }, - "max_holds", - { data_type => "integer", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -88,8 +81,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-25 15:10:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hv9wFvd5mb8Ch7RPCZynoA +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PIjw7tbrnnAgXDlxiX9cpA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Itemtype.pm b/Koha/Schema/Result/Itemtype.pm index 0e36247b50..fdd507da6c 100644 --- a/Koha/Schema/Result/Itemtype.pm +++ b/Koha/Schema/Result/Itemtype.pm @@ -165,6 +165,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 circulation_rules + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "circulation_rules", + "Koha::Schema::Result::CirculationRule", + { "foreign.itemtype" => "self.itemtype" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 default_branch_item_rule Type: might_have @@ -211,8 +226,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cNP7/nYGdVeKZ8L7sp1+FQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GthTVMBLO5Zi6NU3up3m+A # Use the ItemtypeLocalization view to create the join on localization our $LANGUAGE; diff --git a/installer/data/mysql/atomicupdate/bug_18887.perl b/installer/data/mysql/atomicupdate/bug_18887.perl deleted file mode 100644 index 3d38b57e14..0000000000 --- a/installer/data/mysql/atomicupdate/bug_18887.perl +++ /dev/null @@ -1,49 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - unless (TableExists('circulation_rules')){ - $dbh->do(q{ - CREATE TABLE `circulation_rules` ( - `id` int(11) NOT NULL auto_increment, - `branchcode` varchar(10) NULL default NULL, - `categorycode` varchar(10) NULL default NULL, - `itemtype` varchar(10) NULL default NULL, - `rule_name` varchar(32) NOT NULL, - `rule_value` varchar(32) NOT NULL, - PRIMARY KEY (`id`), - - CONSTRAINT `circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `circ_rules_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `circ_rules_ibfk_3` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, - KEY `rule_name` (`rule_name`), - UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - }); - } - - - if (column_exists('branch_borrower_circ_rules', 'max_holds') ){ - $dbh->do(q{ - INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) - SELECT branchcode, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM branch_borrower_circ_rules - }); - - $dbh->do(q{ - ALTER TABLE branch_borrower_circ_rules DROP COLUMN max_holds - }); - } - - if (column_exists('default_borrower_circ_rules', 'max_holds') ){ - $dbh->do(q{ - INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) - SELECT NULL, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM default_borrower_circ_rules - }); - - $dbh->do(q{ - ALTER TABLE default_borrower_circ_rules DROP COLUMN max_holds - }); - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 18887 - Introduce new table 'circulation_rules', use for 'max_holds' rules)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e9ad680be2..e277334d3e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -16483,6 +16483,49 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 21403 - Add Indian Amazon Affiliate option to AmazonLocale setting)\n"; } + +$DBversion = '18.06.00.036'; +if( CheckVersion( $DBversion ) ) { + unless (TableExists('circulation_rules')){ + $dbh->do(q{ + CREATE TABLE `circulation_rules` ( + `id` int(11) NOT NULL auto_increment, + `branchcode` varchar(10) NULL default NULL, + `categorycode` varchar(10) NULL default NULL, + `itemtype` varchar(10) NULL default NULL, + `rule_name` varchar(32) NOT NULL, + `rule_value` varchar(32) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `circ_rules_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `circ_rules_ibfk_3` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, + KEY `rule_name` (`rule_name`), + UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + }); + } + if (column_exists('branch_borrower_circ_rules', 'max_holds') ){ + $dbh->do(q{ + INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) + SELECT branchcode, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM branch_borrower_circ_rules + }); + $dbh->do(q{ + ALTER TABLE branch_borrower_circ_rules DROP COLUMN max_holds + }); + } + if (column_exists('default_borrower_circ_rules', 'max_holds') ){ + $dbh->do(q{ + INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value ) + SELECT NULL, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM default_borrower_circ_rules + }); + $dbh->do(q{ + ALTER TABLE default_borrower_circ_rules DROP COLUMN max_holds + }); + } + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18887 - Introduce new table 'circulation_rules', use for 'max_holds' rules)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5