[Koha-patches] [PATCH] [SIGNED-OFF] Bug 7045: Default-value behavior inconsistency

Nicole C. Engard nengard at bywatersolutions.com
Sat Oct 15 06:16:41 CEST 2011


From: D Ruth Bavousett <ruth at bywatersolutions.com>

This patch will allow for YY as well as YYYY substitutions on framework default values, and
changes the substitution of 'user' for the username to require USER.

It also will now allow USER in item fields.

Signed-off-by: Nicole C. Engard <nengard at bywatersolutions.com>

Test Plan:

1. Edit 952 in one framework to include 4 defaults, YYYY-MM-DD,
MM/DD/YY, USER, and user (in any fields)
2. Edit bib fields (I chose 5xx fields) with the same 4 values
3. Catalog using those frameworks and see if the values
populate properly

Note:

USER enters the logged in User's last name only, not their username
or their full name.
---
 cataloguing/addbiblio.pl |    4 +++-
 cataloguing/additem.pl   |    8 +++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index ee0662a..e180c82 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -307,13 +307,15 @@ sub create_input {
 
         # get today date & replace YYYY, MM, DD if provided in the default value
         my ( $year, $month, $day ) = Today();
+        my $shortyear = substr $year, 2, 2;
         $month = sprintf( "%02d", $month );
         $day   = sprintf( "%02d", $day );
         $value =~ s/YYYY/$year/g;
+        $value =~ s/YY/$shortyear/g;
         $value =~ s/MM/$month/g;
         $value =~ s/DD/$day/g;
         my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");    
-        $value=~s/user/$username/g;
+        $value=~s/USER/$username/g;
     
     }
     my $dbh = C4::Context->dbh;
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 6229f0c..9fe22b7 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -33,6 +33,7 @@ use C4::ClassSource;
 use C4::Dates;
 use List::MoreUtils qw/any/;
 
+use Date::Calc qw(Today);
 use MARC::File::XML;
 use URI::Escape;
 
@@ -124,10 +125,15 @@ sub generate_subfield_form {
         if ( ! defined( $value ) || $value eq '')  {
             $value = $subfieldlib->{defaultvalue};
             # get today date & replace YYYY, MM, DD if provided in the default value
-            my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
+            my ( $year, $month, $day ) = Today();
+            my $shortyear = substr $year, 2, 2;
             $value =~ s/YYYY/$year/g;
+            $value =~ s/YY/$shortyear/g;
             $value =~ s/MM/$month/g;
             $value =~ s/DD/$day/g;
+            my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
+            $value=~s/USER/$username/g;
+
         }
         
         $subfield_data{visibility} = "display:none;" if (($subfieldlib->{hidden} > 4) || ($subfieldlib->{hidden} < -4));
-- 
1.7.2.3



More information about the Koha-patches mailing list