From a3dd19a4d519319e0c982c7814c061eccc8a144a 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 --- Koha/Patron.pm | 8 ++++++- Koha/Schema/Result/HoldGroup.pm | 13 ++++++++-- Koha/Schema/Result/OldReserve.pm | 24 +++++++++---------- Koha/Schema/Result/Reserve.pm | 24 +++++++++---------- api/v1/swagger/definitions/hold_group.yaml | 3 +++ .../bug_40517_-_hold_group_table_updates.pl | 9 ++++++- installer/data/mysql/kohastructure.sql | 3 ++- svc/holds | 1 + 8 files changed, 56 insertions(+), 29 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 1f70c473e9c..23f38211db9 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1897,9 +1897,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 e6b7e971992..07bbcbc8079 100644 --- a/Koha/Schema/Result/OldReserve.pm +++ b/Koha/Schema/Result/OldReserve.pm @@ -392,18 +392,18 @@ __PACKAGE__->belongs_to( }, ); -=head2 item_group +=head2 hold_group Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "item_group", - "Koha::Schema::Result::ItemGroup", - { item_group_id => "item_group_id" }, + "hold_group", + "Koha::Schema::Result::HoldGroup", + { hold_group_id => "hold_group_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -412,18 +412,18 @@ __PACKAGE__->belongs_to( }, ); -=head2 hold_group +=head2 item_group Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "hold_group", - "Koha::Schema::Result::HoldGroup", - { hold_group_id => "hold_group_id" }, + "item_group", + "Koha::Schema::Result::ItemGroup", + { item_group_id => "item_group_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -473,8 +473,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-30 17:21:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6huDoFe9Uil1WyJ7EOcQSw +# 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 0d730f2e6cc..664df77b482 100644 --- a/Koha/Schema/Result/Reserve.pm +++ b/Koha/Schema/Result/Reserve.pm @@ -420,18 +420,18 @@ __PACKAGE__->belongs_to( }, ); -=head2 item_group +=head2 hold_group Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "item_group", - "Koha::Schema::Result::ItemGroup", - { item_group_id => "item_group_id" }, + "hold_group", + "Koha::Schema::Result::HoldGroup", + { hold_group_id => "hold_group_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -440,18 +440,18 @@ __PACKAGE__->belongs_to( }, ); -=head2 hold_group +=head2 item_group Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "hold_group", - "Koha::Schema::Result::HoldGroup", - { hold_group_id => "hold_group_id" }, + "item_group", + "Koha::Schema::Result::ItemGroup", + { item_group_id => "item_group_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -501,8 +501,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-30 17:21:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bmt1FkgXdJSOMQFdAHO3cQ +# 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 9b0ea8936ac..4ce20a82efe 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -5065,8 +5065,9 @@ DROP TABLE IF EXISTS `hold_groups`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE hold_groups ( - hold_group_id int unsigned NOT NULL AUTO_INCREMENT, + `hold_group_id` int 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 8dc9c75cd03..a755a7f422a 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