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

(-)a/C4/Items.pm (-5 / +20 lines)
Lines 2254-2264 Returns undef if the move failed or the biblionumber of the destination record o Link Here
2254
sub MoveItemFromBiblio {
2254
sub MoveItemFromBiblio {
2255
    my ($itemnumber, $frombiblio, $tobiblio) = @_;
2255
    my ($itemnumber, $frombiblio, $tobiblio) = @_;
2256
    my $dbh = C4::Context->dbh;
2256
    my $dbh = C4::Context->dbh;
2257
    my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = ?");
2257
    my ( $tobiblioitem ) = $dbh->selectrow_array(q|
2258
    $sth->execute( $tobiblio );
2258
        SELECT biblioitemnumber
2259
    my ( $tobiblioitem ) = $sth->fetchrow();
2259
        FROM biblioitems
2260
    $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
2260
        WHERE biblionumber = ?
2261
    my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
2261
    |, undef, $tobiblio );
2262
    my $return = $dbh->do(q|
2263
        UPDATE items
2264
        SET biblioitemnumber = ?,
2265
            biblionumber = ?
2266
        WHERE itemnumber = ?
2267
            AND biblionumber = ?
2268
    |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
2262
    if ($return == 1) {
2269
    if ($return == 1) {
2263
        ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
2270
        ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
2264
        ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
2271
        ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
Lines 2270-2275 sub MoveItemFromBiblio { Link Here
2270
		    $order->{'biblionumber'} = $tobiblio;
2277
		    $order->{'biblionumber'} = $tobiblio;
2271
	        C4::Acquisition::ModOrder($order);
2278
	        C4::Acquisition::ModOrder($order);
2272
	    }
2279
	    }
2280
2281
        # Update holds
2282
        $dbh->do( q|
2283
            UPDATE reserves
2284
            SET biblionumber = ?
2285
            WHERE itemnumber = ?
2286
        |, undef, $tobiblio, $itemnumber );
2287
2273
        return $tobiblio;
2288
        return $tobiblio;
2274
	}
2289
	}
2275
    return;
2290
    return;
(-)a/t/db_dependent/Items/MoveItemFromBiblio.t (-2 / +26 lines)
Lines 16-24 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 5;
19
use Test::More tests => 8;
20
20
21
use C4::Items;
21
use C4::Items;
22
use C4::Reserves;
22
23
23
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
24
25
Lines 43-48 my $item3 = $builder->build( Link Here
43
    }
44
    }
44
);
45
);
45
46
47
my $bib_level_hold_not_to_move = $builder->build(
48
    {   source => 'Reserve',
49
        value  => { biblionumber => $from_biblio->{biblionumber}, },
50
    }
51
);
52
my $item_level_hold_not_to_move = $builder->build(
53
    {   source => 'Reserve',
54
        value  => { biblionumber => $from_biblio->{biblionumber}, itemnumber => $item1->{itemnumber} },
55
    }
56
);
57
my $item_level_hold_to_move = $builder->build(
58
    {   source => 'Reserve',
59
        value  => { biblionumber => $from_biblio->{biblionumber}, itemnumber => $item2->{itemnumber} },
60
    }
61
);
62
46
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
63
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
47
64
48
is( $to_biblionumber_after_moved, $to_biblio->{biblionumber}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
65
is( $to_biblionumber_after_moved, $to_biblio->{biblionumber}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
Lines 57-59 my $get_item2 = C4::Items::GetItem( $item2->{itemnumber} ); Link Here
57
is( $get_item2->{biblionumber}, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
74
is( $get_item2->{biblionumber}, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
58
my $get_item3 = C4::Items::GetItem( $item3->{itemnumber} );
75
my $get_item3 = C4::Items::GetItem( $item3->{itemnumber} );
59
is( $get_item3->{biblionumber}, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
76
is( $get_item3->{biblionumber}, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
60
- 
77
78
my $get_bib_level_hold    = C4::Reserves::GetReserve( $bib_level_hold_not_to_move->{reserve_id} );
79
my $get_item_level_hold_1 = C4::Reserves::GetReserve( $item_level_hold_not_to_move->{reserve_id} );
80
my $get_item_level_hold_2 = C4::Reserves::GetReserve( $item_level_hold_to_move->{reserve_id} );
81
82
is( $get_bib_level_hold->{biblionumber},    $from_biblio->{biblionumber}, 'MoveItemFromBiblio should not have moved the biblio-level hold' );
83
is( $get_item_level_hold_1->{biblionumber}, $from_biblio->{biblionumber}, 'MoveItemFromBiblio should not have moved the item-level hold placed on item 1' );
84
is( $get_item_level_hold_2->{biblionumber}, $to_biblio->{biblionumber},   'MoveItemFromBiblio should have moved the item-level hold placed on item 2' );

Return to bug 8723