From 81399156f8aaeea0d3fff7877731cd8d89e615d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Aug 2016 09:09:53 +0100 Subject: [PATCH] Bug 7045: Use <> for default value placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When adding a biblio, the default value of a MARC subfield defined in the frameworks can be used as placeholders to set the current date or the surname of the logged in user (use cases?). The different placeholders are 'YYYY', 'MM', 'DD', 'user'. When adding an item, same behavior except that 'user' is not replaced. This patch makes behaviors consistent between the 2 editors and surrounds placeholders with << >> We will now have: <>, <>, <
> and <> Test plan: Define default values for biblio and item subfields. Create a bibliographic record and attach it an item. The default values should be used and replaced if you used placeholders. Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall (cherry picked from commit 50abf24ff04aae0c9010411fa6e98561c2ccc66f) Signed-off-by: Frédéric Demians (cherry picked from commit 60ab0769530c190dcd849f15909eed4961aa8a83) Signed-off-by: Julian Maurice --- cataloguing/addbiblio.pl | 21 ++++++++++++--------- cataloguing/additem.pl | 17 +++++++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 67d18caaf0..d366209ac7 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -35,6 +35,7 @@ use C4::Branch; # XXX subfield_is_koha_internal_p use C4::ClassSource; use C4::ImportBatch; use C4::Charset; +use Koha::DateUtils; use Date::Calc qw(Today); use MARC::File::USMARC; @@ -293,15 +294,17 @@ sub create_input { if ( $value eq '' ) { $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; - # get today date & replace YYYY, MM, DD if provided in the default value - my ( $year, $month, $day ) = Today(); - $month = sprintf( "%02d", $month ); - $day = sprintf( "%02d", $day ); - $value =~ s/YYYY/$year/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; + # get today date & replace <>, <>, <
> if provided in the default value + my $today_dt = dt_from_string; + my $year = $today_dt->year; + my $month = $today_dt->month; + my $day = $today_dt->day; + $value =~ s/<>/$year/g; + $value =~ s/<>/$month/g; + $value =~ s/<
>/$day/g; + # And <> with surname (?) + my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); + $value=~s/<>/$username/g; } my $dbh = C4::Context->dbh; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index b896b0bed6..b9e44c404e 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -128,12 +128,17 @@ sub generate_subfield_form { $value =~ s/"/"/g; if ( ! defined( $value ) || $value eq '') { $value = $subfieldlib->{defaultvalue}; - # get today date & replace YYYY, MM, DD if provided in the default value - my $today_iso = output_pref( { dt=>dt_from_string, dateonly => 1, dateformat => 'iso' } ); - my ( $year, $month, $day ) = split ('-', $today_iso); - $value =~ s/YYYY/$year/g; - $value =~ s/MM/$month/g; - $value =~ s/DD/$day/g; + # get today date & replace <>, <>, <
> if provided in the default value + my $today_dt = dt_from_string; + my $year = $today_dt->year; + my $month = $today_dt->month; + my $day = $today_dt->day; + $value =~ s/<>/$year/g; + $value =~ s/<>/$day/g; + # And <> with surname (?) + my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); + $value=~s/<>/$username/g; } $subfield_data{visibility} = "display:none;" if (($subfieldlib->{hidden} > 4) || ($subfieldlib->{hidden} <= -4)); -- 2.39.5