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

(-)a/C4/Items.pm (-3 / +14 lines)
Lines 137-151 sub CartToShelf { Link Here
137
=head2 AddItemFromMarc
137
=head2 AddItemFromMarc
138
138
139
  my ($biblionumber, $biblioitemnumber, $itemnumber) 
139
  my ($biblionumber, $biblioitemnumber, $itemnumber) 
140
      = AddItemFromMarc($source_item_marc, $biblionumber);
140
      = AddItemFromMarc($source_item_marc, $biblionumber[, $params]);
141
141
142
Given a MARC::Record object containing an embedded item
142
Given a MARC::Record object containing an embedded item
143
record and a biblionumber, create a new item record.
143
record and a biblionumber, create a new item record.
144
144
145
The final optional parameter, C<$params>, expected to contain
146
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
147
there it prevents calling of ModZebra (and Elasticsearch update),
148
which takes most of the time in batch adds/deletes: ModZebra better
149
to be called later in C<additem.pl> after the whole loop.
150
151
$params:
152
    skip_modzebra_update => true / false
145
=cut
153
=cut
146
154
147
sub AddItemFromMarc {
155
sub AddItemFromMarc {
148
    my ( $source_item_marc, $biblionumber ) = @_;
156
    my $source_item_marc = shift;
157
    my $biblionumber     = shift;
158
    my $params           = @_ ? shift : {};
159
149
    my $dbh = C4::Context->dbh;
160
    my $dbh = C4::Context->dbh;
150
161
151
    # parse item hash from MARC
162
    # parse item hash from MARC
Lines 161-167 sub AddItemFromMarc { Link Here
161
    $item_values->{biblionumber} = $biblionumber;
172
    $item_values->{biblionumber} = $biblionumber;
162
    $item_values->{cn_source} = delete $item_values->{'items.cn_source'}; # Because of C4::Biblio::_disambiguate
173
    $item_values->{cn_source} = delete $item_values->{'items.cn_source'}; # Because of C4::Biblio::_disambiguate
163
    $item_values->{cn_sort}   = delete $item_values->{'items.cn_sort'};   # Because of C4::Biblio::_disambiguate
174
    $item_values->{cn_sort}   = delete $item_values->{'items.cn_sort'};   # Because of C4::Biblio::_disambiguate
164
    my $item = Koha::Item->new( $item_values )->store;
175
    my $item = Koha::Item->new( $item_values )->store({ skip_modzebra_update => $params->{skip_modzebra_update} });
165
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
176
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
166
}
177
}
167
178
(-)a/Koha/Item.pm (-7 / +13 lines)
Lines 61-67 Koha::Item - Koha Item object class Link Here
61
=cut
61
=cut
62
62
63
sub store {
63
sub store {
64
    my ($self, $params) = @_;
64
    my $self = shift;
65
    my $params = @_ ? shift : {};
65
66
66
    my $log_action = $params->{log_action} // 1;
67
    my $log_action = $params->{log_action} // 1;
67
68
Lines 99-105 sub store { Link Here
99
            $self->cn_sort($cn_sort);
100
            $self->cn_sort($cn_sort);
100
        }
101
        }
101
102
102
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
103
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
104
            unless $params->{skip_modzebra_update};
103
105
104
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
106
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
105
          if $log_action && C4::Context->preference("CataloguingLog");
107
          if $log_action && C4::Context->preference("CataloguingLog");
Lines 156-162 sub store { Link Here
156
            $self->permanent_location( $self->location );
158
            $self->permanent_location( $self->location );
157
        }
159
        }
158
160
159
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
161
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
162
            unless $params->{skip_modzebra_update};
160
163
161
        $self->_after_item_action_hooks({ action => 'modify' });
164
        $self->_after_item_action_hooks({ action => 'modify' });
162
165
Lines 176-187 sub store { Link Here
176
=cut
179
=cut
177
180
178
sub delete {
181
sub delete {
179
    my ( $self ) = @_;
182
    my $self = shift;
183
    my $params = @_ ? shift : {};
180
184
181
    # FIXME check the item has no current issues
185
    # FIXME check the item has no current issues
182
    # i.e. raise the appropriate exception
186
    # i.e. raise the appropriate exception
183
187
184
    C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
188
    C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
189
        unless $params->{skip_modzebra_update};
185
190
186
    $self->_after_item_action_hooks({ action => 'delete' });
191
    $self->_after_item_action_hooks({ action => 'delete' });
187
192
Lines 196-209 sub delete { Link Here
196
=cut
201
=cut
197
202
198
sub safe_delete {
203
sub safe_delete {
199
    my ($self) = @_;
204
    my $self = shift;
205
    my $params = @_ ? shift : {};
200
206
201
    my $safe_to_delete = $self->safe_to_delete;
207
    my $safe_to_delete = $self->safe_to_delete;
202
    return $safe_to_delete unless $safe_to_delete eq '1';
208
    return $safe_to_delete unless $safe_to_delete eq '1';
203
209
204
    $self->move_to_deleted;
210
    $self->move_to_deleted;
205
211
206
    return $self->delete;
212
    return $self->delete($params);
207
}
213
}
208
214
209
=head3 safe_to_delete
215
=head3 safe_to_delete
(-)a/cataloguing/additem.pl (-3 / +7 lines)
Lines 596-602 if ($op eq "additem") { Link Here
596
596
597
		# Adding the item
597
		# Adding the item
598
        if (!$exist_itemnumber) {
598
        if (!$exist_itemnumber) {
599
            my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
599
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) =
600
                AddItemFromMarc( $record, $biblionumber, { skip_modzebra_update => 1 } );
600
            set_item_default_location($oldbibitemnum);
601
            set_item_default_location($oldbibitemnum);
601
602
602
            # We count the item only if it was really added
603
            # We count the item only if it was really added
Lines 610-615 if ($op eq "additem") { Link Here
610
		# Preparing the next iteration
611
		# Preparing the next iteration
611
		$oldbarcode = $barcodevalue;
612
		$oldbarcode = $barcodevalue;
612
	    }
613
	    }
614
615
	    C4::Biblio::ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
616
613
	    undef($itemrecord);
617
	    undef($itemrecord);
614
	}
618
	}
615
    }	
619
    }	
Lines 682-691 if ($op eq "additem") { Link Here
682
#-------------------------------------------------------------------------------
686
#-------------------------------------------------------------------------------
683
    my $items = Koha::Items->search({ biblionumber => $biblionumber });
687
    my $items = Koha::Items->search({ biblionumber => $biblionumber });
684
    while ( my $item = $items->next ) {
688
    while ( my $item = $items->next ) {
685
        $error = $item->safe_delete;
689
        $error = $item->safe_delete({ skip_modzebra_update => 1 });
686
        next if $error eq '1'; # Means ok
690
        next if $error eq '1'; # Means ok
687
        push @errors,$error;
691
        push @errors,$error;
688
    }
692
    }
693
    C4::Biblio::ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
689
    if ( @errors ) {
694
    if ( @errors ) {
690
        $nextop="additem";
695
        $nextop="additem";
691
    } else {
696
    } else {
692
- 

Return to bug 24027