Bugzilla – Attachment 32446 Details for
Bug 6473
Test bug for Git-bz ✔ ❤ ★
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9011 - Re-engineer circ anonymization, move to subroutine in C4::Circulation
Bug-9011---Re-engineer-circ-anonymization-move-to-.patch (text/plain), 8.77 KB, created by
Kyle M Hall (khall)
on 2014-10-16 16:42:25 UTC
(
hide
)
Description:
Bug 9011 - Re-engineer circ anonymization, move to subroutine in C4::Circulation
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2014-10-16 16:42:25 UTC
Size:
8.77 KB
patch
obsolete
>From be6b0abe7a0d2629c760e0e86941e5f767d39ef0 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 5 Mar 2014 10:11:51 -0500 >Subject: [PATCH] Bug 9011 - Re-engineer circ anonymization, move to subroutine in C4::Circulation > >Signed-off-by: Nick Clemens <nick@quecheelibrary.org> > >http://bugs.koha-community.org/show_bug.cgi?id=6473 >--- > C4/Circulation.pm | 45 ++++++-- > Koha/Schema/Result/OldIssue.pm | 6 + > t/db_dependent/Circulation_anonymization.t | 153 ++++++++++++++++++++++++++++ > 3 files changed, 193 insertions(+), 11 deletions(-) > create mode 100644 t/db_dependent/Circulation_anonymization.t > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 8c0b208..47f7ca1 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -47,6 +47,7 @@ use Algorithm::CheckDigits; > use Data::Dumper; > use Koha::DateUtils; > use Koha::Calendar; >+use Koha::Database; > use Koha::Borrower::Debarments; > use Carp; > use Date::Calc qw( >@@ -2065,17 +2066,7 @@ sub MarkIssueReturned { > WHERE borrowernumber = ? > AND itemnumber = ?'); > $sth_copy->execute($borrowernumber, $itemnumber); >- # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber >- if ( $privacy == 2) { >- # The default of 0 does not work due to foreign key constraints >- # The anonymisation will fail quietly if AnonymousPatron is not a valid entry >- # FIXME the above is unacceptable - bug 9942 relates >- my $anonymouspatron = (C4::Context->preference('AnonymousPatron')) ? C4::Context->preference('AnonymousPatron') : 0; >- my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=? >- WHERE borrowernumber = ? >- AND itemnumber = ?"); >- $sth_ano->execute($anonymouspatron, $borrowernumber, $itemnumber); >- } >+ AnonymizeItemIssueHistory({ itemnumber => $itemnumber }); > my $sth_del = $dbh->prepare("DELETE FROM issues > WHERE borrowernumber = ? > AND itemnumber = ?"); >@@ -3775,6 +3766,38 @@ sub GetAgeRestriction { > return $restriction_year; > } > >+=head AnonymizeItemIssueHistory >+ >+ AnonymizeItemIssueHistory({ itemnumber => $itemnumber }); >+ >+=cut >+ >+sub AnonymizeItemIssueHistory { >+ my ( $params ) = @_; >+ >+ my $itemnumber = $params->{itemnumber}; >+ return unless $itemnumber; >+ >+ my $a = C4::Context->preference('AnonymousPatron'); >+ return unless $a; >+ >+ my $schema = Koha::Database->new()->schema(); >+ >+ my $old_issues_rs = $schema->resultset('OldIssue')->search( >+ { >+ 'me.itemnumber' => $itemnumber, >+ 'me.borrowernumber' => { '!=' => $a }, >+ }, >+ { prefetch => 'borrower', order_by => { -desc => 'issue_id' } } >+ ); >+ >+ my $oi = $old_issues_rs->next(); >+ if ( $oi->borrower()->privacy() == 2 ) { >+ $oi->set_column( 'borrowernumber', $a ); >+ $oi->update(); >+ } >+} >+ > 1; > > __END__ >diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm >index faa472c..eca845c 100644 >--- a/Koha/Schema/Result/OldIssue.pm >+++ b/Koha/Schema/Result/OldIssue.pm >@@ -191,6 +191,12 @@ __PACKAGE__->belongs_to( > # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-17 21:06:58 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/ofcOgd+0YhWqMTWEDdaCw > >+__PACKAGE__->belongs_to( >+ "borrower", >+ "Koha::Schema::Result::Borrower", >+ { borrowernumber => "borrowernumber" }, >+ { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" }, >+); > > # You can replace this text with custom content, and it will be preserved on regeneration > 1; >diff --git a/t/db_dependent/Circulation_anonymization.t b/t/db_dependent/Circulation_anonymization.t >new file mode 100644 >index 0000000..caec6b5 >--- /dev/null >+++ b/t/db_dependent/Circulation_anonymization.t >@@ -0,0 +1,153 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use C4::Context; >+use C4::Circulation; >+use Koha::Database; >+ >+use Test::More tests => 4; >+ >+BEGIN { >+ use_ok('C4::Circulation'); >+ use_ok('Koha::Database'); >+} >+ >+#Start transaction >+my $dbh = C4::Context->dbh; >+$dbh->{RaiseError} = 1; >+$dbh->{AutoCommit} = 0; >+ >+$dbh->do(q|DELETE FROM issues|); >+$dbh->do(q|DELETE FROM items|); >+$dbh->do(q|DELETE FROM borrowers|); >+$dbh->do(q|DELETE FROM branches|); >+$dbh->do(q|DELETE FROM categories|); >+$dbh->do(q|DELETE FROM accountlines|); >+$dbh->do(q|DELETE FROM issuingrules|); >+ >+my $schema = Koha::Database->new()->schema(); >+ >+#Add branch and category >+my $samplebranch1 = $schema->resultset('Branch')->create( >+ { >+ branchcode => 'CPL', >+ branchname => 'Sample Branch', >+ branchaddress1 => 'sample adr1', >+ branchaddress2 => 'sample adr2', >+ branchaddress3 => 'sample adr3', >+ branchzip => 'sample zip', >+ branchcity => 'sample city', >+ branchstate => 'sample state', >+ branchcountry => 'sample country', >+ branchphone => 'sample phone', >+ branchfax => 'sample fax', >+ branchemail => 'sample email', >+ branchurl => 'sample url', >+ branchip => 'sample ip', >+ branchprinter => undef, >+ opac_info => 'sample opac', >+ } >+); >+ >+my $samplecat = $schema->resultset('Category')->create( >+ { >+ categorycode => 'CAT1', >+ description => 'Description1', >+ enrolmentperiod => 'Null', >+ enrolmentperioddate => 'Null', >+ dateofbirthrequired => 'Null', >+ finetype => 'Null', >+ bulk => 'Null', >+ enrolmentfee => 'Null', >+ overduenoticerequired => 'Null', >+ issuelimit => 'Null', >+ reservefee => 'Null', >+ hidelostitems => 0, >+ category_type => 'Null' >+ } >+); >+ >+#Add biblio and item >+my $record = MARC::Record->new(); >+$record->append_fields( >+ MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); >+my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); >+ >+my $itemnumber; >+( $biblionumber, $biblioitemnumber, $itemnumber ) = C4::Items::AddItem( >+ { >+ barcode => 'barcode_1', >+ itemcallnumber => 'callnumber1', >+ homebranch => $samplebranch1->branchcode(), >+ holdingbranch => $samplebranch1->branchcode(), >+ issue => 1, >+ reserve => 1 >+ }, >+ $biblionumber >+); >+ >+my $anonymous_patron = $schema->resultset('Borrower')->create( >+ { >+ firstname => 'Anonymous', >+ surname => 'Patron', >+ categorycode => $samplecat->categorycode(), >+ branchcode => $samplebranch1->branchcode(), >+ } >+); >+C4::Context->set_preference( 'AnonymousPatron', $anonymous_patron->borrowernumber() ); >+ >+my $borrower1 = $schema->resultset('Borrower')->create( >+ { >+ firstname => 'firstname', >+ surname => 'surname', >+ categorycode => $samplecat->categorycode(), >+ branchcode => $samplebranch1->branchcode(), >+ privacy => 2, >+ } >+); >+my $borrower_1 = C4::Members::GetMember( borrowernumber => $borrower1->borrowernumber() ); >+ >+my $borrower2 = $schema->resultset('Borrower')->create( >+ { >+ firstname => 'firstname', >+ surname => 'surname', >+ categorycode => $samplecat->categorycode(), >+ branchcode => $samplebranch1->branchcode(), >+ privacy => 1, >+ } >+); >+my $borrower_2 = C4::Members::GetMember( borrowernumber => $borrower2->borrowernumber() ); >+ >+# NEED TO BE FIXED !!! >+# The first parameter for set_userenv is the class ref >+#my @USERENV = ( $borrower_id1, 'test', 'MASTERTEST', 'firstname', 'username', 'CPL', 'CPL', 'email@example.org' ); >+my @USERENV = ( $borrower1->borrowernumber(), 'test', 'MASTERTEST', 'firstname', 'CPL', 'CPL', 'email@example.org' ); >+ >+C4::Context->_new_userenv('DUMMY_SESSION_ID'); >+C4::Context->set_userenv(@USERENV); >+ >+my $userenv = C4::Context->userenv >+ or BAIL_OUT("No userenv"); >+ >+#Begin Tests >+ >+AddIssue( $borrower_1, 'barcode_1' ); >+AddReturn('barcode_1'); >+my $old_issue = >+ $schema->resultset('OldIssue')->search( { itemnumber => $itemnumber }, >+ { order_by => { -desc => 'issue_id' } } )->next(); >+ok( $old_issue->borrower()->borrowernumber() == $anonymous_patron->borrowernumber(), "Patron with privacy of 2 anonymized" ); >+ >+my $next_issue_id = $old_issue->issue_id() + 1; >+ >+ >+AddIssue( $borrower_2, 'barcode_1' ); >+AddReturn('barcode_1'); >+$old_issue = >+ $schema->resultset('OldIssue')->find( $next_issue_id ); >+ok( $old_issue->borrower()->borrowernumber() == $borrower2->borrowernumber(), "Patron with privacy of 1 not anonymized" ); >+ >+ >+#End transaction >+$dbh->rollback; >-- >1.7.2.5
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 6473
:
4386
|
6837
|
6838
|
6839
|
6840
|
6841
|
6842
|
6843
|
7154
|
7155
|
7567
|
7994
|
7995
|
7996
|
7997
|
8018
|
9807
|
9808
|
9813
|
9831
|
9832
|
9836
|
9854
|
10842
|
10843
|
10844
|
10845
|
10846
|
10847
|
10848
|
10849
|
10850
|
10851
|
10852
|
10853
|
10854
|
10855
|
10856
|
10857
|
10858
|
11540
|
11543
|
11544
|
12502
|
12513
|
12514
|
12515
|
12516
|
12517
|
12518
|
12519
|
13473
|
13673
|
14955
|
14969
|
14970
|
14972
|
15201
|
18949
|
18950
|
18951
|
18952
|
18953
|
18954
|
18955
|
18956
|
18957
|
18958
|
18959
|
18960
|
18961
|
18962
|
18963
|
18971
|
18972
|
19518
|
19519
|
19591
|
19592
|
19871
|
19879
|
19880
|
19881
|
19882
|
20011
|
20012
|
20013
|
20014
|
22477
|
22481
|
22482
|
22496
|
22502
|
22503
|
31958
|
32444
|
32445
|
32446
|
32447
|
32448
|
32449
|
32450
|
32451
|
32452
|
34200
|
34201
|
34625
|
34999
|
35130
|
35269
|
35273
|
35274
|
35275
|
35276
|
35277
|
35279
|
35280
|
35303
|
40954
|
40957
|
45345
|
45349
|
45731
|
45732
|
45733
|
45734
|
47283
|
47284
|
47298
|
47299
|
47300
|
47334
|
47336
|
49083
|
56974
|
61059
|
61069
|
62038
|
65313
|
77301
|
78016
|
79959
|
80178
|
80179
|
80180
|
80181
|
80182
|
84400
|
86644
|
86645
|
87152
|
88128
|
95586
|
95716
|
97394
|
99026
|
99027
|
114217
|
114218
|
114219
|
114220
|
114221
|
114222
|
114223
|
114224
|
114225
|
114226
|
119255
|
121181
|
131891
|
131893
|
131894
|
134862
|
144109
|
144144
|
144671
|
144672
|
144673
|
147183
|
149030
|
149031
|
149032
|
149033
|
160566
|
160567
|
160568