From 55aaea83d127822b257bcb47876d7443a5ffd135 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Mon, 22 Jul 2013 12:39:48 -0700 Subject: [PATCH] LP#1418772: Avoid internal server error on viewing full record when copy create_date is null In the TPAC client, when it tries to show record details containing a copy record with no create date, it shows an Internal Server Error instead. 1. The error is caused by trying to execute the parse_datetime() method in the parse_date() function in the WWW/EGCatLoader/util.pm module with an empty date string. The function will normally translate a datetime string from the database to a datetime string that is formatted for TPAC templates. The fix is to not execute parse_datetime() and just return an empty string. 2. In the record/copy_table.tt2 template, if an empty datetime string is the value for copy_info.create_date, the format() method of the Date plugin will show the current datetime by default. The fix is to show '-' in its place, replicating the same template logic as for copy_info.due_date. Signed-off-by: Jeff Davis Conflicts: Open-ILS/src/templates/opac/parts/record/copy_table.tt2 Signed-off-by: Galen Charlton --- .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 3 +++ .../opac/parts/record/copy_table.tt2 | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 05f59d8bff..4ff0a1a657 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -195,6 +195,9 @@ sub init_ro_object_cache { $ro_object_subs->{parse_datetime} = sub { my $date = shift; + # Calling parse_datetime() with empty $date will lead to Internal Server Error + return '' if ($date eq '' or $date eq undef); + # Probably an accidental entry like '0212' instead of '2012', # but 1) the leading 0 may get stripped in cstore and # 2) DateTime::Format::ISO8601 returns an error as years diff --git a/Open-ILS/src/templates/opac/parts/record/copy_table.tt2 b/Open-ILS/src/templates/opac/parts/record/copy_table.tt2 index 74059d03cf..1c09536c67 100644 --- a/Open-ILS/src/templates/opac/parts/record/copy_table.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/copy_table.tt2 @@ -142,16 +142,21 @@ END; # FOREACH bib ctx.get_crahp(copy_info.age_protect).name : l('None') | html %] [% - IF ctx.get_org_setting(copy_info.circ_lib, 'circ.holds.age_protect.active_date') == 1; - disp_date = copy_info.active_date ? copy_info.active_date : copy_info.create_date; - ELSE; - disp_date = copy_info.create_date; - END; + IF ctx.get_org_setting(copy_info.circ_lib, 'circ.holds.age_protect.active_date') == 1; + disp_date = copy_info.active_date ? copy_info.active_date : copy_info.create_date; + ELSE; + disp_date = copy_info.create_date; + END; - date.format( - ctx.parse_datetime(disp_date), - DATE_FORMAT - ) %] + IF disp_date; + date.format( + ctx.parse_datetime(disp_date), + DATE_FORMAT + ); + ELSE; + '-'; + END; + %] [% END # is_staff %] [% IF ctx.is_staff OR serial_holdings %] [% # Show copy/volume hold links to staff (without -- 2.43.2