From c3f28829e50690da8fdfa104cdbacb3d0354da18 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 11 Mar 2019 13:03:37 +0000 Subject: [PATCH] Bug 22368: DBRev 18.12.00.024 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Biblio.pm | 19 ++- Koha/Schema/Result/Borrower.pm | 64 +++++++- Koha/Schema/Result/Branch.pm | 19 ++- Koha/Schema/Result/Suggestion.pm | 145 ++++++++++++++++-- .../data/mysql/atomicupdate/bug_22368.perl | 80 ---------- installer/data/mysql/updatedatabase.pl | 81 ++++++++++ 7 files changed, 313 insertions(+), 97 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22368.perl diff --git a/Koha.pm b/Koha.pm index c346b3bfd2..1d4d38e3f9 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.12.00.023"; +$VERSION = "18.12.00.024"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Biblio.pm b/Koha/Schema/Result/Biblio.pm index b118011f27..53e806b81f 100644 --- a/Koha/Schema/Result/Biblio.pm +++ b/Koha/Schema/Result/Biblio.pm @@ -302,6 +302,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 suggestions + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions", + "Koha::Schema::Result::Suggestion", + { "foreign.biblionumber" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 tags_all Type: has_many @@ -348,7 +363,7 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bUv00JjY09Hj2Zj4klqyxA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ebn7Szfm8/HbrdAc7ekTnA 1; diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 6c6fd7eaa8..a9e9a5c216 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -1315,6 +1315,66 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 suggestions_acceptedbies + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions_acceptedbies", + "Koha::Schema::Result::Suggestion", + { "foreign.acceptedby" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 suggestions_managedbies + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions_managedbies", + "Koha::Schema::Result::Suggestion", + { "foreign.managedby" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 suggestions_rejectedbies + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions_rejectedbies", + "Koha::Schema::Result::Suggestion", + { "foreign.rejectedby" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 suggestions_suggestedbies + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions_suggestedbies", + "Koha::Schema::Result::Suggestion", + { "foreign.suggestedby" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 tags_all Type: has_many @@ -1446,8 +1506,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-02-15 13:15:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NhuG8jv9ut+qIIm3vGHsrQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:F/j4bsmnxc2Cja5DKfMseQ __PACKAGE__->belongs_to( "guarantor", diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm index 576de646e1..40d54c0f09 100644 --- a/Koha/Schema/Result/Branch.pm +++ b/Koha/Schema/Result/Branch.pm @@ -631,6 +631,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 suggestions + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "suggestions", + "Koha::Schema::Result::Suggestion", + { "foreign.branchcode" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 transport_cost_frombranches Type: has_many @@ -662,8 +677,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-05 20:42:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nArzlMOpUO6oVOAZUgzSRg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pKohWwsuUHcZSlGDj7zmcw __PACKAGE__->add_columns( '+pickup_location' => { is_boolean => 1 } diff --git a/Koha/Schema/Result/Suggestion.pm b/Koha/Schema/Result/Suggestion.pm index ac08c1e5c1..2086d98811 100644 --- a/Koha/Schema/Result/Suggestion.pm +++ b/Koha/Schema/Result/Suggestion.pm @@ -32,8 +32,8 @@ __PACKAGE__->table("suggestions"); =head2 suggestedby data_type: 'integer' - default_value: 0 - is_nullable: 0 + is_foreign_key: 1 + is_nullable: 1 =head2 suggesteddate @@ -44,6 +44,7 @@ __PACKAGE__->table("suggestions"); =head2 managedby data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 manageddate @@ -55,6 +56,7 @@ __PACKAGE__->table("suggestions"); =head2 acceptedby data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 accepteddate @@ -66,6 +68,7 @@ __PACKAGE__->table("suggestions"); =head2 rejectedby data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 rejecteddate @@ -144,6 +147,7 @@ __PACKAGE__->table("suggestions"); =head2 biblionumber data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 reason @@ -165,6 +169,7 @@ __PACKAGE__->table("suggestions"); =head2 branchcode data_type: 'varchar' + is_foreign_key: 1 is_nullable: 1 size: 10 @@ -208,19 +213,19 @@ __PACKAGE__->add_columns( "suggestionid", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "suggestedby", - { data_type => "integer", default_value => 0, is_nullable => 0 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "suggesteddate", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 0 }, "managedby", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "manageddate", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "acceptedby", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "accepteddate", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "rejectedby", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "rejecteddate", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "STATUS", @@ -257,7 +262,7 @@ __PACKAGE__->add_columns( "isbn", { data_type => "varchar", is_nullable => 1, size => 30 }, "biblionumber", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "reason", { data_type => "mediumtext", is_nullable => 1 }, "patronreason", @@ -265,7 +270,7 @@ __PACKAGE__->add_columns( "budgetid", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "branchcode", - { data_type => "varchar", is_nullable => 1, size => 10 }, + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, "collectiontitle", { data_type => "mediumtext", is_nullable => 1 }, "itemtype", @@ -294,6 +299,66 @@ __PACKAGE__->set_primary_key("suggestionid"); =head1 RELATIONS +=head2 acceptedby + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "acceptedby", + "Koha::Schema::Result::Borrower", + { borrowernumber => "acceptedby" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +=head2 biblionumber + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "biblionumber", + "Koha::Schema::Result::Biblio", + { biblionumber => "biblionumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +=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 => "SET NULL", + on_update => "CASCADE", + }, +); + =head2 budgetid Type: belongs_to @@ -314,9 +379,69 @@ __PACKAGE__->belongs_to( }, ); +=head2 managedby + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "managedby", + "Koha::Schema::Result::Borrower", + { borrowernumber => "managedby" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +=head2 rejectedby + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "rejectedby", + "Koha::Schema::Result::Borrower", + { borrowernumber => "rejectedby" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +=head2 suggestedby + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "suggestedby", + "Koha::Schema::Result::Borrower", + { borrowernumber => "suggestedby" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dOt4/U4rLcXq+aACRwcpYw +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UsG/gxLa0HMMbcpbscV29Q # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_22368.perl b/installer/data/mysql/atomicupdate/bug_22368.perl deleted file mode 100644 index e5b8a1056d..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22368.perl +++ /dev/null @@ -1,80 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if ( CheckVersion($DBversion) ) { - - # Add constraint for suggestedby - unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_suggestedby' ) ) - { - $dbh->do( -"ALTER TABLE suggestions CHANGE COLUMN suggestedby suggestedby INT(11) NULL DEFAULT NULL;" - ); - $dbh->do( -"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.suggestedby = borrowers.borrowernumber) SET suggestedby = null WHERE borrowernumber IS null" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_suggestedby` FOREIGN KEY (`suggestedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - # Add constraint for managedby - unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_managedby' ) ) - { - $dbh->do( -"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.managedby = borrowers.borrowernumber) SET managedby = null WHERE borrowernumber IS NULL" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_managedby` FOREIGN KEY (`managedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - # Add constraint for acceptedby - unless ( - foreign_key_exists( 'suggestions', 'suggestions_ibfk_acceptedby' ) ) - { - $dbh->do( -"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.acceptedby = borrowers.borrowernumber) SET acceptedby = null WHERE borrowernumber IS NULL" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_acceptedby` FOREIGN KEY (`acceptedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - # Add constraint for rejectedby - unless ( - foreign_key_exists( 'suggestions', 'suggestions_ibfk_rejectedby' ) ) - { - $dbh->do( -"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.rejectedby = borrowers.borrowernumber) SET rejectedby = null WHERE borrowernumber IS null" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_rejectedby` FOREIGN KEY (`rejectedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - # Add constraint for biblionumber - unless ( - foreign_key_exists( 'suggestions', 'suggestions_ibfk_biblionumber' ) ) - { - $dbh->do( -"UPDATE suggestions s LEFT JOIN biblio b ON (s.biblionumber = b.biblionumber) SET s.biblionumber = null WHERE b.biblionumber IS null" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_biblionumber` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - # Add constraint for branchcode - unless ( - foreign_key_exists( 'suggestions', 'suggestions_ibfk_branchcode' ) ) - { - $dbh->do( -"UPDATE suggestions s LEFT JOIN branches b ON (s.branchcode = b.branchcode) SET s.branchcode = null WHERE b.branchcode IS null" - ); - $dbh->do( -"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE" - ); - } - - SetVersion($DBversion); - print -"Upgrade to $DBversion done (Bug 22368 - Add missing constraints to suggestions)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f824fba5cb..1298e454c0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17609,6 +17609,87 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 20639 - Add ILLOpacbackends syspref)\n"; } +$DBversion = '18.12.00.024'; +if ( CheckVersion($DBversion) ) { + + # Add constraint for suggestedby + unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_suggestedby' ) ) + { + $dbh->do( +"ALTER TABLE suggestions CHANGE COLUMN suggestedby suggestedby INT(11) NULL DEFAULT NULL;" + ); + $dbh->do( +"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.suggestedby = borrowers.borrowernumber) SET suggestedby = null WHERE borrowernumber IS null" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_suggestedby` FOREIGN KEY (`suggestedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + # Add constraint for managedby + unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_managedby' ) ) + { + $dbh->do( +"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.managedby = borrowers.borrowernumber) SET managedby = null WHERE borrowernumber IS NULL" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_managedby` FOREIGN KEY (`managedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + # Add constraint for acceptedby + unless ( + foreign_key_exists( 'suggestions', 'suggestions_ibfk_acceptedby' ) ) + { + $dbh->do( +"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.acceptedby = borrowers.borrowernumber) SET acceptedby = null WHERE borrowernumber IS NULL" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_acceptedby` FOREIGN KEY (`acceptedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + # Add constraint for rejectedby + unless ( + foreign_key_exists( 'suggestions', 'suggestions_ibfk_rejectedby' ) ) + { + $dbh->do( +"UPDATE suggestions LEFT JOIN borrowers ON (suggestions.rejectedby = borrowers.borrowernumber) SET rejectedby = null WHERE borrowernumber IS null" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_rejectedby` FOREIGN KEY (`rejectedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + # Add constraint for biblionumber + unless ( + foreign_key_exists( 'suggestions', 'suggestions_ibfk_biblionumber' ) ) + { + $dbh->do( +"UPDATE suggestions s LEFT JOIN biblio b ON (s.biblionumber = b.biblionumber) SET s.biblionumber = null WHERE b.biblionumber IS null" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_biblionumber` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + # Add constraint for branchcode + unless ( + foreign_key_exists( 'suggestions', 'suggestions_ibfk_branchcode' ) ) + { + $dbh->do( +"UPDATE suggestions s LEFT JOIN branches b ON (s.branchcode = b.branchcode) SET s.branchcode = null WHERE b.branchcode IS null" + ); + $dbh->do( +"ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE" + ); + } + + SetVersion($DBversion); + print +"Upgrade to $DBversion done (Bug 22368 - Add missing constraints to suggestions)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5