Bug 27272: Remove GetItemsInfo, GetItemsLocationInfo and GetHostItemsInfo

With the different bug reports we removed the calls for those 3
subroutines. We can remove them now.

Test plan:
git grep their names and you should not find any occurrences in the code
base

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-06-03 08:39:39 +02:00 committed by Tomas Cohen Arazi
parent 3f90b7b43d
commit d32a205a69
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
3 changed files with 2 additions and 380 deletions

View File

@ -34,9 +34,6 @@ BEGIN {
ModItemTransfer
CheckItemPreSave
GetItemsForInventory
GetItemsInfo
GetItemsLocationInfo
GetHostItemsInfo
get_hostitemnumbers_of
GetMarcItem
CartToShelf
@ -669,262 +666,6 @@ sub GetItemsForInventory {
return (\@results, $iTotalRecords);
}
=head2 GetItemsInfo
@results = GetItemsInfo($biblionumber);
Returns information about items with the given biblionumber.
C<GetItemsInfo> returns a list of references-to-hash. Each element
contains a number of keys. Most of them are attributes from the
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
Koha database. Other keys include:
=over 2
=item C<$data-E<gt>{branchname}>
The name (not the code) of the branch to which the book belongs.
=item C<$data-E<gt>{datelastseen}>
This is simply C<items.datelastseen>, except that while the date is
stored in YYYY-MM-DD format in the database, here it is converted to
DD/MM/YYYY format. A NULL date is returned as C<//>.
=item C<$data-E<gt>{datedue}>
=item C<$data-E<gt>{class}>
This is the concatenation of C<biblioitems.classification>, the book's
Dewey code, and C<biblioitems.subclass>.
=item C<$data-E<gt>{ocount}>
I think this is the number of copies of the book available.
=item C<$data-E<gt>{order}>
If this is set, it is set to C<One Order>.
=back
=cut
sub GetItemsInfo {
my ( $biblionumber ) = @_;
my $dbh = C4::Context->dbh;
require C4::Languages;
my $language = C4::Languages::getlanguage();
my $query = "
SELECT items.*,
biblio.*,
biblioitems.volume,
biblioitems.number,
biblioitems.itemtype,
biblioitems.isbn,
biblioitems.issn,
biblioitems.publicationyear,
biblioitems.publishercode,
biblioitems.volumedate,
biblioitems.volumedesc,
biblioitems.lccn,
biblioitems.url,
items.notforloan as itemnotforloan,
issues.borrowernumber,
issues.date_due as datedue,
issues.onsite_checkout,
borrowers.cardnumber,
borrowers.surname,
borrowers.firstname,
borrowers.branchcode as bcode,
serial.serialseq,
serial.publisheddate,
itemtypes.description,
COALESCE( localization.translation, itemtypes.description ) AS translated_description,
itemtypes.notforloan as notforloan_per_itemtype,
holding.branchurl,
holding.branchcode,
holding.branchname,
holding.opac_info as holding_branch_opac_info,
home.opac_info as home_branch_opac_info,
IF(tmp_holdsqueue.itemnumber,1,0) AS has_pending_hold
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
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 tmp_holdsqueue USING (itemnumber)
LEFT JOIN localization ON itemtypes.itemtype = localization.code
AND localization.entity = 'itemtypes'
AND localization.lang = ?
|;
$query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
my $sth = $dbh->prepare($query);
$sth->execute($language, $biblionumber);
my $i = 0;
my @results;
my $serial;
my $userenv = C4::Context->userenv;
my $want_not_same_branch = C4::Context->preference("IndependentBranches") && !C4::Context->IsSuperLibrarian();
while ( my $data = $sth->fetchrow_hashref ) {
if ( $data->{borrowernumber} && $want_not_same_branch) {
$data->{'NOTSAMEBRANCH'} = $data->{'bcode'} ne $userenv->{branch};
}
$serial ||= $data->{'serial'};
my $descriptions;
# get notforloan complete status if applicable
$descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} });
$data->{notforloanvalue} = $descriptions->{lib} // '';
$data->{notforloanvalueopac} = $descriptions->{opac_description} // '';
# get restricted status and description if applicable
$descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} });
$data->{restrictedvalue} = $descriptions->{lib} // '';
$data->{restrictedvalueopac} = $descriptions->{opac_description} // '';
# my stack procedures
$descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
$data->{stack} = $descriptions->{lib} // '';
# Find the last 3 people who borrowed this item.
my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
WHERE itemnumber = ?
AND old_issues.borrowernumber = borrowers.borrowernumber
ORDER BY returndate DESC
LIMIT 3");
$sth2->execute($data->{'itemnumber'});
my $ii = 0;
while (my $data2 = $sth2->fetchrow_hashref()) {
$data->{"timestamp$ii"} = $data2->{'timestamp'} if $data2->{'timestamp'};
$data->{"card$ii"} = $data2->{'cardnumber'} if $data2->{'cardnumber'};
$data->{"borrower$ii"} = $data2->{'borrowernumber'} if $data2->{'borrowernumber'};
$ii++;
}
$results[$i] = $data;
$i++;
}
return $serial
? sort { ($b->{'publisheddate'} || $b->{'enumchron'} || "") cmp ($a->{'publisheddate'} || $a->{'enumchron'} || "") } @results
: @results;
}
=head2 GetItemsLocationInfo
my @itemlocinfo = GetItemsLocationInfo($biblionumber);
Returns the branch names, shelving location and itemcallnumber for each item attached to the biblio in question
C<GetItemsInfo> returns a list of references-to-hash. Data returned:
=over 2
=item C<$data-E<gt>{homebranch}>
Branch Name of the item's homebranch
=item C<$data-E<gt>{holdingbranch}>
Branch Name of the item's holdingbranch
=item C<$data-E<gt>{location}>
Item's shelving location code
=item C<$data-E<gt>{location_intranet}>
The intranet description for the Shelving Location as set in authorised_values 'LOC'
=item C<$data-E<gt>{location_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<gt>{itemcallnumber}>
Item's itemcallnumber
=item C<$data-E<gt>{cn_sort}>
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 = ?
ORDER BY cn_sort ASC";
my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
while ( my $data = $sth->fetchrow_hashref ) {
my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $data->{location} });
$av = $av->count ? $av->next : undef;
$data->{location_intranet} = $av ? $av->lib : '';
$data->{location_opac} = $av ? $av->opac_description : '';
push @results, $data;
}
return @results;
}
=head2 GetHostItemsInfo
$hostiteminfo = GetHostItemsInfo($hostfield);
Returns the iteminfo for items linked to records via a host field
=cut
sub GetHostItemsInfo {
my ($record) = @_;
my @returnitemsInfo;
if( !C4::Context->preference('EasyAnalyticalRecords') ) {
return @returnitemsInfo;
}
my @fields;
if( C4::Context->preference('marcflavour') eq 'MARC21' ) {
@fields = $record->field('773');
} elsif( C4::Context->preference('marcflavour') eq 'UNIMARC') {
@fields = $record->field('461');
}
foreach my $hostfield ( @fields ) {
my $hostbiblionumber = $hostfield->subfield("0");
my $linkeditemnumber = $hostfield->subfield("9");
my @hostitemInfos = GetItemsInfo($hostbiblionumber);
foreach my $hostitemInfo (@hostitemInfos) {
if( $hostitemInfo->{itemnumber} eq $linkeditemnumber ) {
push @returnitemsInfo, $hostitemInfo;
last;
}
}
}
return @returnitemsInfo;
}
=head2 get_hostitemnumbers_of
my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use Data::Dumper;
use MARC::Record;
use C4::Items qw( ModItemTransfer GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc );
use C4::Items qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc );
use C4::Biblio qw( GetMarcFromKohaField AddBiblio );
use C4::Circulation qw( AddIssue );
use Koha::Items;
@ -34,7 +34,7 @@ use Koha::AuthorisedValues;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Test::More tests => 12;
use Test::More tests => 11;
use Test::Warn;
@ -190,84 +190,6 @@ subtest 'ModItemTransfer tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'GetItemsInfo tests' => sub {
plan tests => 9;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $library1 = $builder->build({
source => 'Branch',
});
my $library2 = $builder->build({
source => 'Branch',
});
my $itemtype = $builder->build({
source => 'Itemtype',
});
Koha::AuthorisedValues->delete;
my $av1 = Koha::AuthorisedValue->new(
{
category => 'RESTRICTED',
authorised_value => '1',
lib => 'Restricted Access',
lib_opac => 'Restricted Access OPAC',
}
)->store();
# Add a biblio
my $biblio = $builder->build_sample_biblio();
# Add an item
my $itemnumber = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
homebranch => $library1->{branchcode},
holdingbranch => $library2->{branchcode},
itype => $itemtype->{itemtype},
restricted => 1,
}
)->itemnumber;
my $library = Koha::Libraries->find( $library1->{branchcode} );
$library->opac_info("homebranch OPAC info");
$library->store;
$library = Koha::Libraries->find( $library2->{branchcode} );
$library->opac_info("holdingbranch OPAC info");
$library->store;
my @results = GetItemsInfo( $biblio->biblionumber );
ok( @results, 'GetItemsInfo returns results');
is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info",
'GetItemsInfo returns the correct home branch OPAC info notice' );
is( $results[0]->{ holding_branch_opac_info }, "holdingbranch OPAC info",
'GetItemsInfo returns the correct holding branch OPAC info notice' );
is( exists( $results[0]->{ onsite_checkout } ), 1,
'GetItemsInfo returns a onsite_checkout key' );
is( $results[0]->{ restricted }, 1,
'GetItemsInfo returns a restricted value code' );
is( $results[0]->{ restrictedvalue }, "Restricted Access",
'GetItemsInfo returns a restricted value description (staff)' );
is( $results[0]->{ restrictedvalueopac }, "Restricted Access OPAC",
'GetItemsInfo returns a restricted value description (OPAC)' );
#place item into holds queue
my $dbh = C4::Context->dbh;
@results = GetItemsInfo( $biblio->biblionumber );
is( $results[0]->{ has_pending_hold }, "0",
'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
$dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $biblio->biblionumber, $itemnumber);
@results = GetItemsInfo( $biblio->biblionumber );
is( $results[0]->{ has_pending_hold }, "1",
'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
$schema->storage->txn_rollback;
};
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
plan tests => 4;

View File

@ -1,41 +0,0 @@
use Modern::Perl;
use Test::More tests => 1;
use t::lib::Mocks;
use t::lib::TestBuilder;
use C4::Items qw( GetHostItemsInfo );
use Koha::Database;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
subtest 'GetHostItemsInfo' => sub {
plan tests => 3;
my $builder = t::lib::TestBuilder->new;
my $bib1 = $builder->build_sample_biblio;
my $itm1 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
my $itm2 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
my $marc = MARC::Record->new;
$marc->append_fields(
MARC::Field->new( '461', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm2->itemnumber ),
);
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 0);
my @a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 0, 'GetHostItemsInfo returns empty list when pref is disabled' );
t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 1);
@a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 2, 'GetHostItemsInfo returns two items for MARC21' );
t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC');
@a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 1, 'GetHostItemsInfo returns one item for UNIMARC' );
};
$schema->storage->txn_rollback;