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/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 5122-5127 DROP TABLE IF EXISTS `hold_group_target_holds`; Link Here
5122
CREATE TABLE hold_group_target_holds (
5122
CREATE TABLE hold_group_target_holds (
5123
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5123
    `hold_group_id` int unsigned NOT NULL UNIQUE COMMENT 'foreign key, linking this to the hold_groups table',
5124
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5124
    `reserve_id` int(11) DEFAULT NULL UNIQUE COMMENT 'foreign key, linking this to the reserves table',
5125
    PRIMARY KEY (`hold_group_id`, `reserve_id`),
5125
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5126
    CONSTRAINT `hold_group_target_holds_ibfk_1` FOREIGN KEY (`hold_group_id`) REFERENCES `hold_groups` (`hold_group_id`) ON DELETE CASCADE,
5126
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5127
    CONSTRAINT `hold_group_target_holds_ibfk_2` FOREIGN KEY (`reserve_id`) REFERENCES `reserves` (`reserve_id`) ON DELETE CASCADE
5127
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5128
) 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