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

(-)a/C4/Items.pm (-28 / +65 lines)
Lines 1863-1869 sub _koha_new_item { Link Here
1863
1863
1864
=head2 MoveItemFromBiblio
1864
=head2 MoveItemFromBiblio
1865
1865
1866
  MoveItemFromBiblio($itenumber, $frombiblio, $tobiblio);
1866
  MoveItemFromBiblio($itenumber, $frombiblio, $tobiblio, $bibliotoindex);
1867
1867
1868
Moves an item from a biblio to another
1868
Moves an item from a biblio to another
1869
1869
Lines 1879-1914 sub MoveItemFromBiblio { Link Here
1879
        FROM biblioitems
1879
        FROM biblioitems
1880
        WHERE biblionumber = ?
1880
        WHERE biblionumber = ?
1881
    |, undef, $tobiblio );
1881
    |, undef, $tobiblio );
1882
    my $return = $dbh->do(q|
1883
        UPDATE items
1884
        SET biblioitemnumber = ?,
1885
            biblionumber = ?
1886
        WHERE itemnumber = ?
1887
            AND biblionumber = ?
1888
    |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
1889
    if ($return == 1) {
1890
        ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
1891
        ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
1892
	    # Checking if the item we want to move is in an order 
1893
        require C4::Acquisition;
1894
        my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
1895
	    if ($order) {
1896
		    # Replacing the biblionumber within the order if necessary
1897
		    $order->{'biblionumber'} = $tobiblio;
1898
	        C4::Acquisition::ModOrder($order);
1899
	    }
1900
1882
1901
        # Update reserves, hold_fill_targets, tmp_holdsqueue and linktracker tables
1883
    if ( defined $_[3]) {
1902
        for my $table_name ( qw( reserves hold_fill_targets tmp_holdsqueue linktracker ) ) {
1884
        my $bibliotoindex = $_[3];
1903
            $dbh->do( qq|
1885
        if ($bibliotoindex eq "new") {
1904
                UPDATE $table_name
1886
            my $return = $dbh->do(q|
1905
                SET biblionumber = ?
1887
                UPDATE items
1888
                SET biblioitemnumber = ?,
1889
                    biblionumber = ?
1906
                WHERE itemnumber = ?
1890
                WHERE itemnumber = ?
1907
            |, undef, $tobiblio, $itemnumber );
1891
                    AND biblionumber = ?
1892
            |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
1893
            if ($return == 1) {
1894
                ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
1895
	              # Checking if the item we want to move is in an order 
1896
                require C4::Acquisition;
1897
                my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
1898
	              if ($order) {
1899
		                # Replacing the biblionumber within the order if necessary
1900
		                $order->{'biblionumber'} = $tobiblio;
1901
	                  C4::Acquisition::ModOrder($order);
1902
                }
1903
1904
                # Update reserves, hold_fill_targets, tmp_holdsqueue and linktracker tables
1905
                for my $table_name ( qw( reserves hold_fill_targets tmp_holdsqueue linktracker ) ) {
1906
                    $dbh->do( qq|
1907
                        UPDATE $table_name
1908
                        SET biblionumber = ?
1909
                        WHERE itemnumber = ?
1910
                    |, undef, $tobiblio, $itemnumber );
1911
                }
1912
                return $tobiblio;
1913
	          }
1914
        } elsif ($bibliotoindex eq "old") {
1915
            ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
1916
            return 1;
1908
        }
1917
        }
1909
        return $tobiblio;
1918
    } else {
1910
	}
1919
          my $return = $dbh->do(q|
1911
    return;
1920
             UPDATE items
1921
             SET biblioitemnumber = ?,
1922
                biblionumber = ?
1923
             WHERE itemnumber = ?
1924
                AND biblionumber = ?
1925
          |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
1926
          if ($return == 1) {
1927
              ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
1928
              ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
1929
              # Checking if the item we want to move is in an order 
1930
              require C4::Acquisition;
1931
              my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
1932
              if ($order) {
1933
                   # Replacing the biblionumber within the order if necessary
1934
                   $order->{'biblionumber'} = $tobiblio;
1935
                   C4::Acquisition::ModOrder($order);
1936
              }
1937
              # Update reserves, hold_fill_targets, tmp_holdsqueue and linktracker tables
1938
              for my $table_name ( qw( reserves hold_fill_targets tmp_holdsqueue linktracker ) ) {
1939
                   $dbh->do( qq|
1940
                        UPDATE $table_name
1941
                        SET biblionumber = ?
1942
                        WHERE itemnumber = ?
1943
                   |, undef, $tobiblio, $itemnumber );
1944
              }
1945
              return $tobiblio;
1946
          }
1947
          return;
1948
    }
1912
}
1949
}
1913
1950
1914
=head2 ItemSafeToDelete
1951
=head2 ItemSafeToDelete
(-)a/cataloguing/moveitem.pl (-20 / +30 lines)
Lines 65-71 $template->param(bibliotitle => $biblio->title); Link Here
65
$template->param(biblionumber => $biblionumber);
65
$template->param(biblionumber => $biblionumber);
66
66
67
# If we already have the barcode of the item to move and the biblionumber to move the item to
67
# If we already have the barcode of the item to move and the biblionumber to move the item to
68
if ($barcode && $biblionumber) { 
68
if ($barcode && $biblionumber) {
69
69
70
    my $itemnumber;
70
    my $itemnumber;
71
    my $item = Koha::Items->find({ barcode => $barcode });
71
    my $item = Koha::Items->find({ barcode => $barcode });
Lines 74-98 if ($barcode && $biblionumber) { Link Here
74
74
75
        $itemnumber = $item->itemnumber;
75
        $itemnumber = $item->itemnumber;
76
        my $frombiblionumber = $item->biblionumber;
76
        my $frombiblionumber = $item->biblionumber;
77
77
        my @bibliostoindex = ("new", "old");
78
	    my $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber); 
78
        my $moveresult;
79
	    if ($moveresult) { 
79
        foreach my $bibliotoindex (@bibliostoindex) {
80
		$template->param(success => 1);
80
            if ($bibliotoindex eq "new") {
81
	    } else {
81
                $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber, $bibliotoindex);
82
		$template->param(error => 1,
82
                if ($moveresult) {
83
				 errornonewitem => 1); 
83
                    $template->param(success => 1);
84
	    }
84
              } else {
85
85
                    $template->param(error => 1,
86
86
                        errornonewitem => 1);
87
	} else {
87
              }
88
	    $template->param(error => 1,
88
            } elsif ($bibliotoindex eq "old" && $moveresult) {
89
	                     errornoitem => 1);
89
                my $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber, $bibliotoindex);
90
	}
90
                if ($moveresult) {
91
    $template->param(
91
                    $template->param(success => 1);
92
			barcode => $barcode,  
92
                } else {
93
			itemnumber => $itemnumber,
93
                    $template->param(error => 1,
94
		    );
94
                      errornonewitem => 1);
95
95
                }
96
            }
97
        }
