Bug 14493: export_borrowers.pl - Export patron attributes bug14493_patron_export_attributes
authorVitor Fernandes <vfernandes@keep.pt>
Thu, 12 Jul 2018 19:17:38 +0000 (15:17 -0400)
committerJason Etheridge <jason@equinoxinitiative.org>
Thu, 12 Jul 2018 19:17:38 +0000 (15:17 -0400)
Tweaked Vitor's original patch to accomodate changes to the file.

---

export_borrowers.pl changed to support patron attributes

Test plan:

- Use export_borrowers.pl to export all patron and all fields
- The patrons extended attributes are not exported
- Apply the patch
- Use export_borrowers.pl with the no fields specified or with the field patron_attributes
- The patrons extended attributes will be exported in one column

Create by: Vitor Fernandes <vfernandes@keep.pt>
Sponsored by: KEEP SOLUTIONS

Signed-off-by: Jason Etheridge <jason@equinoxinitiative.org>

misc/export_borrowers.pl

index 5f5c7f7..1ac7454 100755 (executable)
@@ -24,6 +24,7 @@ use Text::CSV;
 use Getopt::Long qw(:config no_ignore_case);
 
 use C4::Context;
+use C4::Members::Attributes qw(GetBorrowerAttributes);
 use Koha::Patrons;
 
 binmode STDOUT, ":encoding(UTF-8)";
@@ -41,9 +42,10 @@ $0 [--field=FIELD [--field=FIELD [...]]] [--separator=CHAR] [--show-header] [--w
 $0 -h
 
     -f, --field=FIELD       Field to export. It is repeatable and has to match
-                            column names of the borrower table (also as 'description' and 'category_type'
-                            If no field is specified, then all fields will be
-                            exported.
+                            column names of the borrower table (with 'description',
+                            'category_type', and 'patron_attributes' also being
+                            options). If no field is specified, then all fields
+                            will be exported.
     -s, --separator=CHAR    This character will be used to separate fields.
                             Some characters like | or ; will need to be escaped
                             in the parameter setting, like -s=\\| or -s=\\;
@@ -105,6 +107,7 @@ my $category = $patron->category;
 my $member = $patron->unblessed;
 $member->{description} = $category->description;
 $member->{category_type} = $category->category_type;
+$member->{'patron_attributes'} = join (",", map { $_->{code}.":".$_->{value} } @{GetBorrowerAttributes($borrowernumber)});
 
 @fields = keys %$member unless (@fields);
 
@@ -131,6 +134,7 @@ while ( my $borrowernumber = $sth->fetchrow_array ) {
     my $member = $patron->unblessed;
     $member->{description} = $category->description;
     $member->{category_type} = $category->category_type;
+    $member->{'patron_attributes'} = join (",", map { $_->{code}.":".$_->{value} } @{GetBorrowerAttributes($borrowernumber)});
     $csv->combine(
         map {
             ( defined $member->{$_} and !ref $member->{$_} )