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

(-)a/C4/Items.pm (-55 / +3 lines)
Lines 160-225 sub AddItemFromMarc { Link Here
160
    my $localitemmarc = MARC::Record->new;
160
    my $localitemmarc = MARC::Record->new;
161
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
161
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
162
162
163
#RMME
164
    my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
165
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
166
    return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields );
167
168
    my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
163
    my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
164
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
165
    $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields);
169
    $item_values->{biblionumber} = $biblionumber;
166
    $item_values->{biblionumber} = $biblionumber;
170
    # FIXME RM my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
167
    my $item = Koha::Item->new( $item_values )->store;
171
    my $item = Koha::Item->new( $item_values ); # FIXME Handle $unlinked_item_subfields
172
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
168
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
173
}
169
}
174
170
175
=head2 AddItem
176
177
  my ($biblionumber, $biblioitemnumber, $itemnumber) 
178
      = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]);
179
180
Given a hash containing item column names as keys,
181
create a new Koha item record.
182
183
The first two optional parameters (C<$dbh> and C<$frameworkcode>)
184
do not need to be supplied for general use; they exist
185
simply to allow them to be picked up from AddItemFromMarc.
186
187
The final optional parameter, C<$unlinked_item_subfields>, contains
188
an arrayref containing subfields present in the original MARC
189
representation of the item (e.g., from the item editor) that are
190
not mapped to C<items> columns directly but should instead
191
be stored in C<items.more_subfields_xml> and included in 
192
the biblio items tag for display and indexing.
193
194
=cut
195
196
sub AddItem {
197
    my $item         = shift;
198
    my $biblionumber = shift;
199
200
    my $dbh           = @_ ? shift : C4::Context->dbh;
201
    my $unlinked_item_subfields;
202
    if (@_) {
203
        $unlinked_item_subfields = shift;
204
    }
205
206
    $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
207
208
    my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
209
    return if $error;
210
211
    $item->{'itemnumber'} = $itemnumber;
212
213
    C4::Biblio::ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" );
214
215
    logaction( "CATALOGUING", "ADD", $itemnumber, "item" )
216
      if C4::Context->preference("CataloguingLog");
217
218
    _after_item_action_hooks({ action => 'create', item_id => $itemnumber });
219
220
    return ( $item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber );
221
}
222
223
=head2 AddItemBatchFromMarc
171
=head2 AddItemBatchFromMarc
224
172
225
  ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, 
173
  ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, 
(-)a/Koha/Item.pm (+8 lines)
Lines 26-32 use Koha::Database; Link Here
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
27
27
28
use C4::Context;
28
use C4::Context;
29
use C4::Biblio qw( ModZebra ); # FIXME This is terrible, we should move the indexation code outside of C4::Biblio
29
use C4::ClassSource; # FIXME We would like to avoid that
30
use C4::ClassSource; # FIXME We would like to avoid that
31
use C4::Log qw( logaction );
30
32
31
use Koha::Checkouts;
33
use Koha::Checkouts;
32
use Koha::IssuingRules;
34
use Koha::IssuingRules;
Lines 87-92 sub store { Link Here
87
            my $cn_sort = GetClassSort($self->cn_source, $self->itemcallnumber, "");
89
            my $cn_sort = GetClassSort($self->cn_source, $self->itemcallnumber, "");
88
            $self->cn_sort($cn_sort);
90
            $self->cn_sort($cn_sort);
89
        }
91
        }
92
93
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
94
95
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
96
          if C4::Context->preference("CataloguingLog");
97
90
    }
98
    }
91
99
92
    unless ( $self->dateaccessioned ) {
100
    unless ( $self->dateaccessioned ) {
(-)a/t/lib/TestBuilder.pm (-6 / +4 lines)
Lines 181-196 sub build_sample_item { Link Here
181
    my $barcode = delete $args->{barcode}
181
    my $barcode = delete $args->{barcode}
182
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
182
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
183
183
184
    my ( undef, undef, $itemnumber ) = C4::Items::AddItem(
184
    return Koha::Item->new(
185
        {
185
        {
186
            biblionumber  => $biblionumber,
186
            homebranch    => $library,
187
            homebranch    => $library,
187
            holdingbranch => $library,
188
            holdingbranch => $library,
188
            barcode       => $barcode,
189
            barcode       => $barcode,
189
            %$args,
190
            %$args,
190
        },
191
        }
191
        $biblionumber
192
    )->store->get_from_storage;
192
    );
193
    return Koha::Items->find($itemnumber);
194
}
193
}
195
194
196
# ------------------------------------------------------------------------------
195
# ------------------------------------------------------------------------------
197
- 

Return to bug 23463