Bugzilla – Attachment 138832 Details for
Bug 27272
Move C4::Items::GetItemsInfo to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27272: Remove GetItemsInfo, GetItemsLocationInfo and GetHostItemsInfo
Bug-27272-Remove-GetItemsInfo-GetItemsLocationInfo.patch (text/plain), 16.02 KB, created by
Jonathan Druart
on 2022-08-08 14:55:17 UTC
(
hide
)
Description:
Bug 27272: Remove GetItemsInfo, GetItemsLocationInfo and GetHostItemsInfo
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-08-08 14:55:17 UTC
Size:
16.02 KB
patch
obsolete
>From 3fb3cada97949bcd9fa3ed096e1e79fba8383f13 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 3 Jun 2022 08:39:39 +0200 >Subject: [PATCH] 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 >--- > C4/Items.pm | 259 ------------------------ > t/db_dependent/Items.t | 82 +------- > t/db_dependent/Items/GetHostItemsInfo.t | 41 ---- > 3 files changed, 2 insertions(+), 380 deletions(-) > delete mode 100755 t/db_dependent/Items/GetHostItemsInfo.t > >diff --git a/C4/Items.pm b/C4/Items.pm >index 443242be5d9..24289c67541 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -34,9 +34,6 @@ BEGIN { > ModItemTransfer > CheckItemPreSave > GetItemsForInventory >- GetItemsInfo >- GetItemsLocationInfo >- GetHostItemsInfo > get_hostitemnumbers_of > GetMarcItem > CartToShelf >@@ -673,262 +670,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); >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index c39a0b963f3..10b9bab3b75 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -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; >diff --git a/t/db_dependent/Items/GetHostItemsInfo.t b/t/db_dependent/Items/GetHostItemsInfo.t >deleted file mode 100755 >index d5c34c3b706..00000000000 >--- a/t/db_dependent/Items/GetHostItemsInfo.t >+++ /dev/null >@@ -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; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27272
:
128230
|
128231
|
135640
|
135641
|
135642
|
135643
|
135644
|
135645
|
135646
|
135647
|
135648
|
135649
|
135650
|
135651
|
135652
|
135653
|
135654
|
135655
|
135656
|
135657
|
135658
|
135659
|
137966
|
137967
|
137968
|
137969
|
137970
|
137971
|
137972
|
137973
|
137974
|
137975
|
137976
|
137977
|
137978
|
137979
|
137980
|
137981
|
137982
|
138109
|
138296
|
138297
|
138298
|
138303
|
138304
|
138305
|
138306
|
138307
|
138308
|
138437
|
138438
|
138439
|
138440
|
138441
|
138442
|
138553
|
138554
|
138555
|
138556
|
138557
|
138558
|
138559
|
138560
|
138561
|
138562
|
138563
|
138564
|
138565
|
138566
|
138567
|
138568
|
138569
|
138570
|
138571
|
138572
|
138573
|
138574
|
138575
|
138614
|
138615
|
138616
|
138617
|
138618
|
138619
|
138620
|
138621
|
138622
|
138623
|
138624
|
138625
|
138626
|
138627
|
138628
|
138629
|
138630
|
138631
|
138632
|
138633
|
138634
|
138635
|
138636
|
138714
|
138715
|
138716
|
138717
|
138718
|
138719
|
138720
|
138721
|
138722
|
138723
|
138724
|
138725
|
138726
|
138727
|
138728
|
138729
|
138730
|
138731
|
138732
|
138733
|
138734
|
138735
|
138736
|
138773
|
138774
|
138775
|
138776
|
138777
|
138778
|
138779
|
138780
|
138781
|
138782
|
138783
|
138784
|
138785
|
138786
|
138787
|
138788
|
138789
|
138790
|
138791
|
138792
|
138793
|
138794
|
138832
|
139928