Bug 35782: Replace TT plugin's method Biblio::HoldsCount

We can use biblio.holds.count instead.

The main idea here is to make sure we are passing a Koha::Biblio object
as 'biblio' to all the templates including biblio-view-menu.inc

Test plan:
1. Go to the biblio detail view, click on the different entries in the menu
on the left. Confirm that the "Holds" tab always has the correct number
of Holds display in the parenthesis.

2. Run a search and confirm that the number of holds are still displayed
for each result.

QA:
git grep biblio-view-menu.inc
notice the tt list, open the corresponding perl controllers and confirm
that 'biblio' is passed and that it is a Koha::Biblio object.
The only missing place I found was in viewlog.
Note that we are not removing the TT method yet, we are marking it as
deprecated and also display a warning during the update DB process in
case one of the notice templates is using it.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2024-01-12 08:44:12 +01:00 committed by Katrin Fischer
parent 638b5ef1b4
commit 06c09e15fd
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
6 changed files with 36 additions and 6 deletions

View File

@ -31,9 +31,12 @@ use Koha::Recalls;
use Koha::DateUtils qw(dt_from_string);
# Do not use HoldsCount, it is deprecated and will be removed in a future release.
sub HoldsCount {
my ( $self, $biblionumber ) = @_;
warn "HoldsCount is deprecated, you should use biblio.holds.count instead";
my $holds = Koha::Holds->search( { biblionumber => $biblionumber } );
return $holds->count();

View File

@ -0,0 +1,25 @@
use Modern::Perl;
return {
bug_number => "35872",
description => "Biblio.HoldsCount is deprecated",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# Do you stuffs here
my ($count) = $dbh->selectrow_array(
q{
SELECT COUNT(*)
FROM letter
WHERE content LIKE "%Biblio.HoldsCount%";
}
);
if ($count) {
say $out "WARNING - Biblio.HoldsCount is used in at least one notice template";
say $out "It is deprecated and will be remove in a future version of Koha.";
say $out "Replace it with biblio.holds.count instead";
}
},
};

View File

@ -1,6 +1,6 @@
[% USE Koha %]
[% USE Biblio %]
[% SET biblio_object_id = object || biblionumber || biblio.biblionumber %]
[% SET biblio_object_id = biblio.biblionumber %]
<div id="menu">
<ul>
@ -66,7 +66,7 @@
[%- ELSE -%]
<li>
[%- END -%]
<a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio_object_id | url %]">Holds ([% Biblio.HoldsCount( biblio_object_id ) | html %])</a>
<a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio_object_id | url %]">Holds ([% biblio.holds.count | html %])</a>
</li>
[%- END -%]

View File

@ -570,11 +570,11 @@
<span class="noholdstext">No holds allowed</span>
[% ELSE %]
[% IF CAN_user_reserveforothers_place_holds %]
<a id="reserve_[% SEARCH_RESULT.biblionumber | html %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber | html %]">Holds ([% Biblio.HoldsCount( SEARCH_RESULT.biblionumber ) | html %])</a>
<a id="reserve_[% SEARCH_RESULT.biblionumber | html %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber | html %]">Holds ([% SEARCH_RESULT.biblio_object.holds.count | html %])</a>
[% IF ( holdfor ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber | uri %]&amp;findborrower=[% holdfor_patron.cardnumber | uri %]">Place hold for [% INCLUDE 'patron-title.inc' patron => holdfor_patron no_title => 1 no_cardnumber => 1 %]</a></span>[% END %]
[% IF ( holdforclub ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber | uri %]&amp;club=[% holdforclub | uri %]">Place hold for [% holdforclub_name | html %]</a></span>[% END %]
[% ELSE %]
<span>Holds ([% Biblio.HoldsCount( SEARCH_RESULT.biblionumber ) | html %])</span>
<span>Holds ([% SEARCH_RESULT.biblio_object.holds.count | html %])</span>
[% END %]
[% END # /IF SEARCH_RESULT.norequests %]
[% IF Koha.Preference('UseRecalls') and CAN_user_recalls %]

View File

@ -1032,7 +1032,7 @@
[% UNLESS ( patron ) %]
[% UNLESS borrowers %]
[% SET hold_count = Biblio.HoldsCount( biblio.biblionumber ) | html %]
[% SET hold_count = biblio.holds.count | html %]
[% IF hold_count %]
<label for ="always_show_holds">Always show holds</label>
[% IF always_show_holds == 'DONT' %]

View File

@ -130,11 +130,13 @@ if ($do_it) {
if ( @modules == 1 && $object_type eq 'biblio' ) {
# Handle 'Modification log' from cataloguing
my @itemnumbers = Koha::Items->search({ biblionumber => $object })->get_column('itemnumber');
my $biblio = Koha::Biblios->find( $object );
my @itemnumbers = $biblio->items->get_column('itemnumber');
$search_params{'-or'} = [
{ -and => { object => $object, info => { -like => 'biblio%' }}},
{ -and => { object => \@itemnumbers, info => { -like => 'item%' }}},
];
$template->param( biblio => $biblio );
} else {
$search_params{info} = { -like => '%' . $info . '%' } if $info;
$search_params{object} = $object if $object;