98
  } else {
99
      $template->param(error => 1,
100
                       errornoitem => 1);
101
  }
102
  $template->param(
103
     barcode => $barcode,
104
     itemnumber => $itemnumber,
105
  );
96
} else {
106
} else {
97
    $template->param(missingparameter => 1);
107
    $template->param(missingparameter => 1);
98
    if (!$barcode)      { $template->param(missingbarcode      => 1); }
108
    if (!$barcode)      { $template->param(missingbarcode      => 1); }
(-)a/t/db_dependent/Items/MoveItemFromBiblio.t (-5 / +6 lines)
Lines 16-22 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 => 8;
19
use Test::More tests => 9;
20
20
21
use C4::Items;
21
use C4::Items;
22
use C4::Reserves;
22
use C4::Reserves;
Lines 71-81 my $item_level_hold_to_move = $builder->build( Link Here
71
    }
71
    }
72
);
72
);
73
73
74
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
74
my $to_biblionumber_index_new_biblio = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber}, "new" );
75
my $to_biblionumber_index_old_biblio = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber}, "old" );
75
76
76
is( $to_biblionumber_after_moved, $to_biblio->{biblionumber}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
77
is( $to_biblionumber_index_new_biblio, $to_biblio->{biblionumber}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
78
is( $to_biblionumber_index_old_biblio, 1 , 'MoveItemFromBiblio should return the value 1 if the old biblio has been indexed if success' );
77
79
78
$to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
80
my $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumber}, $from_biblio->{biblionumber}, $to_biblio->{biblionumber} );
79
81
80
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
82
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
81
83
82
- 

Return to bug 20549