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

(-)a/C4/Reserves.pm (-2 / +3 lines)
Lines 2104-2110 sub MergeHolds { Link Here
2104
2104
2105
=head2 RevertWaitingStatus
2105
=head2 RevertWaitingStatus
2106
2106
2107
  $success = RevertWaitingStatus({ itemnumber => $itemnumber });
2107
  RevertWaitingStatus({ itemnumber => $itemnumber });
2108
2108
2109
  Reverts a 'waiting' hold back to a regular hold with a priority of 1.
2109
  Reverts a 'waiting' hold back to a regular hold with a priority of 1.
2110
2110
Lines 2159-2165 sub RevertWaitingStatus { Link Here
2159
      reserve_id = ?
2159
      reserve_id = ?
2160
    ";
2160
    ";
2161
    $sth = $dbh->prepare( $query );
2161
    $sth = $dbh->prepare( $query );
2162
    return $sth->execute( $reserve->{'reserve_id'} );
2162
    $sth->execute( $reserve->{'reserve_id'} );
2163
    _FixPriority( { biblionumber => $reserve->{biblionumber} } );
2163
}
2164
}
2164
2165
2165
=head2 GetReserveId
2166
=head2 GetReserveId
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-1 / +100 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use t::lib::Mocks;
6
use C4::Context;
7
use C4::Branch;
8
9
use Test::More tests => 3;
10
use MARC::Record;
11
use C4::Biblio;
12
use C4::Items;
13
use C4::Members;
14
use C4::Reserves;
15
16
my $dbh = C4::Context->dbh;
17
18
# Start transaction
19
$dbh->{AutoCommit} = 0;
20
$dbh->{RaiseError} = 1;
21
22
$dbh->do("DELETE FROM reserves");
23
$dbh->do("DELETE FROM old_reserves");
24
25
*C4::Context::userenv = \&Mock_userenv;
26
27
sub Mock_userenv {
28
    my $userenv = { flags => 1, id => '1', branch => 'CPL' };
29
    return $userenv;
30
}
31
32
my $borrowers_count = 3;
33
34
# Setup Test------------------------
35
# Helper biblio.
36
diag("Creating biblio instance for testing.");
37
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
38
39
# Helper item for that biblio.
40
diag("Creating item instance for testing.");
41
my $item_barcode = 'my_barcode';
42
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
43
    { homebranch => 'CPL', holdingbranch => 'CPL', barcode => $item_barcode },
44
    $bibnum );
45
46
# Create some borrowers
47
my @borrowernumbers;
48
foreach my $i ( 1 .. $borrowers_count ) {
49
    my $borrowernumber = AddMember(
50
        firstname    => 'my firstname',
51
        surname      => 'my surname ' . $i,
52
        categorycode => 'S',
53
        branchcode   => 'CPL',
54
    );
55
    push @borrowernumbers, $borrowernumber;
56
}
57
58
my $biblionumber = $bibnum;
59
60
my @branches = GetBranchesLoop();
61
my $branch   = $branches[0][0]{value};
62
63
# Create five item level holds
64
foreach my $borrowernumber (@borrowernumbers) {
65
    AddReserve(
66
        $branch,
67
        $borrowernumber,
68
        $biblionumber,
69
        my $constraint = 'a',
70
        my $bibitems   = q{},
71
        my $priority,
72
        my $resdate,
73
        my $expdate,
74
        my $notes = q{},
75
        $title,
76
        my $checkitem,
77
        my $found,
78
    );
79
}
80
81
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
82
C4::Circulation::AddIssue( GetMember( borrowernumber => $borrowernumbers[1] ),
83
    $item_barcode, my $datedue, my $cancelreserve = 'revert' );
84
85
my $priorities = $dbh->selectall_arrayref(
86
    "SELECT priority FROM reserves ORDER BY priority ASC");
87
ok( scalar @$priorities == 2,   'Only 2 holds remain in the reserves table' );
88
ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
89
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
90
91
# Helper method to set up a Biblio.
92
sub create_helper_biblio {
93
    my $bib   = MARC::Record->new();
94
    my $title = 'Silence in the library';
95
    $bib->append_fields(
96
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
97
        MARC::Field->new( '245', ' ', ' ', a => $title ),
98
    );
99
    return ( $bibnum, $title, $bibitemnum ) = AddBiblio( $bib, '' );
100
}

Return to bug 12086