View | Details | Raw Unified | Return to bug 40529
Collapse All | Expand All

(-)a/Koha/Hold.pm (+25 lines)
Lines 290-295 sub set_as_hold_group_target { Link Here
290
    }
290
    }
291
}
291
}
292
292
293
=head3 remove_as_hold_group_target
294
295
$self->remove_as_hold_group_target;
296
297
Removes this hold as the target of its hold group if it is currently set as such,
298
and if the DisplayAddHoldGroups system preference is enabled.
299
300
=cut
301
302
sub remove_as_hold_group_target {
303
    my ($self) = @_;
304
305
    if (   $self->hold_group
306
        && $self->hold_group->target_hold_id eq $self->reserve_id
307
        && C4::Context->preference("DisplayAddHoldGroups") )
308
    {
309
        $self->_result->find_related(
310
            'hold_group_target_hold',
311
            { hold_group_id => $self->hold_group->hold_group_id, reserve_id => $self->reserve_id }
312
        )->delete();
313
    }
314
}
315
293
=head3 is_hold_group_target
316
=head3 is_hold_group_target
294
317
295
$self->is_hold_group_target;
318
$self->is_hold_group_target;
Lines 1083-1088 sub revert_found { Link Here
1083
1106
1084
            C4::Reserves::_FixPriority( { biblionumber => $self->biblionumber } );
1107
            C4::Reserves::_FixPriority( { biblionumber => $self->biblionumber } );
1085
1108
1109
            $self->remove_as_hold_group_target();
1110
1086
            Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $self->biblionumber ] } )
1111
            Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $self->biblionumber ] } )
1087
                if C4::Context->preference('RealTimeHoldsQueue');
1112
                if C4::Context->preference('RealTimeHoldsQueue');
1088
        }
1113
        }
(-)a/Koha/Schema/Result/HoldGroupTargetHold.pm (-10 / +19 lines)
Lines 36-42 foreign key, linking this to the hold_groups table Link Here
36
36
37
  data_type: 'integer'
37
  data_type: 'integer'
38
  is_foreign_key: 1
38
  is_foreign_key: 1
39
  is_nullable: 1
39
  is_nullable: 0
40
40
41
foreign key, linking this to the reserves table
41
foreign key, linking this to the reserves table
42
42
Lines 51-59 __PACKAGE__->add_columns( Link Here
51
    is_nullable => 0,
51
    is_nullable => 0,
52
  },
52
  },
53
  "reserve_id",
53
  "reserve_id",
54
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
54
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
55
);
55
);
56
56
57
=head1 PRIMARY KEY
58
59
=over 4
60
61
=item * L</hold_group_id>
62
63
=item * L</reserve_id>
64
65
=back
66
67
=cut
68
69
__PACKAGE__->set_primary_key("hold_group_id", "reserve_id");
70
57
=head1 UNIQUE CONSTRAINTS
71
=head1 UNIQUE CONSTRAINTS
58
72
59
=head2 C<hold_group_id>
73
=head2 C<hold_group_id>
Lines 109-125 __PACKAGE__->belongs_to( Link Here
109
  "reserve",
123
  "reserve",
110
  "Koha::Schema::Result::Reserve",
124
  "Koha::Schema::Result::Reserve",
111
  { reserve_id => "reserve_id" },
125
  { reserve_id => "reserve_id" },
112
  {
126
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
113
    is_deferrable => 1,
114
    join_type     => "LEFT",
115
    on_delete     => "CASCADE",
116
    on_update     => "RESTRICT",
117
  },
118
);
127
);
119
128
120
129
121
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-25 13:10:48
130
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-08-06 15:04:39
122
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xgRnzTXH+Q+YxYLKQeGe+g
131
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UD9tr/ceHggVl1rRrimtVg
123
132
124
133
125
# You can replace this text with custom code or comments, and it will be preserved on regeneration
134
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/installer/data/mysql/atomicupdate/bug_40529_-_hold_group_table_target.pl (+1 lines)
Lines 14-19 return { Link Here
14
                    CREATE TABLE hold_group_target_holds (
14
                    CREATE TABLE hold_group_target_holds (
15
                        `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
15
                        `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
16
                        `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
16
                        `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
17
                        PRIMARY KEY (`hold_group_id`, `reserve_id`),
17
                        CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
18
                        CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
18
                        CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
19
                        CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
19
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
20
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 5088-5093 DROP TABLE IF EXISTS `hold_group_target_holds`; Link Here
5088
CREATE TABLE hold_group_target_holds (
5088
CREATE TABLE hold_group_target_holds (
5089
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5089
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5090
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5090
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5091
    PRIMARY KEY (`hold_group_id`, `reserve_id`),
5091
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5092
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5092
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5093
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5093
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5094
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/t/db_dependent/Koha/Hold.t (-3 / +9 lines)
Lines 36-42 use Koha::DateUtils qw(dt_from_string); Link Here
36
use Koha::Holds;
36
use Koha::Holds;
37
use Koha::Libraries;
37
use Koha::Libraries;
38
use Koha::Old::Holds;
38
use Koha::Old::Holds;
39
use C4::Reserves    qw( AddReserve ModReserveAffect );
39
use C4::Reserves    qw( AddReserve ModReserveAffect RevertWaitingStatus);
40
use C4::Circulation qw( AddReturn );
40
use C4::Circulation qw( AddReturn );
41
41
42
my $schema  = Koha::Database->new->schema;
42
my $schema  = Koha::Database->new->schema;
Lines 1977-1983 subtest 'is_hold_group_target, cleanup_hold_group and set_as_hold_group_target t Link Here
1977
};
1977
};
1978
1978
1979
subtest '_Findgroupreserve in the context of hold groups' => sub {
1979
subtest '_Findgroupreserve in the context of hold groups' => sub {
1980
    plan tests => 17;
1980
    plan tests => 19;
1981
1981
1982
    $schema->storage->txn_begin;
1982
    $schema->storage->txn_begin;
1983
1983
Lines 2078-2083 subtest '_Findgroupreserve in the context of hold groups' => sub { Link Here
2078
2078
2079
    is( $hold->is_hold_group_target, 1, 'First hold is the hold group target' );
2079
    is( $hold->is_hold_group_target, 1, 'First hold is the hold group target' );
2080
2080
2081
    C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
2082
    is( $hold->is_hold_group_target,       0,     'First hold is no longer the hold group target' );
2083
    is( $hold->hold_group->target_hold_id, undef, 'Hold group no longer has a target' );
2084
2085
    AddReturn( $item->barcode, $library_1->{branchcode} );
2086
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
2087
2081
    my @reserves_with_target_hold = C4::Reserves::_Findgroupreserve( $item->biblionumber, $item->id, 0, [] );
2088
    my @reserves_with_target_hold = C4::Reserves::_Findgroupreserve( $item->biblionumber, $item->id, 0, [] );
2082
2089
2083
    is(
2090
    is(
2084
- 

Return to bug 40529