Browse Source

Bug 18260: Koha::Biblio - Remove GetBiblio

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 <veron@veron.ch>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
17.11.x
Jonathan Druart 7 years ago
parent
commit
c73e269a13
  1. 2
      C4/Acquisition.pm
  2. 20
      C4/Biblio.pm
  3. 19
      C4/ILSDI/Services.pm
  4. 8
      C4/ImportBatch.pm
  5. 8
      C4/Serials.pm
  6. 5
      Koha/REST/V1/Hold.pm
  7. 5
      catalogue/imageviewer.pl
  8. 11
      catalogue/issuehistory.pl
  9. 3
      catalogue/itemsearch.pl
  10. 10
      koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt
  11. 4
      opac/opac-imageviewer.pl
  12. 6
      reports/orders_by_fund.pl
  13. 5
      serials/subscription-history.pl
  14. 8
      t/db_dependent/Acquisition.t
  15. 4
      tools/batch_record_modification.pl

2
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',

20
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);

19
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 );

8
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));

8
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;
}

5
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({

5
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);

11
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,

3
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}) {

10
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt

@ -2,7 +2,7 @@
[% USE KohaDates %]
[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Catalog &rsaquo; Checkout history for [% title |html %]</title>
<title>Koha &rsaquo; Catalog &rsaquo; Checkout history for [% biblio.title |html %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" href="[% interface %]/[% theme %]/css/datatables.css" />
[% INCLUDE 'datatables.inc' %]
@ -23,7 +23,7 @@ $(document).ready(function() {
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo; Checkout history for <i>[% title |html %]</i></div>
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo; Checkout history for <i>[% biblio.title |html %]</i></div>
<div id="doc3" class="yui-t2">
@ -31,8 +31,8 @@ $(document).ready(function() {
<div id="yui-main">
<div class="yui-b">
<h1>Checkout history for [% title |html %]</h1>
[% IF ( author ) %]<h3>by [% author %]</h3>[% END %]
<h1>Checkout history for [% biblio.title |html %]</h1>
[% IF biblio.author %]<h3>by [% biblio.author %]</h3>[% END %]
<div class="searchresults">
[% IF ( issues ) %]
@ -92,7 +92,7 @@ $(document).ready(function() {
</table>
[% ELSE %]
<div class="dialog message"><p>
<b>[% title |html %][% IF ( author ) %], by [% author %][% END %]</b> has never been checked out.</p></div>
<b>[% biblio.title |html %][% IF biblio.author %], by [% biblio.author %][% END %]</b> has never been checked out.</p></div>
[% END %]
</div>

4
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);

6
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'};

5
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'},

8
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

4
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',

Loading…
Cancel
Save