From 7485c2efef492568f58f6e0fc3efcd99310c6ddf Mon Sep 17 00:00:00 2001 From: Benjamin Rokseth Date: Fri, 13 Apr 2018 08:36:06 +0200 Subject: [PATCH] Bug 20271: fix whitespace issues in C4::Items Signed-off-by: Brendan A Gallagher Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec --- C4/Items.pm | 267 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 133 insertions(+), 134 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index c018e7d..c1f0a6f 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -50,7 +50,7 @@ use vars qw(@ISA @EXPORT); BEGIN { - require Exporter; + require Exporter; @ISA = qw( Exporter ); # function exports @@ -60,33 +60,33 @@ BEGIN { AddItem AddItemBatchFromMarc ModItemFromMarc - Item2Marc + Item2Marc ModItem ModDateLastSeen ModItemTransfer DelItem - + CheckItemPreSave - + GetItemsForInventory GetItemsByBiblioitemnumber GetItemsInfo - GetItemsLocationInfo - GetHostItemsInfo + GetItemsLocationInfo + GetHostItemsInfo GetItemnumbersForBiblio - get_hostitemnumbers_of + get_hostitemnumbers_of GetItemnumberFromBarcode GetBarcodeFromItemnumber GetHiddenItemnumbers ItemSafeToDelete DelItemCheck - MoveItemFromBiblio - GetLatestAcquisitions + MoveItemFromBiblio + GetLatestAcquisitions CartToShelf ShelfToCart - GetAnalyticsCount + GetAnalyticsCount SearchItemsByField SearchItems @@ -102,7 +102,7 @@ C4::Items - item management functions =head1 DESCRIPTION -This module contains an API for manipulating item +This module contains an API for manipulating item records in Koha, and is used by cataloguing, circulation, acquisitions, and serials management. @@ -116,7 +116,7 @@ modification transaction must keep the items table and the MARC XML in sync at all times. Consequently, all code that creates, modifies, or deletes -item records B use an appropriate function from +item records B use an appropriate function from C. If no existing function is suitable, it is better to add one to C than to use add one-off SQL statements to add or modify items. @@ -222,7 +222,7 @@ sub ShelfToCart { =head2 AddItemFromMarc - my ($biblionumber, $biblioitemnumber, $itemnumber) + my ($biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($source_item_marc, $biblionumber); Given a MARC::Record object containing an embedded item @@ -237,9 +237,9 @@ sub AddItemFromMarc { # parse item hash from MARC my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); my ($itemtag,$itemsubfield)=C4::Biblio::GetMarcFromKohaField("items.itemnumber",$frameworkcode); - - my $localitemmarc=MARC::Record->new; - $localitemmarc->append_fields($source_item_marc->field($itemtag)); + + my $localitemmarc=MARC::Record->new; + $localitemmarc->append_fields($source_item_marc->field($itemtag)); my $item = &TransformMarcToKoha( $localitemmarc, $frameworkcode ,'items'); my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode); return AddItem($item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields); @@ -247,7 +247,7 @@ sub AddItemFromMarc { =head2 AddItem - my ($biblionumber, $biblioitemnumber, $itemnumber) + my ($biblionumber, $biblioitemnumber, $itemnumber) = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]); Given a hash containing item column names as keys, @@ -261,7 +261,7 @@ The final optional parameter, C<$unlinked_item_subfields>, contains an arrayref containing subfields present in the original MARC representation of the item (e.g., from the item editor) that are not mapped to C columns directly but should instead -be stored in C and included in +be stored in C and included in the biblio items tag for display and indexing. =cut @@ -309,7 +309,7 @@ sub AddItem { =head2 AddItemBatchFromMarc - ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, + ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, $biblionumber, $biblioitemnumber, $frameworkcode); Efficiently create item records from a MARC biblio record with @@ -374,7 +374,7 @@ sub AddItemBatchFromMarc { # and there is no TransformMarcFieldToKoha my $temp_item_marc = MARC::Record->new(); $temp_item_marc->append_fields($item_field); - + # add biblionumber and biblioitemnumber my $item = TransformMarcToKoha( $temp_item_marc, $frameworkcode, 'items' ); my $unlinked_item_subfields = _get_unlinked_item_subfields($temp_item_marc, $frameworkcode); @@ -397,7 +397,7 @@ sub AddItemBatchFromMarc { push @itemnumbers, $itemnumber; # FIXME not checking error $item->{'itemnumber'} = $itemnumber; - logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); + logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields); $item_field->replace_with($new_item_marc->field($itemtag)); @@ -420,7 +420,7 @@ sub AddItemBatchFromMarc { This function updates an item record based on a supplied C object containing an embedded item field. -This API is meant for the use of C; for +This API is meant for the use of C; for other purposes, C should be used. This function uses the hash %default_values_for_mod_from_marc, @@ -539,11 +539,11 @@ C<$unlinked_item_subfields> contains an arrayref containing subfields present in the original MARC representation of the item (e.g., from the item editor) that are not mapped to C columns directly but should instead -be stored in C and included in +be stored in C and included in the biblio items tag for display and indexing. If one of the changed columns is used to calculate -the derived value of a column such as C, +the derived value of a column such as C, this routine will perform the necessary calculation and set the value. @@ -771,7 +771,7 @@ sub CheckItemPreSave { =head1 EXPORTED SPECIAL ACCESSOR FUNCTIONS -The following functions provide various ways of +The following functions provide various ways of getting an item record, a set of item records, or lists of authorized values for certain item fields. @@ -948,9 +948,9 @@ sub GetItemsByBiblioitemnumber { my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ? AND items.deleted_at IS NULL") || die $dbh->errstr; # Get all items attached to a biblioitem my $i = 0; - my @results; + my @results; $sth->execute($bibitem) || die $sth->errstr; - while ( my $data = $sth->fetchrow_hashref ) { + while ( my $data = $sth->fetchrow_hashref ) { # Foreach item, get circulation information my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers WHERE itemnumber = ? @@ -965,9 +965,9 @@ sub GetItemsByBiblioitemnumber { } else { # set date_due to blank, so in the template we check itemlost, and withdrawn - $data->{'date_due'} = ''; - } # else - # Find the last 3 people who borrowed this item. + $data->{'date_due'} = ''; + } # else + # Find the last 3 people who borrowed this item. my $query2 = "SELECT * FROM old_issues, borrowers WHERE itemnumber = ? AND old_issues.borrowernumber = borrowers.borrowernumber ORDER BY returndate desc,timestamp desc LIMIT 3"; @@ -981,8 +981,8 @@ sub GetItemsByBiblioitemnumber { $i2++; } push(@results,$data); - } - return (\@results); + } + return (\@results); } =head2 GetItemsInfo @@ -1066,21 +1066,21 @@ sub GetItemsInfo { home.opac_info as home_branch_opac_info "; $query .= " - FROM items - LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode - LEFT JOIN branches AS home ON items.homebranch=home.branchcode - LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber AND biblio.deleted_at IS NULL - LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber - LEFT JOIN issues USING (itemnumber) - LEFT JOIN borrowers USING (borrowernumber) - LEFT JOIN serialitems USING (itemnumber) - LEFT JOIN serial USING (serialid) - LEFT JOIN itemtypes ON itemtypes.itemtype = " + FROM items + LEFT JOIN branches AS holding ON items.holdingbranch = holding.branchcode + LEFT JOIN branches AS home ON items.homebranch=home.branchcode + LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber AND biblio.deleted_at IS NULL + LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber + LEFT JOIN issues USING (itemnumber) + LEFT JOIN borrowers USING (borrowernumber) + LEFT JOIN serialitems USING (itemnumber) + LEFT JOIN serial USING (serialid) + LEFT JOIN itemtypes ON itemtypes.itemtype = " . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'); $query .= q| - LEFT JOIN localization ON itemtypes.itemtype = localization.code - AND localization.entity = 'itemtypes' - AND localization.lang = ? + LEFT JOIN localization ON itemtypes.itemtype = localization.code + AND localization.entity = 'itemtypes' + AND localization.lang = ? |; $query .= " WHERE items.biblionumber = ? AND items.deleted_at IS NULL ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; @@ -1166,7 +1166,7 @@ The intranet description for the Shelving Location as set in authorised_values ' =item C<$data-E{location_opac}> -The OPAC description for the Shelving Location as set in authorised_values 'LOC'. Falls back to intranet description if no OPAC +The OPAC description for the Shelving Location as set in authorised_values 'LOC'. Falls back to intranet description if no OPAC description is set. =item C<$data-E{itemcallnumber}> @@ -1178,21 +1178,21 @@ Item's itemcallnumber Item's call number normalized for sorting =back - + =cut sub GetItemsLocationInfo { my $biblionumber = shift; my @results; - my $dbh = C4::Context->dbh; - my $query = "SELECT a.branchname as homebranch, b.branchname as holdingbranch, - location, itemcallnumber, cn_sort - FROM items, branches as a, branches as b - WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode - AND biblionumber = ? AND deleted_at IS NULL - ORDER BY cn_sort ASC"; - my $sth = $dbh->prepare($query); + my $dbh = C4::Context->dbh; + my $query = "SELECT a.branchname as homebranch, b.branchname as holdingbranch, + location, itemcallnumber, cn_sort + FROM items, branches as a, branches as b + WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode + AND biblionumber = ? AND deleted_at IS NULL + ORDER BY cn_sort ASC"; + my $sth = $dbh->prepare($query); $sth->execute($biblionumber); while ( my $data = $sth->fetchrow_hashref ) { @@ -1200,9 +1200,9 @@ sub GetItemsLocationInfo { $av = $av->count ? $av->next : undef; $data->{location_intranet} = $av ? $av->lib : ''; $data->{location_opac} = $av ? $av->opac_description : ''; - push @results, $data; - } - return @results; + push @results, $data; + } + return @results; } =head2 GetHostItemsInfo @@ -1244,53 +1244,52 @@ sub GetHostItemsInfo { =head2 GetLastAcquisitions - my $lastacq = GetLastAcquisitions({'branches' => ('branch1','branch2'), + my $lastacq = GetLastAcquisitions({'branches' => ('branch1','branch2'), 'itemtypes' => ('BK','BD')}, 10); =cut sub GetLastAcquisitions { - my ($data,$max) = @_; - - my $itemtype = C4::Context->preference('item-level_itypes') ? 'itype' : 'itemtype'; - - my $number_of_branches = @{$data->{branches}}; - my $number_of_itemtypes = @{$data->{itemtypes}}; - - - my @where = ('WHERE (items.deleted_at IS NULL AND biblio.deleted_at IS NULL AND biblioitems.deleted_at IS NULL) '); - $number_of_branches and push @where - , 'AND holdingbranch IN (' - , join(',', ('?') x $number_of_branches ) - , ')' - ; - - $number_of_itemtypes and push @where - , "AND $itemtype IN (" - , join(',', ('?') x $number_of_itemtypes ) - , ')' - ; - - my $query = "SELECT biblio.biblionumber as biblionumber, title, dateaccessioned - FROM items RIGHT JOIN biblio ON (items.biblionumber=biblio.biblionumber) - RIGHT JOIN biblioitems ON (items.biblioitemnumber=biblioitems.biblioitemnumber) - @where - GROUP BY biblio.biblionumber - ORDER BY dateaccessioned DESC LIMIT $max"; - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare($query); - + my ($data,$max) = @_; + + my $itemtype = C4::Context->preference('item-level_itypes') ? 'itype' : 'itemtype'; + + my $number_of_branches = @{$data->{branches}}; + my $number_of_itemtypes = @{$data->{itemtypes}}; + + my @where = ('WHERE (items.deleted_at IS NULL AND biblio.deleted_at IS NULL AND biblioitems.deleted_at IS NULL)'); + $number_of_branches and push @where + , 'AND holdingbranch IN (' + , join(',', ('?') x $number_of_branches ) + , ')' + ; + + $number_of_itemtypes and push @where + , "AND $itemtype IN (" + , join(',', ('?') x $number_of_itemtypes ) + , ')' + ; + + my $query = "SELECT biblio.biblionumber as biblionumber, title, dateaccessioned + FROM items RIGHT JOIN biblio ON (items.biblionumber=biblio.biblionumber) + RIGHT JOIN biblioitems ON (items.biblioitemnumber=biblioitems.biblioitemnumber) + @where + GROUP BY biblio.biblionumber + ORDER BY dateaccessioned DESC LIMIT $max"; + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute((@{$data->{branches}}, @{$data->{itemtypes}})); - - my @results; - while( my $row = $sth->fetchrow_hashref){ - push @results, {date => $row->{dateaccessioned} - , biblionumber => $row->{biblionumber} - , title => $row->{title}}; - } - - return @results; + + my @results; + while( my $row = $sth->fetchrow_hashref){ + push @results, {date => $row->{dateaccessioned} + , biblionumber => $row->{biblionumber} + , title => $row->{title}}; + } + + return @results; } =head2 GetItemnumbersForBiblio @@ -1493,16 +1492,16 @@ sub GetMarcItem { # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work. # Also, don't emit a subfield if the underlying field is blank. - + return Item2Marc($itemrecord,$biblionumber); } sub Item2Marc { - my ($itemrecord,$biblionumber)=@_; - my $mungeditem = { - map { - defined($itemrecord->{$_}) && $itemrecord->{$_} ne '' ? ("items.$_" => $itemrecord->{$_}) : () - } keys %{ $itemrecord } + my ($itemrecord,$biblionumber)=@_; + my $mungeditem = { + map { + defined($itemrecord->{$_}) && $itemrecord->{$_} ne '' ? ("items.$_" => $itemrecord->{$_}) : () + } keys %{ $itemrecord } }; my $framework = C4::Biblio::GetFrameworkCode( $biblionumber ); my $itemmarc = C4::Biblio::TransformKohaToMarc( @@ -1514,11 +1513,11 @@ sub Item2Marc { my $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($mungeditem->{'items.more_subfields_xml'}); if (defined $unlinked_item_subfields and $#$unlinked_item_subfields > -1) { - foreach my $field ($itemmarc->field($itemtag)){ + foreach my $field ($itemmarc->field($itemtag)){ $field->add_subfields(@$unlinked_item_subfields); } } - return $itemmarc; + return $itemmarc; } =head1 PRIVATE FUNCTIONS AND VARIABLES @@ -1554,7 +1553,7 @@ my %derived_columns = ( } ); -=head2 _set_derived_columns_for_add +=head2 _set_derived_columns_for_add _set_derived_column_for_add($item); @@ -1578,7 +1577,7 @@ sub _set_derived_columns_for_add { } } -=head2 _set_derived_columns_for_mod +=head2 _set_derived_columns_for_mod _set_derived_column_for_mod($item); @@ -1681,12 +1680,12 @@ row specified by C<$itemnumber>. sub _get_single_item_column { my $column = shift; my $itemnumber = shift; - + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT $column FROM items WHERE itemnumber = ?"); $sth->execute($itemnumber); my ($value) = $sth->fetchrow(); - return $value; + return $value; } =head2 _calc_items_cn_sort @@ -1704,7 +1703,7 @@ sub _calc_items_cn_sort { $item->{'items.cn_sort'} = GetClassSort($source_values->{'items.cn_source'}, $source_values->{'itemcallnumber'}, ""); } -=head2 _set_defaults_for_add +=head2 _set_defaults_for_add _set_defaults_for_add($item_hash); @@ -1715,7 +1714,7 @@ columns: =over 2 -=item * +=item * C @@ -1755,7 +1754,7 @@ Perform the actual insert into the C table. sub _koha_new_item { my ( $item, $barcode ) = @_; - my $dbh=C4::Context->dbh; + my $dbh=C4::Context->dbh; my $error; $item->{permanent_location} //= $item->{location}; _mod_item_dates( $item ); @@ -1886,14 +1885,14 @@ sub MoveItemFromBiblio { if ($return == 1) { ModZebra( $tobiblio, "specialUpdate", "biblioserver" ); ModZebra( $frombiblio, "specialUpdate", "biblioserver" ); - # Checking if the item we want to move is in an order + # Checking if the item we want to move is in an order require C4::Acquisition; my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber); - if ($order) { - # Replacing the biblionumber within the order if necessary - $order->{'biblionumber'} = $tobiblio; - C4::Acquisition::ModOrder($order); - } + if ($order) { + # Replacing the biblionumber within the order if necessary + $order->{'biblionumber'} = $tobiblio; + C4::Acquisition::ModOrder($order); + } # Update reserves, hold_fill_targets, tmp_holdsqueue and linktracker tables for my $table_name ( qw( reserves hold_fill_targets tmp_holdsqueue linktracker ) ) { @@ -1904,7 +1903,7 @@ sub MoveItemFromBiblio { |, undef, $tobiblio, $itemnumber ); } return $tobiblio; - } + } return; } @@ -2017,7 +2016,7 @@ routine accepts a hashref specifying the columns to update. sub _koha_modify_item { my ( $item ) = @_; - my $dbh=C4::Context->dbh; + my $dbh=C4::Context->dbh; my $error; my $query = "UPDATE items SET "; @@ -2108,12 +2107,12 @@ sub _marc_from_item_hash { if (@_) { $unlinked_item_subfields = shift; } - + # Tack on 'items.' prefix to column names so lookup from MARC frameworks will work # Also, don't emit a subfield if the underlying field is blank. - my $mungeditem = { map { (defined($item->{$_}) and $item->{$_} ne '') ? - (/^items\./ ? ($_ => $item->{$_}) : ("items.$_" => $item->{$_})) - : () } keys %{ $item } }; + my $mungeditem = { map { (defined($item->{$_}) and $item->{$_} ne '') ? + (/^items\./ ? ($_ => $item->{$_}) : ("items.$_" => $item->{$_})) + : () } keys %{ $item } }; my $item_marc = MARC::Record->new(); foreach my $item_field ( keys %{$mungeditem} ) { @@ -2157,7 +2156,7 @@ sub _repack_item_errors { $repacked_error->{'error_code'} = $error_code; $repacked_error->{'error_information'} = $error_ref->{$error_code}; push @repacked_errors, $repacked_error; - } + } return @repacked_errors; } @@ -2180,7 +2179,7 @@ sub _get_unlinked_item_subfields { my @fields = $original_item_marc->fields(); if ($#fields > -1) { my $field = $fields[0]; - my $tag = $field->tag(); + my $tag = $field->tag(); foreach my $subfield ($field->subfields()) { if (defined $subfield->[1] and $subfield->[1] ne '' and @@ -2207,7 +2206,7 @@ sub _get_unlinked_subfields_xml { # 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"); + $marc->encoding("UTF-8"); $xml = $marc->as_xml("USMARC"); } @@ -2239,7 +2238,7 @@ sub _parse_unlinked_item_subfields_from_xml { $count= &GetAnalyticsCount($itemnumber) -counts Usage of itemnumber in Analytical bibliorecords. +counts Usage of itemnumber in Analytical bibliorecords. =cut @@ -2443,10 +2442,10 @@ sub SearchItems { my $query = q{ SELECT SQL_CALC_FOUND_ROWS items.* FROM items - LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber - LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber - LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber - WHERE items.deleted_at IS NULL + LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber + LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber + LEFT JOIN biblio_metadata ON biblio_metadata.biblionumber = biblio.biblionumber + WHERE items.deleted_at IS NULL }; if (defined $where_str and $where_str ne '') { $query .= qq{ AND $where_str }; -- 2.1.4