From c73e269a13f64fe016dc90941280c9d2e9cfb02c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Mar 2017 16:43:40 -0300 Subject: [PATCH] Bug 18260: Koha::Biblio - Remove GetBiblio MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit C4::Biblio::GetBiblio can be replaced with Koha Biblio->find Test plan: Import batch, view issue history, search for items, see the image of a bibliographic record, modify and delete records in a batch Followed test plan, works as expected. Signed-off-by: Marc Véron Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/Acquisition.pm | 2 +- C4/Biblio.pm | 20 ------------------- C4/ILSDI/Services.pm | 19 +++++++++--------- C4/ImportBatch.pm | 8 ++++---- C4/Serials.pm | 8 ++++---- Koha/REST/V1/Hold.pm | 5 ++--- catalogue/imageviewer.pl | 5 ++--- catalogue/issuehistory.pl | 11 +++++----- catalogue/itemsearch.pl | 3 ++- .../prog/en/modules/catalogue/issuehistory.tt | 10 +++++----- opac/opac-imageviewer.pl | 4 +++- reports/orders_by_fund.pl | 6 ++++-- serials/subscription-history.pl | 5 +++-- t/db_dependent/Acquisition.t | 8 ++++---- tools/batch_record_modification.pl | 4 +++- 15 files changed, 52 insertions(+), 66 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 5e1e651e0a..2e36ac15b8 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -3084,7 +3084,7 @@ sub NotifyOrderUsers { for my $borrowernumber (@borrowernumbers) { my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); my $library = Koha::Libraries->find( $borrower->{branchcode} )->unblessed; - my $biblio = C4::Biblio::GetBiblio( $order->{biblionumber} ); + my $biblio = Koha::Biblios->find( $order->{biblionumber} )->unblessed; my $letter = C4::Letters::GetPreparedLetter( module => 'acquisition', letter_code => 'ACQ_NOTIF_ON_RECEIV', diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 953964cf49..78cafdfd56 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -64,7 +64,6 @@ BEGIN { # to get something push @EXPORT, qw( - GetBiblio GetBiblioData GetMarcBiblio GetBiblioItemData @@ -907,25 +906,6 @@ sub GetISBDView { return $res; } -=head2 GetBiblio - - my $biblio = &GetBiblio($biblionumber); - -=cut - -sub GetBiblio { - my ($biblionumber) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?"); - my $count = 0; - my @results; - $sth->execute($biblionumber); - if ( my $data = $sth->fetchrow_hashref ) { - return $data; - } - return; -} # sub GetBiblio - =head2 GetBiblioItemInfosOf GetBiblioItemInfosOf(@biblioitemnumbers); diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 9b65a4a587..387dac2727 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -441,7 +441,8 @@ sub GetPatronInfo { my $library = Koha::Libraries->find( $hold->branchcode ); my $branchname = $library ? $library->branchname : ''; $unblessed_hold->{branchname} = $branchname; - $unblessed_hold->{title} = GetBiblio( $hold->biblionumber )->{'title'}; # Should be $hold->get_biblio + $biblio = Koha::Biblios->find( $hold->biblionumber ); # Should be $hold->get_biblio + $unblessed_hold->{title} = $biblio ? $biblio->title : ''; # Just in case, but should not be needed push @{ $borrower->{holds}{hold} }, $unblessed_hold; @@ -641,10 +642,10 @@ sub HoldTitle { # Get the biblio record, or return an error code my $biblionumber = $cgi->param('bib_id'); - my $biblio = GetBiblio( $biblionumber ); - return { code => 'RecordNotFound' } unless $$biblio{biblionumber}; - - my $title = $$biblio{title}; + my $biblio = Koha::Biblios->find( $biblionumber ); + return { code => 'RecordNotFound' } unless $biblio; + + my $title = $biblio ? $biblio->title : ''; # Check if the biblio can be reserved return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ) eq 'OK'; @@ -709,10 +710,10 @@ sub HoldItem { # Get the biblio or return an error code my $biblionumber = $cgi->param('bib_id'); - my $biblio = GetBiblio($biblionumber); - return { code => 'RecordNotFound' } unless $$biblio{biblionumber}; + my $biblio = Koha::Biblios->find( $biblionumber ); + return { code => 'RecordNotFound' } unless $biblio; - my $title = $$biblio{title}; + my $title = $biblio ? $biblio->title : ''; # Get the item or return an error code my $itemnumber = $cgi->param('item_id'); @@ -720,7 +721,7 @@ sub HoldItem { return { code => 'RecordNotFound' } unless $$item{itemnumber}; # If the biblio does not match the item, return an error code - return { code => 'RecordNotFound' } if $$item{biblionumber} ne $$biblio{biblionumber}; + return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber; # Check for item disponibility my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber ); diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 1b598c7e9d..c4550eb4ab 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -662,7 +662,7 @@ sub BatchCommitRecords { $recordid = $record_match; my $oldxml; if ($record_type eq 'biblio') { - my $oldbiblio = GetBiblio($recordid); + my $oldbiblio = Koha::Biblios->find( $recordid ); $oldxml = GetXmlBiblio($recordid); # remove item fields so that they don't get @@ -674,7 +674,7 @@ sub BatchCommitRecords { } $oldxml = $old_marc->as_xml($marc_type); - ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); + ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode); $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; if ($item_result eq 'create_new' || $item_result eq 'replace') { @@ -865,13 +865,13 @@ sub BatchRevertRecords { my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'}, $marc_type); if ($record_type eq 'biblio') { my $biblionumber = $rowref->{'matched_biblionumber'}; - my $oldbiblio = GetBiblio($biblionumber); + my $oldbiblio = Koha::Biblios->find( $biblionumber ); $logger->info("C4::ImportBatch::BatchRevertRecords: Biblio record $biblionumber does not exist, restoration of this record was skipped") unless $oldbiblio; next unless $oldbiblio; # Record has since been deleted. Deleted records should stay deleted. $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); - ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'}); + ModBiblio($old_record, $biblionumber, $oldbiblio->frameworkcode); } else { my $authid = $rowref->{'matched_authid'}; ModAuthority($authid, $old_record, GuessAuthTypeCode($old_record)); diff --git a/C4/Serials.pm b/C4/Serials.pm index 4b9ac61ba0..b4897c2434 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1483,14 +1483,14 @@ sub NewSubscription { logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); #set serial flag on biblio if not already set. - my $bib = GetBiblio($biblionumber); - if ( $bib and !$bib->{'serial'} ) { + my $biblio = Koha::Biblios->find( $biblionumber ); + if ( $biblio and !$biblio->serial ) { my $record = GetMarcBiblio($biblionumber); - my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} ); + my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $biblio->frameworkcode ); if ($tag) { eval { $record->field($tag)->update( $subf => 1 ); }; } - ModBiblio( $record, $biblionumber, $bib->{'frameworkcode'} ); + ModBiblio( $record, $biblionumber, $biblio->frameworkcode ); } return $subscriptionid; } diff --git a/Koha/REST/V1/Hold.pm b/Koha/REST/V1/Hold.pm index 99af4617d2..9128c24d11 100644 --- a/Koha/REST/V1/Hold.pm +++ b/Koha/REST/V1/Hold.pm @@ -76,9 +76,8 @@ sub add { }, 400); } $biblionumber ||= $biblio->biblionumber; - $biblio->unblessed; # FIXME remove later } else { - $biblio = C4::Biblio::GetBiblio($biblionumber); + $biblio = Koha::Biblios->find( $biblionumber ); } my $can_reserve = @@ -102,7 +101,7 @@ sub add { my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber, $biblionumber, undef, $priority, undef, $expirationdate, undef, - $biblio->{title}, $itemnumber); + $biblio->title, $itemnumber); unless ($reserve_id) { return $c->$cb({ diff --git a/catalogue/imageviewer.pl b/catalogue/imageviewer.pl index 3317db1909..aa73e9dd1a 100755 --- a/catalogue/imageviewer.pl +++ b/catalogue/imageviewer.pl @@ -44,9 +44,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber') || $query->param('bib'); my $imagenumber = $query->param('imagenumber'); -my $biblio = GetBiblio($biblionumber); -my $biblio_object = Koha::Biblios->find( $biblionumber ); # This should replace $biblio -my $itemcount = $biblio_object->items->count;; +my $biblio = Koha::Biblios->find( $biblionumber ); +my $itemcount = $biblio->items->count;; my @items = GetItemsInfo($biblionumber); diff --git a/catalogue/issuehistory.pl b/catalogue/issuehistory.pl index d4774c8367..070a1289c0 100755 --- a/catalogue/issuehistory.pl +++ b/catalogue/issuehistory.pl @@ -27,6 +27,8 @@ use C4::Circulation; # GetBiblioIssues use C4::Biblio; # GetBiblio use C4::Search; # enabled_staff_search_views +use Koha::Biblios; + my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { @@ -38,20 +40,17 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -# getting cgi params. -my $params = $query->Vars; - -my $biblionumber = $params->{'biblionumber'}; +my $biblionumber = $query->param('biblionumber'); if (C4::Context->preference("HidePatronName")) { $template->param(HidePatronName => 1); } my $issues = GetBiblioIssues($biblionumber); -my $biblio = GetBiblio($biblionumber); -$template->param(%$biblio); +my $biblio = Koha::Biblios->find( $biblionumber ); $template->param( + biblio => $biblio, total => scalar @$issues, issues => $issues, issuehistoryview => 1, diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index 5f20dd3813..ee8ca66186 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -28,6 +28,7 @@ use C4::Biblio; use C4::Koha; use Koha::AuthorisedValues; +use Koha::Biblios; use Koha::Item::Search::Field qw(GetItemSearchFields); use Koha::ItemTypes; use Koha::Libraries; @@ -226,7 +227,7 @@ if (scalar keys %params > 0) { } foreach my $item (@$results) { - $item->{biblio} = GetBiblio($item->{biblionumber}); + $item->{biblio} = Koha::Biblios->find( $item->{biblionumber} ); ($item->{biblioitem}) = GetBiblioItemByBiblioNumber($item->{biblionumber}); $item->{status} = $notforloan_map->{$item->{notforloan}}; if (defined $item->{location}) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt index ae5117d98d..b1245b73e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt @@ -2,7 +2,7 @@ [% USE KohaDates %] [% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] -Koha › Catalog › Checkout history for [% title |html %] +Koha › Catalog › Checkout history for [% biblio.title |html %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'datatables.inc' %] @@ -23,7 +23,7 @@ $(document).ready(function() { [% INCLUDE 'header.inc' %] [% INCLUDE 'cat-search.inc' %] - +
@@ -31,8 +31,8 @@ $(document).ready(function() {
-

Checkout history for [% title |html %]

-[% IF ( author ) %]

by [% author %]

[% END %] +

Checkout history for [% biblio.title |html %]

+[% IF biblio.author %]

by [% biblio.author %]

[% END %]
[% IF ( issues ) %] @@ -92,7 +92,7 @@ $(document).ready(function() { [% ELSE %]

- [% title |html %][% IF ( author ) %], by [% author %][% END %] has never been checked out.

+ [% biblio.title |html %][% IF biblio.author %], by [% biblio.author %][% END %] has never been checked out.

[% END %]
diff --git a/opac/opac-imageviewer.pl b/opac/opac-imageviewer.pl index 3cb4779402..8023d7deb5 100755 --- a/opac/opac-imageviewer.pl +++ b/opac/opac-imageviewer.pl @@ -26,6 +26,8 @@ use C4::Biblio; use C4::Output; use C4::Images; +use Koha::Biblios; + my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { @@ -38,7 +40,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber') || $query->param('bib'); my $imagenumber = $query->param('imagenumber'); -my $biblio = GetBiblio($biblionumber); +my $biblio = Koha::Biblios->find( $biblionumber ); if ( C4::Context->preference("OPACLocalCoverImages") ) { my @images = ListImagesForBiblio($biblionumber); diff --git a/reports/orders_by_fund.pl b/reports/orders_by_fund.pl index 469b2c2c8d..25b0adeacd 100755 --- a/reports/orders_by_fund.pl +++ b/reports/orders_by_fund.pl @@ -34,6 +34,7 @@ use C4::Budgets; use C4::Biblio; use C4::Reports; use C4::Acquisition; #GetBasket() +use Koha::Biblios; use Koha::DateUtils; my $query = new CGI; @@ -97,13 +98,14 @@ if ( $get_orders ) { # Format the order's informations foreach my $order (@orders) { # Get the title of the ordered item - my $biblio = C4::Biblio::GetBiblio($order->{'biblionumber'}); + my $biblio = Koha::Biblios->find( $order->{biblionumber} ); my $basket = C4::Acquisition::GetBasket($order->{'basketno'}); $order->{'basketname'} = $basket->{'basketname'}; $order->{'authorisedbyname'} = $basket->{'authorisedbyname'}; - $order->{'title'} = $biblio->{'title'} || $order->{'biblionumber'}; + $order->{title} = $biblio ? $biblio->title : ''; + $order->{title} ||= $order->{biblionumber}; $order->{'total_rrp'} = $order->{'quantity'} * $order->{'rrp'}; $order->{'total_ecost'} = $order->{'quantity'} * $order->{'ecost'}; diff --git a/serials/subscription-history.pl b/serials/subscription-history.pl index 8b7dd3dada..8934cf1c06 100755 --- a/serials/subscription-history.pl +++ b/serials/subscription-history.pl @@ -35,6 +35,7 @@ use C4::Output; use C4::Biblio; use C4::Serials; +use Koha::Biblios; use Koha::DateUtils; my $input = new CGI; @@ -72,11 +73,11 @@ if($op && $op eq 'mod') { exit; } else { my $history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid); - my $biblio = GetBiblio($history->{'biblionumber'}); + my $biblio = Koha::Biblios->find( $history->{biblionumber} ); $template->param( subscriptionid => $subscriptionid, - title => $biblio->{'title'}, + title => $biblio->title, histstartdate => $history->{'histstartdate'}, histenddate => $history->{'histenddate'}, receivedlist => $history->{'recievedlist'}, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 90166501ca..646dd78d08 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -502,7 +502,7 @@ ok((not defined $error), "DelOrder does not fail"); $order1 = GetOrder($order1->{ordernumber}); ok((defined $order1->{datecancellationprinted}), "order is cancelled"); ok((not defined $order1->{cancellationreason}), "order has no cancellation reason"); -ok((defined GetBiblio($order1->{biblionumber})), "biblio still exists"); +ok((defined Koha::Biblios->find( $order1->{biblionumber} )), "biblio still exists"); $order2 = GetOrder($ordernumbers[1]); $error = DelOrder($order2->{biblionumber}, $order2->{ordernumber}, 1); @@ -510,7 +510,7 @@ ok((not defined $error), "DelOrder does not fail"); $order2 = GetOrder($order2->{ordernumber}); ok((defined $order2->{datecancellationprinted}), "order is cancelled"); ok((not defined $order2->{cancellationreason}), "order has no cancellation reason"); -ok((not defined GetBiblio($order2->{biblionumber})), "biblio does not exist anymore"); +ok((not defined Koha::Biblios->find( $order2->{biblionumber} )), "biblio does not exist anymore"); my $order4 = GetOrder($ordernumbers[3]); $error = DelOrder($order4->{biblionumber}, $order4->{ordernumber}, 1, "foobar"); @@ -518,14 +518,14 @@ ok((not defined $error), "DelOrder does not fail"); $order4 = GetOrder($order4->{ordernumber}); ok((defined $order4->{datecancellationprinted}), "order is cancelled"); ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\""); -ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore"); +ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore"); my $order5 = GetOrder($ordernumbers[4]); C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} ); $error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1); $order5 = GetOrder($order5->{ordernumber}); ok((defined $order5->{datecancellationprinted}), "order is cancelled"); -ok(GetBiblio($order5->{biblionumber}), "biblio still exists"); +ok((defined Koha::Biblios->find( $order5->{biblionumber} )), "biblio still exists"); # End of tests for DelOrder diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 6ea0317955..89527fbcb3 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -29,6 +29,8 @@ use C4::AuthoritiesMarc qw( BuildSummary ModAuthority ); use C4::BackgroundJob; use C4::Biblio qw( GetMarcBiblio ModBiblio ); use C4::MarcModificationTemplates qw( GetModificationTemplateActions GetModificationTemplates ModifyRecordWithTemplate ); + +use Koha::Biblios; use Koha::MetadataRecord::Authority; my $input = new CGI; @@ -116,7 +118,7 @@ if ( $op eq 'form' ) { for my $record_id ( uniq @record_ids ) { if ( $recordtype eq 'biblio' ) { # Retrieve biblio information - my $biblio = C4::Biblio::GetBiblio( $record_id ); + my $biblio = Koha::Biblios->find( $record_id ); unless ( $biblio ) { push @messages, { type => 'warning', -- 2.39.5