Bugzilla – Attachment 140105 Details for
Bug 7021
Add patron category to the statistics table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7021: Terminology - usercode -> categorycode
Bug-7021-Terminology---usercode---categorycode.patch (text/plain), 10.05 KB, created by
Kyle M Hall (khall)
on 2022-09-02 11:15:27 UTC
(
hide
)
Description:
Bug 7021: Terminology - usercode -> categorycode
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2022-09-02 11:15:27 UTC
Size:
10.05 KB
patch
obsolete
>From 392275633c26d2b37e2853dfddf1806823513a42 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 23 May 2022 14:43:34 +0100 >Subject: [PATCH] Bug 7021: Terminology - usercode -> categorycode > >Lets stick to standard terminology and use categorycode rather than >usercode here. > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/Circulation.pm | 25 +++--- > C4/Stats.pm | 8 +- > .../Bug-7021-Reintroduce_usercode_column.perl | 4 +- > installer/data/mysql/kohastructure.sql | 2 +- > misc/add_statistics_borrowers_categorycode.pl | 83 +++++++++++++++++++ > 5 files changed, 104 insertions(+), 18 deletions(-) > create mode 100755 misc/add_statistics_borrowers_categorycode.pl > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index b7abe300b9..b9272c91bd 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -813,15 +813,17 @@ sub CanBookBeIssued { > # > if ( $patron->category->category_type eq 'X' && ( $item_object->barcode )) { > # stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 . >- C4::Stats::UpdateStats({ >- branch => C4::Context->userenv->{'branch'}, >- type => 'localuse', >- itemnumber => $item_object->itemnumber, >- itemtype => $effective_itemtype, >- borrowernumber => $patron->borrowernumber, >- ccode => $item_object->ccode}, >- usercode => $patron->categorycode, >- ); >+ C4::Stats::UpdateStats( >+ { >+ branch => C4::Context->userenv->{'branch'}, >+ type => 'localuse', >+ itemnumber => $item_object->itemnumber, >+ itemtype => $effective_itemtype, >+ borrowernumber => $patron->borrowernumber, >+ ccode => $item_object->ccode, >+ categorycode => $patron->categorycode, >+ } >+ ); > ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item > return( { STATS => 1 }, {}); > } >@@ -1741,7 +1743,7 @@ sub AddIssue { > location => $item_object->location, > borrowernumber => $borrower->{'borrowernumber'}, > ccode => $item_object->ccode, >- usercode => $borrower->{'categorycode'} >+ categorycode => $borrower->{'categorycode'} > } > ); > >@@ -2351,6 +2353,7 @@ sub AddReturn { > location => $item->location, > borrowernumber => $borrowernumber, > ccode => $item->ccode, >+ categorycode => $patron->categorycode, > }); > > # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then. >@@ -3190,7 +3193,7 @@ sub AddRenewal { > location => $item_object->location, > borrowernumber => $borrowernumber, > ccode => $item_object->ccode, >- usercode => $patron->categorycode, >+ categorycode => $patron->categorycode, > } > ); > >diff --git a/C4/Stats.pm b/C4/Stats.pm >index af5a97465b..a833ba2e92 100644 >--- a/C4/Stats.pm >+++ b/C4/Stats.pm >@@ -65,7 +65,7 @@ C<$params> is an hashref whose expected keys are: > other : sipmode > itemtype : the type of the item > ccode : the collection code of the item >- usercode : the categorycode of the patron >+ categorycode : the categorycode of the patron > > type key is mandatory. > For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory: >@@ -83,7 +83,7 @@ sub UpdateStats { > # make some controls > return () if ! defined $params; > # change these arrays if new types of transaction or new parameters are allowed >- my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location usercode); >+ my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location categorycode); > my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall); > my @allowed_accounts_types = qw (writeoff payment); > my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype); >@@ -124,7 +124,7 @@ sub UpdateStats { > my $itemtype = exists $params->{itemtype} ? $params->{itemtype} : ''; > my $location = exists $params->{location} ? $params->{location} : undef; > my $ccode = exists $params->{ccode} ? $params->{ccode} : ''; >- my $usercode = exists $params->{usercode} ? $params->{usercode} : undef; >+ my $categorycode = exists $params->{categorycode} ? $params->{categorycode} : undef; > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; > my $statistic = Koha::Statistic->new( >@@ -139,7 +139,7 @@ sub UpdateStats { > location => $location, > borrowernumber => $borrowernumber, > ccode => $ccode, >- usercode => $usercode, >+ categorycode => $categorycode, > } > )->store; > >diff --git a/installer/data/mysql/atomicupdate/Bug-7021-Reintroduce_usercode_column.perl b/installer/data/mysql/atomicupdate/Bug-7021-Reintroduce_usercode_column.perl >index 4a7a32a69e..dd32d14ebf 100644 >--- a/installer/data/mysql/atomicupdate/Bug-7021-Reintroduce_usercode_column.perl >+++ b/installer/data/mysql/atomicupdate/Bug-7021-Reintroduce_usercode_column.perl >@@ -3,8 +3,8 @@ if( CheckVersion( $DBversion ) ) { > # you can use $dbh here like: > # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); > >- $dbh->do("ALTER TABLE statistics ADD COLUMN usercode varchar(10) AFTER ccode"); >+ $dbh->do("ALTER TABLE statistics ADD COLUMN categorycode varchar(10) AFTER ccode"); > > # Always end with this (adjust the bug info) >- NewVersion( $DBversion, 7021, "Bug 7021 - Reintroduce usercode column"); >+ NewVersion( $DBversion, 7021, "Bug 7021 - Introduce categorycode column"); > } >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index b49b637c1d..a406a7e510 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -4937,7 +4937,7 @@ CREATE TABLE `statistics` ( > `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)', > `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower', > `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code', >- `usercode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, >+ `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, > KEY `timeidx` (`datetime`), > KEY `branch_idx` (`branch`), > KEY `type_idx` (`type`), >diff --git a/misc/add_statistics_borrowers_categorycode.pl b/misc/add_statistics_borrowers_categorycode.pl >new file mode 100755 >index 0000000000..17ca24d8b3 >--- /dev/null >+++ b/misc/add_statistics_borrowers_categorycode.pl >@@ -0,0 +1,83 @@ >+#! /usr/bin/perl >+ >+## EXTRACTED USING THIS: >+# grep -Pnir "'notforloan' => '6'" 01_items0* | grep -Po "'id' => '-?(\d+)'" | grep -Po "\d+" > itemnumbers_notforloan_6.txt >+ >+use Modern::Perl; >+ >+use C4::Context; >+use utf8; >+ >+use Koha::Patrons; >+ >+use open ':encoding(utf8)'; >+binmode STDOUT, ':utf8'; >+ >+ >+print "\nTHE FOLLOWING STATISTIC ENTRIES HAVE BEEN UPDATED\n------------------------------------------------\n"; >+ >+ >+##Caches all the loaded Borrowers >+my $borrowers = {}; >+my $deletedBorrowers = {}; >+ >+my $dbh = C4::Context->dbh; >+ >+my $sthDelBor = $dbh->prepare("SELECT * FROM deletedborrowers WHERE borrowernumber = ? "); >+my $sthUpdateStat = $dbh->prepare("UPDATE statistics SET categorycode = ? WHERE datetime = ? AND branch = ? AND type = ? AND itemnumber = ? "); >+ >+my $query2 = "SELECT * FROM statistics WHERE type = 'issue' OR type = 'renew' OR type = 'localuse'"; >+my $sth2 = $dbh->prepare($query2); >+$sth2->execute(); >+my $stats = $sth2->fetchall_arrayref({}); >+ >+foreach my $stat (@$stats) { >+ my $borrower = getCachedBorrower( $stat->{borrowernumber} ); >+ >+ $borrower = getCachedDeletedBorrower( $stat->{borrowernumber} ) unless $borrower; >+ >+ if ($borrower) { >+ $borrower = $borrower->unblessed; >+ $stat->{categorycode} = $borrower->{categorycode}; >+ $sthUpdateStat->execute( $stat->{categorycode}, >+ $stat->{datetime}, >+ $stat->{branch}, >+ $stat->{type}, >+ $stat->{itemnumber}, >+ ); >+ print( $stat->{categorycode} . " " . >+ $stat->{datetime} . " " . >+ $stat->{branch} . " " . >+ $stat->{type} . " " . >+ $stat->{itemnumber} . " " >+ ); >+ print "\n"; >+ } >+} >+ >+ >+ >+##Members are repeatedly loaded in various parts of this code. Better to cache them. >+sub getCachedBorrower { >+ my $borrowernumber = shift; #The hash to store all branches by branchcode >+ >+ if (exists $borrowers->{$borrowernumber}) { >+ return $borrowers->{$borrowernumber}; >+ } >+ my $borrower = Koha::Patrons->find({ borrowernumber => $borrowernumber }); >+ $borrowers->{$borrowernumber} = $borrower; >+ return $borrower; >+} >+##Deleted members are repeatedly loaded in various parts of this code. Better to cache them. >+sub getCachedDeletedBorrower { >+ my $borrowernumber = shift; #The hash to store all branches by branchcode >+ >+ if (exists $deletedBorrowers->{$borrowernumber}) { >+ return $deletedBorrowers->{$borrowernumber}; >+ } >+ $sthDelBor->execute( $borrowernumber ); >+ >+ my $borrower = $sthDelBor->fetchrow_hashref(); >+ $borrowers->{$borrowernumber} = $borrower; >+ return $borrower; >+} >-- >2.30.2
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 7021
:
29456
|
29508
|
122881
|
122882
|
122883
|
129119
|
129120
|
129121
|
129122
|
135269
|
135270
|
135271
|
135272
|
135273
|
135274
|
140103
|
140104
| 140105 |
140106
|
140107
|
140108
|
140109
|
140110
|
140116
|
140144
|
140845