Bug 24134: Add placeholder for 2 digit years to allow autogeneration of dates in 008
authorOwen Leonard <oleonard@myacpl.org>
Mon, 2 Dec 2019 16:42:59 +0000 (16:42 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 13 Aug 2020 05:55:44 +0000 (07:55 +0200)
This patch modifies the code for parsing MARC framework configurations
so that the placeholder "<<YY>>" translates to a two-year date.

To test, apply the patch and modify a framework to include placeholders.
For example, in MARC21:

 - Administration -> MARC structure -> 952 -> Edit subfields -> d
 - Expand "Advanced constraints" and add a default value:
   <<YYYY>> <<YY>> <<MM>> <<DD>> <<USER>>
 - Save your configuration and go to Cataloging.
 - Go to the add/edit items page for a record which uses the framework
   you edited.
 - In the "Add item" form, in the "Date aquired" field, you should see
   the correct values. For example: '2019 19 12 03 Leonard'

Perform the same test when adding an item during the Acquisitions
process (depending on your AcqCreateItem setting).

Note that acqui/neworderempty.pl has been modified because the
placeholder-replacement code is repeated there, but I couldn't discover
how to test it (if it is used at all?)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Items.pm
acqui/neworderempty.pl
cataloguing/addbiblio.pl
cataloguing/additem.pl

index f2db7a4..22ac2de 100644 (file)
@@ -1608,6 +1608,23 @@ sub PrepareItemrecordDisplay {
                     $defaultvalue = q||;
                 } else {
                     $defaultvalue =~ s/"/&quot;/g;
+                    # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+                    my $today_dt = dt_from_string;
+                    my $year     = $today_dt->strftime('%Y');
+                    my $shortyear     = $today_dt->strftime('%y');
+                    my $month    = $today_dt->strftime('%m');
+                    my $day      = $today_dt->strftime('%d');
+                    $defaultvalue =~ s/<<YYYY>>/$year/g;
+                    $defaultvalue =~ s/<<YY>>/$shortyear/g;
+                    $defaultvalue =~ s/<<MM>>/$month/g;
+                    $defaultvalue =~ s/<<DD>>/$day/g;
+
+                    # And <<USER>> with surname (?)
+                    my $username =
+                      (   C4::Context->userenv
+                        ? C4::Context->userenv->{'surname'}
+                        : "superlibrarian" );
+                    $defaultvalue =~ s/<<USER>>/$username/g;
                 }
 
                 my $maxlength = $tagslib->{$tag}->{$subfield}->{maxlength};
index dfa9ebe..d9505d1 100755 (executable)
@@ -228,12 +228,14 @@ if ( not $ordernumber ) {    # create order
 
                 if ( $value ) {
 
-                    # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+                    # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
                     my $today_dt = dt_from_string;
                     my $year     = $today_dt->strftime('%Y');
+                    my $shortyear = $today_dt->strftime('%y');
                     my $month    = $today_dt->strftime('%m');
                     my $day      = $today_dt->strftime('%d');
                     $value =~ s/<<YYYY>>/$year/g;
+                    $value =~ s/<<YY>>/$shortyear/g;
                     $value =~ s/<<MM>>/$month/g;
                     $value =~ s/<<DD>>/$day/g;
 
index 7d48842..4bbf81d 100755 (executable)
@@ -279,12 +279,14 @@ sub create_input {
     if ( $value eq '' ) {
         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{};
 
-        # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+        # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
         my $today_dt = dt_from_string;
         my $year = $today_dt->strftime('%Y');
+        my $shortyear = $today_dt->strftime('%y');
         my $month = $today_dt->strftime('%m');
         my $day = $today_dt->strftime('%d');
         $value =~ s/<<YYYY>>/$year/g;
+        $value =~ s/<<YY>>/$shortyear/g;
         $value =~ s/<<MM>>/$month/g;
         $value =~ s/<<DD>>/$day/g;
         # And <<USER>> with surname (?)
index 001d9d8..bbdedf6 100755 (executable)
@@ -132,12 +132,14 @@ sub generate_subfield_form {
         if ( ! defined( $value ) || $value eq '')  {
             $value = $subfieldlib->{defaultvalue};
             if ( $value ) {
-                # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
+                # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
                 my $today_dt = dt_from_string;
                 my $year = $today_dt->strftime('%Y');
+                my $shortyear = $today_dt->strftime('%y');
                 my $month = $today_dt->strftime('%m');
                 my $day = $today_dt->strftime('%d');
                 $value =~ s/<<YYYY>>/$year/g;
+                $value =~ s/<<YY>>/$shortyear/g;
                 $value =~ s/<<MM>>/$month/g;
                 $value =~ s/<<DD>>/$day/g;
                 # And <<USER>> with surname (?)