Bug 24545: Fix license statements
[srvgit] / Koha / Patron.pm
index 2de2965..e6d7538 100644 (file)
@@ -5,25 +5,25 @@ package Koha::Patron;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
 use Carp;
 use List::MoreUtils qw( any uniq );
 use JSON qw( to_json );
-use Text::Unaccent qw( unac_string );
+use Unicode::Normalize;
 
 use C4::Context;
 use C4::Log;
@@ -199,6 +199,10 @@ sub store {
             $self->surname( uc($self->surname) )
                 if C4::Context->preference("uppercasesurnames");
 
+            $self->relationship(undef) # We do not want to store an empty string in this field
+              if defined $self->relationship
+                     and $self->relationship eq "";
+
             unless ( $self->in_storage ) {    #AddMember
 
                 # Generate a valid userid/login if needed
@@ -357,7 +361,6 @@ other lists are kept.
 sub delete {
     my ($self) = @_;
 
-    my $deleted;
     $self->_result->result_source->schema->txn_do(
         sub {
             # Cancel Patron's holds
@@ -382,12 +385,12 @@ sub delete {
             # FIXME Could be $patron->get_lists
             $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } );
 
-            $deleted = $self->SUPER::delete;
+            $self->SUPER::delete;
 
             logaction( "MEMBERS", "DELETE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog");
         }
     );
-    return $deleted;
+    return $self;
 }
 
 
@@ -411,7 +414,7 @@ sub category {
 sub image {
     my ( $self ) = @_;
 
-    return scalar Koha::Patron::Images->find( $self->borrowernumber );
+    return Koha::Patron::Images->find( $self->borrowernumber );
 }
 
 =head3 library
@@ -1416,14 +1419,14 @@ sub generate_userid {
       $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
       $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
       my $userid = lc(($firstname)? "$firstname.$surname" : $surname);
-      $userid = unac_string('utf-8',$userid);
+      $userid = NFKD( $userid );
+      $userid =~ s/\p{NonspacingMark}//g;
       $userid .= $offset unless $offset == 0;
       $self->userid( $userid );
       $offset++;
      } while (! $self->has_valid_userid );
 
      return $self;
-
 }
 
 =head3 attributes
@@ -1555,9 +1558,9 @@ suitable for API output.
 =cut
 
 sub to_api {
-    my ( $self ) = @_;
+    my ( $self, $params ) = @_;
 
-    my $json_patron = $self->SUPER::to_api;
+    my $json_patron = $self->SUPER::to_api( $params );
 
     $json_patron->{restricted} = ( $self->is_debarred )
                                     ? Mojo::JSON->true