[Koha-patches] [PATCH 1/3] Bug 17933 - Internal software error when searching patron without birth date

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Koha-patches] [PATCH 1/3] Bug 17933 - Internal software error when searching patron without birth date

Dobrica Pavlinusic
When patrons don't have date of birth (which is not required) patron
search results on moremember page produce internal server error since we
can't convert MySQL invalid date 0000-00-00 to datetime object and
call strfdate on it.

Additionally, since we assign dates to template variables and after
than assign whole $data hash to template, later assigment overrides
previous one, so we see birth date field even for patrons which don't
have one.

This patch fixes both of those problems.

Test:
1. edit patron and remove it's birth date
2. try to search for it, and verify server error
3. apply patch
4. repeat search for patron and verify that it works and doesn't
   have enpty birth date field

Signed-off-by: Grace McKenzie <[hidden email]>
---
 Koha/Patron.pm        | 3 ++-
 members/moremember.pl | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Koha/Patron.pm b/Koha/Patron.pm
index 3790884..1b9ece4 100644
--- a/Koha/Patron.pm
+++ b/Koha/Patron.pm
@@ -544,7 +544,8 @@ Return the age of the patron
 sub get_age {
     my ($self)    = @_;
     my $today_str = dt_from_string->strftime("%Y-%m-%d");
-    my $dob_str   = dt_from_string( $self->dateofbirth )->strftime("%Y-%m-%d");
+    my $dob_str   = dt_from_string( $self->dateofbirth ) || return;
+    $dob_str      = $dob_str->strftime("%Y-%m-%d");
 
     my ( $dob_y,   $dob_m,   $dob_d )   = split /-/, $dob_str;
     my ( $today_y, $today_m, $today_d ) = split /-/, $today_str;
diff --git a/members/moremember.pl b/members/moremember.pl
index 7330cb9..51012ed 100755
--- a/members/moremember.pl
+++ b/members/moremember.pl
@@ -146,7 +146,7 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) {
         $data->{$_} = '';
         next;
     }
-    $template->param( $_ => dt_from_string( $userdate ) );
+    $data->{$_} = dt_from_string( $userdate );
 }
 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
 
--
2.1.4

_______________________________________________
Koha-patches mailing list
[hidden email]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Koha-patches] [PATCH 2/3] Bug 17933: Add test and return unless defined dob

Dobrica Pavlinusic
From: Jonathan Druart <[hidden email]>

Without this patch get_age return actually 0 instead of

Signed-off-by: Dobrica Pavlinusic <[hidden email]>
---
 Koha/Patron.pm                | 4 ++--
 t/db_dependent/Koha/Patrons.t | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Koha/Patron.pm b/Koha/Patron.pm
index 1b9ece4..28289c5 100644
--- a/Koha/Patron.pm
+++ b/Koha/Patron.pm
@@ -544,8 +544,8 @@ Return the age of the patron
 sub get_age {
     my ($self)    = @_;
     my $today_str = dt_from_string->strftime("%Y-%m-%d");
-    my $dob_str   = dt_from_string( $self->dateofbirth ) || return;
-    $dob_str      = $dob_str->strftime("%Y-%m-%d");
+    return unless $self->dateofbirth;
+    my $dob_str   = dt_from_string( $self->dateofbirth )->strftime("%Y-%m-%d");
 
     my ( $dob_y,   $dob_m,   $dob_d )   = split /-/, $dob_str;
     my ( $today_y, $today_m, $today_d ) = split /-/, $today_str;
diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t
index e5fcba8..8012568 100644
--- a/t/db_dependent/Koha/Patrons.t
+++ b/t/db_dependent/Koha/Patrons.t
@@ -487,13 +487,15 @@ subtest 'checkouts + get_overdues' => sub {
 };
 
 subtest 'get_age' => sub {
-    plan tests => 6;
+    plan tests => 7;
 
     my $patron = $builder->build( { source => 'Borrower' } );
     $patron = Koha::Patrons->find( $patron->{borrowernumber} );
 
     my $today = dt_from_string;
 
+    $patron->dateofbirth( undef );
+    is( $patron->get_age, undef, 'get_age should return undef if no dateofbirth is defined' );
     $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
     is( $patron->get_age, 12, 'Patron should be 12' );
     $patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1 ) );
--
2.1.4

_______________________________________________
Koha-patches mailing list
[hidden email]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Koha-patches] [PATCH 3/3] Bug 17933: Do not instanciate a patron if not needed

Dobrica Pavlinusic
In reply to this post by Dobrica Pavlinusic
From: Jonathan Druart <[hidden email]>

Signed-off-by: Dobrica Pavlinusic <[hidden email]>
---
 members/moremember.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/members/moremember.pl b/members/moremember.pl
index 51012ed..b3e8d76 100755
--- a/members/moremember.pl
+++ b/members/moremember.pl
@@ -242,7 +242,9 @@ my $overdues_exist = 0;
 my $totalprice = 0;
 
 # Calculate and display patron's age
-$template->param( age => Koha::Patron->new({ dateofbirth => $data->{dateofbirth} })->get_age );
+if ( $data->{dateofbirth} ) {
+    $template->param( age => Koha::Patron->new({ dateofbirth => $data->{dateofbirth} })->get_age );
+}
 
 ### ###############################################################################
 # BUILD HTML
--
2.1.4

_______________________________________________
Koha-patches mailing list
[hidden email]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/
Loading...