From d2af9b9cb73067218e551fe0963c090b3df78316 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 17 Jul 2025 14:42:56 +0000 Subject: [PATCH] Bug 40517: Add visual_group_id to hold_groups Signed-off-by: Anneli Signed-off-by: Andrew Fuerste Henry --- Koha/Patron.pm | 8 +++++++- Koha/Schema/Result/HoldGroup.pm | 13 +++++++++++-- Koha/Schema/Result/OldReserve.pm | 4 ++-- Koha/Schema/Result/Reserve.pm | 4 ++-- api/v1/swagger/definitions/hold_group.yaml | 3 +++ .../bug_40517_-_hold_group_table_updates.pl | 9 ++++++++- installer/data/mysql/kohastructure.sql | 1 + svc/holds | 1 + 8 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 571227f359b..ae113efabff 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1916,9 +1916,15 @@ sub create_hold_group { hold_ids => \@already_in_group_holds, ) if @already_in_group_holds && !$force_grouped; + my @existing_ids = $self->_result->hold_groups->get_column('visual_hold_group_id')->all; + my $next_available_visual_hold_group_id = 1; + while ( grep { $_ == $next_available_visual_hold_group_id } @existing_ids ) { + $next_available_visual_hold_group_id++; + } + my $hold_group_rs = $self->_result->create_related( 'hold_groups', - {} + { visual_hold_group_id => $next_available_visual_hold_group_id } ); foreach my $hold_id (@$hold_ids) { my $hold = Koha::Holds->find($hold_id); diff --git a/Koha/Schema/Result/HoldGroup.pm b/Koha/Schema/Result/HoldGroup.pm index ac2c9ffdbbf..173e7443e2a 100644 --- a/Koha/Schema/Result/HoldGroup.pm +++ b/Koha/Schema/Result/HoldGroup.pm @@ -38,6 +38,13 @@ __PACKAGE__->table("hold_groups"); foreign key, linking this to the borrowers table +=head2 visual_hold_group_id + + data_type: 'integer' + is_nullable: 1 + +visual ID for this hold group, in the context of the related patron + =cut __PACKAGE__->add_columns( @@ -50,6 +57,8 @@ __PACKAGE__->add_columns( }, "borrowernumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "visual_hold_group_id", + { data_type => "integer", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -117,8 +126,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-16 10:57:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Y1eP6naEI2vi94gTHqtubw +# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-25 13:02:35 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hlAYDHvqpFZRpNU+d+y4RA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/OldReserve.pm b/Koha/Schema/Result/OldReserve.pm index 028386206dc..07bbcbc8079 100644 --- a/Koha/Schema/Result/OldReserve.pm +++ b/Koha/Schema/Result/OldReserve.pm @@ -473,8 +473,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-09-03 17:08:22 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bo/exwlpahEVYtkWjusWLw +# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-17 12:06:49 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gjkXXK86royQ6IaAFZI4Yg __PACKAGE__->belongs_to( "item", diff --git a/Koha/Schema/Result/Reserve.pm b/Koha/Schema/Result/Reserve.pm index 3e65b00f67c..664df77b482 100644 --- a/Koha/Schema/Result/Reserve.pm +++ b/Koha/Schema/Result/Reserve.pm @@ -501,8 +501,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-09-03 17:08:22 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:57Fw53HngTXhDU7kVEjqYw +# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-25 13:02:35 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:x5AS7F7aOMb9ihb8gaxZvQ __PACKAGE__->belongs_to( "item", diff --git a/api/v1/swagger/definitions/hold_group.yaml b/api/v1/swagger/definitions/hold_group.yaml index cb9d34cc88e..271c262b58b 100644 --- a/api/v1/swagger/definitions/hold_group.yaml +++ b/api/v1/swagger/definitions/hold_group.yaml @@ -7,6 +7,9 @@ properties: borrowernumber: type: integer description: Patron this hold group belongs to + visual_hold_group_id: + type: integer + description: Visual ID for this hold group, in the context of the related patron holds: type: - array diff --git a/installer/data/mysql/atomicupdate/bug_40517_-_hold_group_table_updates.pl b/installer/data/mysql/atomicupdate/bug_40517_-_hold_group_table_updates.pl index e520c378a40..0d7511eb763 100755 --- a/installer/data/mysql/atomicupdate/bug_40517_-_hold_group_table_updates.pl +++ b/installer/data/mysql/atomicupdate/bug_40517_-_hold_group_table_updates.pl @@ -3,7 +3,7 @@ use Koha::Installer::Output qw(say_warning say_success say_info); return { bug_number => "40517", - description => "Add 'borrower' column to hold_groups", + description => "Add 'borrower' and 'visual_hold_group_id' column to hold_groups", up => sub { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; @@ -27,5 +27,12 @@ return { ); say_success( $out, "Added column 'borrowernumber' to hold_groups" ); } + + unless ( column_exists( 'hold_groups', 'visual_hold_group_id' ) ) { + $dbh->do( + q{ALTER TABLE hold_groups ADD COLUMN visual_hold_group_id int(11) DEFAULT NULL COMMENT 'visual ID for this hold group, in the context of the related patron' AFTER borrowernumber} + ); + say_success( $out, "Added column 'visual_hold_group_id' to hold_groups" ); + } }, }; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index c6fc8abd9e9..8f7e84fbbef 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3552,6 +3552,7 @@ DROP TABLE IF EXISTS `hold_groups`; CREATE TABLE `hold_groups` ( `hold_group_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table', + `visual_hold_group_id` int(11) DEFAULT NULL COMMENT 'visual ID for this hold group, in the context of the related patron', KEY `hold_groups_borrowernumber` (`borrowernumber`), CONSTRAINT `hold_groups_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE, PRIMARY KEY (`hold_group_id`) diff --git a/svc/holds b/svc/holds index 1f9acb167a6..864841851a9 100755 --- a/svc/holds +++ b/svc/holds @@ -114,6 +114,7 @@ while ( my $h = $holds_rs->next() ) { reservenotes => $h->reservenotes(), itemtype_limit => $itemtype_limit, hold_group_id => $h->hold_group_id, + visual_hold_group_id => $h->hold_group ? $h->hold_group->visual_hold_group_id : q{}, reservedate_formatted => $h->reservedate() ? output_pref( { dt => dt_from_string( $h->reservedate() ), dateonly => 1 } ) : q{}, -- 2.39.5