From 7a68532048ac6edf62ccbfa0c1f5181fc682c1c7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 1 Oct 2019 08:12:28 +0100 Subject: [PATCH] Bug 19618: DBRev 19.06.00.030 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- Koha/Schema/Result/Biblio.pm | 19 +- Koha/Schema/Result/Borrower.pm | 19 +- Koha/Schema/Result/Club.pm | 19 +- Koha/Schema/Result/ClubHold.pm | 162 +++++++++++++++++ Koha/Schema/Result/ClubHoldsToPatronHold.pm | 167 ++++++++++++++++++ Koha/Schema/Result/Item.pm | 19 +- Koha/Schema/Result/Reserve.pm | 19 +- .../data/mysql/atomicupdate/club_holds.perl | 42 ----- installer/data/mysql/updatedatabase.pl | 43 +++++ 10 files changed, 458 insertions(+), 53 deletions(-) create mode 100644 Koha/Schema/Result/ClubHold.pm create mode 100644 Koha/Schema/Result/ClubHoldsToPatronHold.pm delete mode 100644 installer/data/mysql/atomicupdate/club_holds.perl diff --git a/Koha.pm b/Koha.pm index 28a0f6d49a..c5d7302aba 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.06.00.029"; +$VERSION = "19.06.00.030"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Biblio.pm b/Koha/Schema/Result/Biblio.pm index 9674b56fe6..43fa26af46 100644 --- a/Koha/Schema/Result/Biblio.pm +++ b/Koha/Schema/Result/Biblio.pm @@ -240,6 +240,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 club_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds", + "Koha::Schema::Result::ClubHold", + { "foreign.biblio_id" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 hold_fill_targets Type: has_many @@ -391,8 +406,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-08-05 13:53:34 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AzvuQItPPs5WeC4tdtS/NQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:otCex8qzJmZyc+JXpKNdpQ __PACKAGE__->has_one( diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index ff22015989..07137a679b 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -959,6 +959,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 club_holds_to_patron_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds_to_patron_holds", + "Koha::Schema::Result::ClubHoldsToPatronHold", + { "foreign.patron_id" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 course_instructors Type: has_many @@ -1560,8 +1575,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-22 04:33:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lbMdmIHlRt+zayG5+Rq4/w +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:FRyurgV8tVN4EBduIM8tGA __PACKAGE__->add_columns( '+anonymized' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/Club.pm b/Koha/Schema/Result/Club.pm index 7011cd54e6..7710a752d0 100644 --- a/Koha/Schema/Result/Club.pm +++ b/Koha/Schema/Result/Club.pm @@ -173,6 +173,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 club_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds", + "Koha::Schema::Result::ClubHold", + { "foreign.club_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 club_template Type: belongs_to @@ -189,8 +204,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6EB6FURHN+brOhDoPZVeGQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WbB7PSSU4xaszsKe9Eacqw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/ClubHold.pm b/Koha/Schema/Result/ClubHold.pm new file mode 100644 index 0000000000..8287c72eec --- /dev/null +++ b/Koha/Schema/Result/ClubHold.pm @@ -0,0 +1,162 @@ +use utf8; +package Koha::Schema::Result::ClubHold; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::ClubHold + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("club_holds"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 club_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 biblio_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 item_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + +=head2 date_created + + data_type: 'timestamp' + datetime_undef_if_invalid: 1 + default_value: current_timestamp + is_nullable: 0 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "club_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "biblio_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "item_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "date_created", + { + data_type => "timestamp", + datetime_undef_if_invalid => 1, + default_value => \"current_timestamp", + is_nullable => 0, + }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 biblio + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "biblio", + "Koha::Schema::Result::Biblio", + { biblionumber => "biblio_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +=head2 club + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "club", + "Koha::Schema::Result::Club", + { id => "club_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +=head2 club_holds_to_patron_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds_to_patron_holds", + "Koha::Schema::Result::ClubHoldsToPatronHold", + { "foreign.club_hold_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 item + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "item", + "Koha::Schema::Result::Item", + { itemnumber => "item_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:FYGXVx1P2R+dGbeP1xshPA + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/Koha/Schema/Result/ClubHoldsToPatronHold.pm b/Koha/Schema/Result/ClubHoldsToPatronHold.pm new file mode 100644 index 0000000000..cb4931a675 --- /dev/null +++ b/Koha/Schema/Result/ClubHoldsToPatronHold.pm @@ -0,0 +1,167 @@ +use utf8; +package Koha::Schema::Result::ClubHoldsToPatronHold; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::ClubHoldsToPatronHold + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("club_holds_to_patron_holds"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 club_hold_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 patron_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 hold_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + +=head2 error_code + + data_type: 'enum' + extra: {list => ["damaged","ageRestricted","itemAlreadyOnHold","tooManyHoldsForThisRecord","tooManyReservesToday","tooManyReserves","notReservable","cannotReserveFromOtherBranches","libraryNotFound","libraryNotPickupLocation","cannotBeTransferred"]} + is_nullable: 1 + +=head2 error_message + + data_type: 'varchar' + is_nullable: 1 + size: 100 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "club_hold_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "patron_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "hold_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "error_code", + { + data_type => "enum", + extra => { + list => [ + "damaged", + "ageRestricted", + "itemAlreadyOnHold", + "tooManyHoldsForThisRecord", + "tooManyReservesToday", + "tooManyReserves", + "notReservable", + "cannotReserveFromOtherBranches", + "libraryNotFound", + "libraryNotPickupLocation", + "cannotBeTransferred", + ], + }, + is_nullable => 1, + }, + "error_message", + { data_type => "varchar", is_nullable => 1, size => 100 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 club_hold + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "club_hold", + "Koha::Schema::Result::ClubHold", + { id => "club_hold_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +=head2 hold + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "hold", + "Koha::Schema::Result::Reserve", + { reserve_id => "hold_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + +=head2 patron + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "patron", + "Koha::Schema::Result::Borrower", + { borrowernumber => "patron_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/T626DfqUi7SnXOyieUzYw + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 9d5743f5c2..da2a91f6ac 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -511,6 +511,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 club_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds", + "Koha::Schema::Result::ClubHold", + { "foreign.item_id" => "self.itemnumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 course_item Type: might_have @@ -717,8 +732,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-14 18:14:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wDXcErUYqg0aoQkzz3P5vg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:n/X6k+IwU4pkLS+PjKWVWA __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); diff --git a/Koha/Schema/Result/Reserve.pm b/Koha/Schema/Result/Reserve.pm index 086b621f5f..3a56d68e21 100644 --- a/Koha/Schema/Result/Reserve.pm +++ b/Koha/Schema/Result/Reserve.pm @@ -280,6 +280,21 @@ __PACKAGE__->belongs_to( }, ); +=head2 club_holds_to_patron_holds + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_holds_to_patron_holds", + "Koha::Schema::Result::ClubHoldsToPatronHold", + { "foreign.hold_id" => "self.reserve_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 itemnumber Type: belongs_to @@ -321,8 +336,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-06-17 07:24:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OMFqEWyKqFTcYj7vAFXy/g +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:48 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Pc5zh5iFbdwko5KS51Y9Uw __PACKAGE__->belongs_to( "item", diff --git a/installer/data/mysql/atomicupdate/club_holds.perl b/installer/data/mysql/atomicupdate/club_holds.perl deleted file mode 100644 index e92789c7ba..0000000000 --- a/installer/data/mysql/atomicupdate/club_holds.perl +++ /dev/null @@ -1,42 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - $dbh->do(q| - CREATE TABLE IF NOT EXISTS club_holds ( - id INT(11) NOT NULL AUTO_INCREMENT, - club_id INT(11) NOT NULL, -- id for the club the hold was generated for - biblio_id INT(11) NOT NULL, -- id for the bibliographic record the hold has been placed against - item_id INT(11) NULL DEFAULT NULL, -- If item-level, the id for the item the hold has been placed agains - date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Timestamp for the placed hold - PRIMARY KEY (id), - -- KEY club_id (club_id), - CONSTRAINT clubs_holds_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT clubs_holds_ibfk_2 FOREIGN KEY (biblio_id) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT clubs_holds_ibfk_3 FOREIGN KEY (item_id) REFERENCES items (itemnumber) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - |); - - $dbh->do(q| - CREATE TABLE IF NOT EXISTS club_holds_to_patron_holds ( - id INT(11) NOT NULL AUTO_INCREMENT, - club_hold_id INT(11) NOT NULL, - patron_id INT(11) NOT NULL, - hold_id INT(11), - error_code ENUM ( 'damaged', 'ageRestricted', 'itemAlreadyOnHold', - 'tooManyHoldsForThisRecord', 'tooManyReservesToday', - 'tooManyReserves', 'notReservable', 'cannotReserveFromOtherBranches', - 'libraryNotFound', 'libraryNotPickupLocation', 'cannotBeTransferred' - ) NULL DEFAULT NULL, - error_message varchar(100) NULL DEFAULT NULL, - PRIMARY KEY (id), - -- KEY club_hold_id (club_hold_id), - CONSTRAINT clubs_holds_paton_holds_ibfk_1 FOREIGN KEY (club_hold_id) REFERENCES club_holds (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT clubs_holds_paton_holds_ibfk_2 FOREIGN KEY (patron_id) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT clubs_holds_paton_holds_ibfk_3 FOREIGN KEY (hold_id) REFERENCES reserves (reserve_id) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - |); - - # Always end with this (adjust the bug info) - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 19618 - add club_holds tables)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 5f34a84aaa..913c9c7bbe 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -19501,6 +19501,49 @@ if ( CheckVersion($DBversion) ) { print "Upgrade to $DBversion done (Bug 23321 - Add cash_registers table, permissions and preferences)\n"; } +$DBversion = '19.06.00.030'; +if( CheckVersion( $DBversion ) ) { + + $dbh->do(q| + CREATE TABLE IF NOT EXISTS club_holds ( + id INT(11) NOT NULL AUTO_INCREMENT, + club_id INT(11) NOT NULL, -- id for the club the hold was generated for + biblio_id INT(11) NOT NULL, -- id for the bibliographic record the hold has been placed against + item_id INT(11) NULL DEFAULT NULL, -- If item-level, the id for the item the hold has been placed agains + date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Timestamp for the placed hold + PRIMARY KEY (id), + -- KEY club_id (club_id), + CONSTRAINT clubs_holds_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT clubs_holds_ibfk_2 FOREIGN KEY (biblio_id) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT clubs_holds_ibfk_3 FOREIGN KEY (item_id) REFERENCES items (itemnumber) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + |); + + $dbh->do(q| + CREATE TABLE IF NOT EXISTS club_holds_to_patron_holds ( + id INT(11) NOT NULL AUTO_INCREMENT, + club_hold_id INT(11) NOT NULL, + patron_id INT(11) NOT NULL, + hold_id INT(11), + error_code ENUM ( 'damaged', 'ageRestricted', 'itemAlreadyOnHold', + 'tooManyHoldsForThisRecord', 'tooManyReservesToday', + 'tooManyReserves', 'notReservable', 'cannotReserveFromOtherBranches', + 'libraryNotFound', 'libraryNotPickupLocation', 'cannotBeTransferred' + ) NULL DEFAULT NULL, + error_message varchar(100) NULL DEFAULT NULL, + PRIMARY KEY (id), + -- KEY club_hold_id (club_hold_id), + CONSTRAINT clubs_holds_paton_holds_ibfk_1 FOREIGN KEY (club_hold_id) REFERENCES club_holds (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT clubs_holds_paton_holds_ibfk_2 FOREIGN KEY (patron_id) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT clubs_holds_paton_holds_ibfk_3 FOREIGN KEY (hold_id) REFERENCES reserves (reserve_id) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + |); + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 19618 - add club_holds tables)\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.20.1