From 9a1b93d59f9a133fcb4c212eaf42bc09c504e922 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=UTF-8 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 --- 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 1e7cb61..3db9d8c 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -36,6 +36,7 @@ use C4::ClassSource; use C4::ImportBatch; use C4::Charset; use Koha::BiblioFrameworks; +use Koha::DateUtils; use Date::Calc qw(Today); use MARC::File::USMARC; @@ -294,15 +295,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 28fd247..0a5e147 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.1.4