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

(-)a/C4/Reserves.pm (+2 lines)
Lines 2204-2209 sub RevertWaitingStatus { Link Here
2204
2204
2205
    _FixPriority( { biblionumber => $hold->biblionumber } );
2205
    _FixPriority( { biblionumber => $hold->biblionumber } );
2206
2206
2207
    $hold->remove_as_hold_group_target();
2208
2207
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $hold->biblionumber ] } )
2209
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $hold->biblionumber ] } )
2208
        if C4::Context->preference('RealTimeHoldsQueue');
2210
        if C4::Context->preference('RealTimeHoldsQueue');
2209
2211
(-)a/Koha/Hold.pm (+23 lines)
Lines 219-224 sub set_as_hold_group_target { Link Here
219
    }
219
    }
220
}
220
}
221
221
222
=head3 remove_as_hold_group_target
223
224
$self->remove_as_hold_group_target;
225
226
Removes this hold as the target of its hold group if it is currently set as such,
227
and if the DisplayAddHoldGroups system preference is enabled.
228
229
=cut
230
231
sub remove_as_hold_group_target {
232
    my ($self) = @_;
233
234
    if (   $self->hold_group
235
        && $self->hold_group->target_hold_id eq $self->reserve_id
236
        && C4::Context->preference("DisplayAddHoldGroups") )
237
    {
238
        $self->_result->find_related(
239
            'hold_group_target_hold',
240
            { hold_group_id => $self->hold_group->hold_group_id, reserve_id => $self->reserve_id }
241
        )->delete();
242
    }
243
}
244
222
=head3 is_hold_group_target
245
=head3 is_hold_group_target
223
246
224
$self->is_hold_group_target;
247
$self->is_hold_group_target;
(-)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 5083-5088 DROP TABLE IF EXISTS `hold_group_target_holds`; Link Here
5083
CREATE TABLE hold_group_target_holds (
5083
CREATE TABLE hold_group_target_holds (
5084
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5084
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5085
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5085
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5086
    PRIMARY KEY (`hold_group_id`, `reserve_id`),
5086
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5087
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5087
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5088
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5088
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5089
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/t/db_dependent/Koha/Hold.t (-3 / +9 lines)
Lines 34-40 use Koha::DateUtils qw(dt_from_string); Link Here
34
use Koha::Holds;
34
use Koha::Holds;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::Old::Holds;
36
use Koha::Old::Holds;
37
use C4::Reserves    qw( AddReserve ModReserveAffect );
37
use C4::Reserves    qw( AddReserve ModReserveAffect RevertWaitingStatus);
38
use C4::Circulation qw( AddReturn );
38
use C4::Circulation qw( AddReturn );
39
39
40
my $schema  = Koha::Database->new->schema;
40
my $schema  = Koha::Database->new->schema;
Lines 1389-1395 subtest 'is_hold_group_target, cleanup_hold_group and set_as_hold_group_target t Link Here
1389
};
1389
};
1390
1390
1391
subtest '_Findgroupreserve in the context of hold groups' => sub {
1391
subtest '_Findgroupreserve in the context of hold groups' => sub {
1392
    plan tests => 17;
1392
    plan tests => 19;
1393
1393
1394
    $schema->storage->txn_begin;
1394
    $schema->storage->txn_begin;
1395
1395
Lines 1490-1495 subtest '_Findgroupreserve in the context of hold groups' => sub { Link Here
1490
1490
1491
    is( $hold->is_hold_group_target, 1, 'First hold is the hold group target' );
1491
    is( $hold->is_hold_group_target, 1, 'First hold is the hold group target' );
1492
1492
1493
    C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1494
    is( $hold->is_hold_group_target,       0,     'First hold is no longer the hold group target' );
1495
    is( $hold->hold_group->target_hold_id, undef, 'Hold group no longer has a target' );
1496
1497
    AddReturn( $item->barcode, $library_1->{branchcode} );
1498
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
1499
1493
    my @reserves_with_target_hold = C4::Reserves::_Findgroupreserve( $item->biblionumber, $item->id, 0, [] );
1500
    my @reserves_with_target_hold = C4::Reserves::_Findgroupreserve( $item->biblionumber, $item->id, 0, [] );
1494
1501
1495
    is(
1502
    is(
1496
- 

Return to bug 40529