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

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

Return to bug 23463