From 3152aca2d1a3cacd3c0bc426c5b37414d014eefd 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 +++++++- api/v1/swagger/definitions/hold_group.yaml | 3 +++ .../atomicupdate/bug_40517_-_hold_group_table_updates.pl | 9 ++++++++- installer/data/mysql/kohastructure.sql | 1 + svc/holds | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 6001c3684f7..745355819d5 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1957,9 +1957,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/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 5da6ad17509..330155a4f77 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