Bugzilla – Attachment 116344 Details for
Bug 20028
Export all patron related personal data in one package
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20028: Add Koha::Patron->takeout
Bug-20028-Add-KohaPatron-takeout.patch (text/plain), 4.72 KB, created by
Lari Taskula
on 2021-02-04 23:11:49 UTC
(
hide
)
Description:
Bug 20028: Add Koha::Patron->takeout
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2021-02-04 23:11:49 UTC
Size:
4.72 KB
patch
obsolete
>From 114a02bbdbfbe9f676ecf355a5aa4bb704c89b49 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Thu, 4 Feb 2021 19:28:30 +0000 >Subject: [PATCH] Bug 20028: Add Koha::Patron->takeout > >To test: >1. prove t/db_dependent/Koha/Patron.t >2. Observe success >--- > Koha/Patron.pm | 44 ++++++++++++++++++++ > t/db_dependent/Koha/Patron.t | 79 +++++++++++++++++++++++++++++++++++- > 2 files changed, 122 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 6ea9e5aae7..d931ff0ecc 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1700,6 +1700,50 @@ sub get_extended_attribute { > return $attribute->next; > } > >+=head3 takeout >+ >+my $takeout = $patron->takeout() >+ >+=cut >+ >+sub takeout { >+ my ( $self ) = @_; >+ >+ my $takeout = {}; >+ >+ my $result_source = $self->_result()->result_source; >+ >+ foreach my $rel ($self->_result()->relationships()) { >+ my $related_source = $result_source->related_source( $re ); >+ >+ # relationships() returns related columns, not tables, and therefore >+ # we could arrive multiple times into the same table >+ if ($takeout->{$related_source->source_name}) { >+ next; >+ } >+ >+ # Skip all the "[borrower] belongs_to" relationships >+ my $info = $result_source->relationship_info( $rel ); >+ if ( $info->{'attrs'}->{'is_depends_on'} ) { >+ next; >+ } >+ >+ # 'cond' has format foreign.columnname, remove ^foreign. from it >+ ( my $rel_col = ( keys %{$info->{'cond'}} )[0] ) =~ s/^foreign\.//; >+ >+ my $rs = $related_source->resultset; >+ my $res = $rs->search( { $rel_col => $self->borrowernumber } ); >+ >+ $res->result_class('DBIx::Class::ResultClass::HashRefInflator'); >+ >+ $takeout->{$related_source->source_name} = [ $res->all() ]; >+ } >+ >+ $takeout->{'borrowers'} = $self->unblessed; >+ >+ return $takeout; >+} >+ > =head3 to_api > > my $json = $patron->to_api; >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index 1b0d24552a..fbc30869a5 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 7; > use Test::Exception; > > use Koha::Database; >@@ -77,6 +77,83 @@ subtest 'add_guarantor() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'takeout' => sub { >+ >+ plan tests => 66; >+ >+ $schema->storage->txn_begin; >+ >+ my $test_objects = {}; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ } >+ ); >+ >+ my $someone_else = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ } >+ ); >+ >+ my $result_source = Koha::Patron->new->_result()->result_source; >+ foreach my $rel ( Koha::Patron->new->_result()->relationships() ) { >+ my $related_source = $result_source->related_source($rel); >+ >+ # relationships() returns related columns, not tables, and therefore >+ # we could arrive multiple times into the same table and had already >+ # generated test data for that object. next; in such case. >+ if ($test_objects->{$related_source->source_name}) { >+ next; >+ } >+ >+ my $rs = $related_source->resultset; >+ my $info = $result_source->relationship_info($rel); >+ >+ # We are not interested in the "belongs_to" relationship of borrowers. >+ # These are tables like branches, categories, sms_provider etc. >+ if ($info->{'attrs'}->{'is_depends_on'}) { >+ next; >+ } >+ >+ my $source_name = $related_source->source_name; >+ (my $rel_col = (keys %{$info->{'cond'}})[0]) =~ s/^foreign\.//; >+ >+ my $built = $builder->build( >+ { >+ source => $source_name, >+ value => { $rel_col => $patron->borrowernumber } >+ } >+ ); >+ >+ $test_objects->{$related_source->source_name} = [ $built ]; >+ >+ # Create test data for someone else, to ensure we are only returning >+ # this patron's data >+ $builder->build( >+ { >+ source => $source_name, >+ value => { $rel_col => $someone_else->borrowernumber } >+ } >+ ); >+ >+ } >+ >+ my $takeout = $patron->takeout; >+ >+ foreach my $rel ( Koha::Patron->new->_result()->relationships() ) { >+ my $related_source = $result_source->related_source($rel); >+ is_deeply( >+ $takeout->{$related_source->source_name}, >+ $test_objects->{$related_source->source_name}, >+ "$rel included in takeout" >+ ); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'relationships_debt() tests' => sub { > > plan tests => 168; >-- >2.17.1
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 20028
:
75622
|
78095
|
79376
|
79381
|
116344
|
116604
|
117106
|
117107
|
117108
|
117109
|
119968
|
119969
|
119970
|
119971
|
119972
|
119974
|
119975
|
119976
|
119977
|
120844
|
120845
|
120846
|
120847
|
124156
|
124157
|
124158
|
124159
|
124160
|
124161
|
124164
|
124165
|
124166
|
124167
|
124168