Skip to content

Commit

Permalink
Bug 30275: Rename issues.renewals to issues.renewals_count
Browse files Browse the repository at this point in the history
Rename the issues.renewals field to renewals_count to prevent a method
name collision with the new relation accessor introduced by this
patchset.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
  • Loading branch information
mrenvoize authored and tomascohen committed Jul 5, 2022
1 parent dd0bc7f commit 2d64b3c
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 20 deletions.
10 changes: 5 additions & 5 deletions C4/Circulation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ sub CanBookBeRenewed {
);

return ( 0, "too_many" )
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals_count;

return ( 0, "too_unseen" )
if C4::Context->preference('UnseenRenewals') &&
Expand Down Expand Up @@ -3153,8 +3153,8 @@ sub AddRenewal {

# Update the issues record to have the new due date, and a new count
# of how many times it has been renewed.
my $renews = ( $issue->renewals || 0 ) + 1;
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? WHERE issue_id = ?");
my $renews = ( $issue->renewals_count || 0 ) + 1;
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals_count = ?, unseen_renewals = ?, lastreneweddate = ? WHERE issue_id = ?");

eval{
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $issue->issue_id );
Expand Down Expand Up @@ -3282,7 +3282,7 @@ sub GetRenewCount {
);
$sth->execute( $bornum, $itemno );
my $data = $sth->fetchrow_hashref;
$renewcount = $data->{'renewals'} if $data->{'renewals'};
$renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
# $item and $borrower should be calculated
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
Expand Down Expand Up @@ -4076,7 +4076,7 @@ sub ProcessOfflineReturn {
$itemnumber,
$operation->{timestamp},
);
$item->renewals(0);
$item->renewals_count(0);
$item->onloan(undef);
$item->store({ log_action => 0 });
return "Success.";
Expand Down
2 changes: 1 addition & 1 deletion C4/ILSDI/Services.pm
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ sub RenewLoan {

# Hashref building
my $out;
$out->{'renewals'} = $issue->renewals;
$out->{'renewals'} = $issue->renewals_count;
$out->{date_due} = dt_from_string($issue->date_due)->strftime('%Y-%m-%d %H:%M');
$out->{'success'} = $renewal[0];
$out->{'error'} = $renewal[1];
Expand Down
4 changes: 2 additions & 2 deletions C4/Members.pm
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ sub GetAllIssues {

my $dbh = C4::Context->dbh;
my $query =
'SELECT issues.*, items.*, biblio.*, biblioitems.*, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp,borrowers.firstname,borrowers.surname
'SELECT issues.*, items.*, biblio.*, biblioitems.*, issues.timestamp as issuestimestamp, issues.renewals_count AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp,borrowers.firstname,borrowers.surname
FROM issues
LEFT JOIN items on items.itemnumber=issues.itemnumber
LEFT JOIN borrowers on borrowers.borrowernumber=issues.issuer_id
LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
WHERE issues.borrowernumber=?
UNION ALL
SELECT old_issues.*, items.*, biblio.*, biblioitems.*, old_issues.timestamp as issuestimestamp, old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp,borrowers.firstname,borrowers.surname
SELECT old_issues.*, items.*, biblio.*, biblioitems.*, old_issues.timestamp as issuestimestamp, old_issues.renewals_count AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp,borrowers.firstname,borrowers.surname
FROM old_issues
LEFT JOIN items on items.itemnumber=old_issues.itemnumber
LEFT JOIN borrowers on borrowers.borrowernumber=old_issues.issuer_id
Expand Down
2 changes: 1 addition & 1 deletion Koha/REST/V1/Checkouts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ sub allows_renewal {
openapi => {
allows_renewal => $renewable,
max_renewals => $rule->rule_value,
current_renewals => $checkout->renewals,
current_renewals => $checkout->renewals_count,
unseen_renewals => $checkout->unseen_renewals,
error => $error
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/swagger/definitions/checkout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ properties:
- "null"
format: date-time
description: Date the item was last renewed
renewals:
renewals_count:
type:
- integer
- "null"
Expand Down
6 changes: 6 additions & 0 deletions installer/data/mysql/atomicupdate/bug_30275.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
});
say $out "Added new table 'checkout_renewals'";

$dbh->do(q{ ALTER TABLE `issues` CHANGE `renewals` `renewals_count` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed' });
say $out "Renamed `issues.renewals` to `issues.renewals_count`";

$dbh->do(q{ ALTER TABLE `old_issues` CHANGE `renewals` `renewals_count` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed' });
say $out "Renamed `old_issues.renewals` to `old_issues.renewals_count`";
}
},
}
4 changes: 2 additions & 2 deletions installer/data/mysql/kohastructure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ CREATE TABLE `issues` (
`branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key, linking to the branches table for the location the item was checked out',
`returndate` datetime DEFAULT NULL COMMENT 'date the item was returned, will be NULL until moved to old_issues',
`lastreneweddate` datetime DEFAULT NULL COMMENT 'date the item was last renewed',
`renewals` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed',
`renewals_count` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed',
`unseen_renewals` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of consecutive times the item was renewed without being seen',
`auto_renew` tinyint(1) DEFAULT 0 COMMENT 'automatic renewal',
`auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'automatic renewal error',
Expand Down Expand Up @@ -3928,7 +3928,7 @@ CREATE TABLE `old_issues` (
`branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key, linking to the branches table for the location the item was checked out',
`returndate` datetime DEFAULT NULL COMMENT 'date the item was returned',
`lastreneweddate` datetime DEFAULT NULL COMMENT 'date the item was last renewed',
`renewals` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed',
`renewals_count` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of times the item was renewed',
`unseen_renewals` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'lists the number of consecutive times the item was renewed without being seen',
`auto_renew` tinyint(1) DEFAULT 0 COMMENT 'automatic renewal',
`auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'automatic renewal error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
[% INCLUDE 'patron-title.inc' patron=checkout.issuer %]
</a>
[% END %]</td>
<td>[% IF checkout.renewals %]
<td>[% IF checkout.renewals_count %]
Yes[% IF checkout.lastreneweddate %], <small>last on: [% checkout.lastreneweddate |$KohaDates with_hours => 1 %]</small>
[% END %]
[% ELSE %]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</td>

<td><a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% issue.itemnumber | uri %]&amp;biblionumber=[% issue.biblionumber | uri %]&amp;bi=[% issue.biblioitemnumber | uri %]#item[% issue.itemnumber | uri %]">[% issue.barcode | html %]</a></td>
<td>[% issue.renewals | html %]</td>
<td>[% issue.renewals_count | html %]</td>
<td data-order="[% issue.issuedate | html %]">
[% issue.issuedate |$KohaDates with_hours => 1 %]
</td>
Expand Down
6 changes: 3 additions & 3 deletions misc/recreateIssueStatistics.pl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
foreach my $table ('issues', 'old_issues') {
# Getting issues
print "looking for missing issues from $table\n";
my $query = "SELECT borrowernumber, branchcode, itemnumber, issuedate, renewals, lastreneweddate from $table where itemnumber is not null";
my $query = "SELECT borrowernumber, branchcode, itemnumber, issuedate, renewals_count, lastreneweddate from $table where itemnumber is not null";
my $sth = $dbh->prepare($query);
$sth->execute;
# Looking for missing issues
Expand Down Expand Up @@ -92,15 +92,15 @@
}

# Looking for missing renewals
if ($hashref->{'renewals'} && $hashref->{'renewals'} > 0 ) {
if ($hashref->{'renewals_count'} && $hashref->{'renewals_count'} > 0 ) {
# This is the not-so accurate part :
# We assume that there are missing renewals, based on the last renewal date
# Maybe should this be deactivated by default ?
my $ctnquery = "SELECT count(*) as cnt FROM statistics WHERE borrowernumber = ? AND itemnumber = ? AND DATE(datetime) = ? AND type = 'renew'";
my $substh = $dbh->prepare($ctnquery);
$substh->execute($hashref->{'borrowernumber'}, $hashref->{'itemnumber'}, $hashref->{'lastreneweddate'});

my $missingrenewalscount = $hashref->{'renewals'} - $substh->fetchrow_hashref->{'cnt'};
my $missingrenewalscount = $hashref->{'renewals_count'} - $substh->fetchrow_hashref->{'cnt'};
print "We assume $missingrenewalscount renewals are missing. Creating them\n" if ($missingrenewalscount > 0);
for (my $i = 0; $i < $missingrenewalscount; $i++) {

Expand Down
2 changes: 1 addition & 1 deletion offline_circ/download.pl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
items.itemcallnumber AS callnumber,
issues.date_due AS date_due,
issues.issuedate AS issuedate,
issues.renewals AS renewals,
issues.renewals_count AS renewals,
issues.unseen_renewals AS unseen_renewals,
borrowers.cardnumber AS cardnumber,
CONCAT(borrowers.surname, ', ', borrowers.firstname) AS borrower_name
Expand Down
4 changes: 2 additions & 2 deletions t/db_dependent/SIP/ILS.t
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ subtest checkout => sub {
AddIssue( $patron->unblessed, $item->barcode, undef, 0 );
my $checkout = $item->checkout;
ok( defined($checkout), "Checkout added");
is( $checkout->renewals, 0, "Correct renewals");
is( $checkout->renewals_count, 0, "Correct renewals");

my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
Expand All @@ -284,7 +284,7 @@ subtest checkout => sub {
is( $transaction->{screen_msg},"Item already checked out to you: renewing item.","We get a success message when issue is renewed");

$checkout->discard_changes();
is( $checkout->renewals, 1, "Renewals has been reduced");
is( $checkout->renewals_count, 1, "Renewals has been reduced");
};

subtest renew_all => sub {
Expand Down

0 comments on commit 2d64b3c

Please sign in to comment.