From d2de8ed3cd763f6089bfb90975e9828becb1884d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 22 Jan 2021 11:24:58 +0100 Subject: [PATCH] Bug 27526: Remove ModItemFromMarc from additem Signed-off-by: Tomas Cohen Arazi --- C4/Biblio.pm | 2 +- cataloguing/additem.pl | 59 ++++++++++++------- .../prog/en/modules/cataloguing/additem.tt | 34 +++++++---- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ebebe415c85..cf79d1e4b31 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2086,7 +2086,7 @@ sub TransformHtmlToXml { my $xml = MARC::File::XML::header('UTF-8'); $xml .= "\n"; - $auth_type = C4::Context->preference('marcflavour') unless $auth_type; + $auth_type = C4::Context->preference('marcflavour') unless $auth_type; # FIXME auth_type must be removed MARC::File::XML->default_record_format($auth_type); # in UNIMARC, field 100 contains the encoding diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index faa5ab75bc5..b17a1a4c5b1 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -127,6 +127,7 @@ sub generate_subfield_form { $subfield_data{repeatable} = $subfieldlib->{repeatable}; $subfield_data{maxlength} = $subfieldlib->{maxlength}; $subfield_data{display_order} = $subfieldlib->{display_order}; + $subfield_data{kohafield} = $subfieldlib->{kohafield} || 'items.more_subfields_xml'; if ( ! defined( $value ) || $value eq '') { $value = $subfieldlib->{defaultvalue}; @@ -740,33 +741,49 @@ if ($op eq "additem") { #------------------------------------------------------------------------------- } elsif ($op eq "saveitem") { #------------------------------------------------------------------------------- - # rebuild - my @tags = $input->multi_param('tag'); - my @subfields = $input->multi_param('subfield'); - my @values = $input->multi_param('field_value'); - # build indicator hash. - my @ind_tag = $input->multi_param('ind_tag'); - my @indicator = $input->multi_param('indicator'); - # my $itemnumber = $input->param('itemnumber'); - my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'ITEM'); - my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8'); - # MARC::Record builded => now, record in DB - # warn "R: ".$record->as_formatted; + + my $itemnumber = $input->param('itemnumber'); + my $item = Koha::Items->find($itemnumber); + # FIXME Handle non existent item + my $olditemlost = $item->itemlost; + my @columns = Koha::Items->columns; + for my $c ( @columns ) { + if ( $c eq 'more_subfields_xml' ) { + my @more_subfields_xml = $input->multi_param("items.more_subfields_xml"); + my @unlinked_item_subfields; + for my $subfield ( @more_subfields_xml ) { + my $v = $input->param('items.more_subfields_xml_' . $subfield); + push @unlinked_item_subfields, $subfield, $v; + } + if ( @unlinked_item_subfields ) { + my $marc = MARC::Record->new(); + # use of tag 999 is arbitrary, and doesn't need to match the item tag + # used in the framework + $marc->append_fields(MARC::Field->new('999', ' ', ' ', @unlinked_item_subfields)); + $marc->encoding("UTF-8"); + $item->more_subfields_xml($marc->as_xml("USMARC")); + next; + } + $item->more_subfields_xml(undef); + } else { + my $v = $input->param("items.".$c); + next unless defined $v; + $item->$c($v); + } + } + # check that the barcode don't exist already - my $addedolditem = TransformMarcToKoha($itemtosave); - my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'}); - if ($exist_itemnumber && $exist_itemnumber != $itemnumber) { + if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) { + # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode push @errors,"barcode_not_unique"; } else { - my $item = Koha::Items->find($itemnumber ); - my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber); - $itemnumber = q{}; - my $olditemlost = $item->itemlost; - my $newitemlost = $newitem->{itemlost}; + my $newitemlost = $item->itemlost; if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) { - LostItem( $item->itemnumber, 'additem' ) + LostItem( $item->itemnumber, 'additem' ); } + $item->store; } + $nextop="additem"; } elsif ($op eq "delinkitem"){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index bfecf0016cb..666c38d275b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -156,6 +156,13 @@
    [% FOREACH ite IN item %] + + [% IF ite.kohafield == 'items.more_subfields_xml' %] + [% SET kohafield = 'items.more_subfields_xml_' _ ite.subfield %] + [% ELSE %] + [% SET kohafield = ite.kohafield %] + [% END %] +
  1. [% IF ( ite.mandatory ) %] @@ -165,12 +172,12 @@ [% SET mv = ite.marc_value %] [% IF ( mv.type == 'hidden' ) %] - + [% ELSIF ( mv.type == 'select' ) %] [% IF ( mv.readonly || ite.IS_RETURN_CLAIM ) %] - [% ELSE %] - [% END %] [% FOREACH aval IN mv.values %] [% IF aval == mv.default %] @@ -186,17 +193,17 @@ [% ELSIF ( mv.type == 'text_auth' ) %] [% IF mv.readonly %] - + [% ELSE %] - + [% SET dopop = "Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=\"${mv.authtypecode}\"&index=${mv.id}','${mv.id}')" %] ... [% END %] [% ELSIF ( mv.type == 'text_plugin' ) %] [% IF mv.readonly %] - + [% ELSE %] - + [% IF ( mv.nopopup ) %] ... [% ELSE %] @@ -206,18 +213,21 @@ [% END %] [% ELSIF ( mv.type == 'text' ) %] [% IF mv.readonly %] - + [% ELSE %] - + [% END %] [% ELSIF ( mv.type == 'textarea' ) %] [% IF mv.readonly %] - + [% ELSE %] - + [% END %] [% END %] + [% IF ite.kohafield == 'items.more_subfields_xml' %] + + [% END %] @@ -261,7 +271,7 @@ [% ELSE %] - + Cancel -- 2.20.1