From aedb878083f9ee321a531a3fec6d358f0f2b7f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sat, 10 Oct 2015 10:03:51 +0200 Subject: [PATCH] [PASSED QA] Bug 14997 - Remove C4::Dates from tools (import / export) This patch removes C4::Dates from: - tools/export.pl - tools/import_borrowers.pl Note: For testing, both need preparation without patch, see below. To test export: - Without patch applied, go to Home > Tools > Export data > Export bibliographic records - Define Start date / End date for Accession dates - Export bibliographic records as 'without-patch.mrc' - Do the same with patch, export as 'with-patch.mrc - Compare the files, they should be the same To test Import patrons: - Without patch - Go to Home > Tools > Import patrons - Create a patron category like 'TEST' (useful for filtering...) - Prepare a file with some patrons with category TEST to import. Fill date of birth, enrolment date, expiry date with values formatted in syspref format, in iso format and garbage - Import - Review the imported patrons (search for category TEST) - With patch: Change cardnumber and names in import file - Import - Review again and compare with results from previous import. Signed-off-by: Mirko Tietgen Signed-off-by: Katrin Fischer --- tools/export.pl | 18 +++++++++++------- tools/import_borrowers.pl | 11 ++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/export.pl b/tools/export.pl index 80a15b4..a674248 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -29,6 +29,7 @@ use C4::Csv; use C4::Koha; # GetItemTypes use C4::Output; use C4::Record; +use Koha::DateUtils; my $query = new CGI; @@ -198,15 +199,18 @@ if ( $op eq "export" ) { my $itemtype = $query->param("itemtype"); my $start_callnumber = $query->param("start_callnumber"); my $end_callnumber = $query->param("end_callnumber"); - $timestamp = ($timestamp) ? C4::Dates->new($timestamp) : '' - if ($commandline); + if ( $commandline ) { + $timestamp = eval { output_pref( { dt => dt_from_string( $timestamp ), dateonly => 1 }); }; + $timestamp = '' unless ( $timestamp ); + } + my $start_accession = ( $query->param("start_accession") ) - ? C4::Dates->new( $query->param("start_accession") ) + ? eval { output_pref( { dt => dt_from_string( $query->param("start_accession") ), dateonly => 1, dateformat => 'iso' } ); } : ''; my $end_accession = ( $query->param("end_accession") ) - ? C4::Dates->new( $query->param("end_accession") ) + ? eval { output_pref( { dt => dt_from_string( $query->param("end_accession") ), dateonly => 1, dateformat => 'iso' } ); } : ''; $dont_export_items = $query->param("dont_export_item") unless ($commandline); @@ -565,7 +569,7 @@ sub construct_query { WHERE $biblioitemstable.timestamp >= ? OR deleteditems.timestamp >= ? ) "; - my $ts = $timestamp->output('iso'); + my $ts = eval { output_pref( { dt => dt_from_string( $timestamp ), dateonly => 1, dateformat => 'iso' }); }; @sql_params = ( $ts, $ts, $ts, $ts ); } else { @@ -618,12 +622,12 @@ sub construct_query { } if ($start_accession) { $sql_query .= " AND dateaccessioned >= ? "; - push @sql_params, $start_accession->output('iso'); + push @sql_params, $start_accession; } if ($end_accession) { $sql_query .= " AND dateaccessioned <= ? "; - push @sql_params, $end_accession->output('iso'); + push @sql_params, $end_accession; } if ($itemtype) { diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index e29a980..1876c88 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -39,7 +39,6 @@ use warnings; use C4::Auth; use C4::Output; -use C4::Dates qw(format_date_in_iso); use C4::Context; use C4::Branch qw/GetBranchesLoop GetBranchName/; use C4::Members; @@ -49,6 +48,7 @@ use C4::Members::Messaging; use C4::Reports::Guided; use C4::Templates; use Koha::Borrower::Debarments; +use Koha::DateUtils; use Text::CSV; # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: @@ -141,11 +141,9 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { } push @feedback, {feedback=>1, name=>'headerrow', value=>join(', ', @csvcolumns)}; - my $today_iso = C4::Dates->new()->output('iso'); + my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); my @criticals = qw(surname branchcode categorycode); # there probably should be others my @bad_dates; # I've had a few. - my $date_re = C4::Dates->new->regexp('syspref'); - my $iso_re = C4::Dates->new->regexp('iso'); LINE: while ( my $borrowerline = <$handle> ) { my %borrower; my @missing_criticals; @@ -211,9 +209,8 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { # Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it. foreach (qw(dateofbirth dateenrolled dateexpiry)) { my $tempdate = $borrower{$_} or next; - if ($tempdate =~ /$date_re/) { - $borrower{$_} = format_date_in_iso($tempdate); - } elsif ($tempdate =~ /$iso_re/) { + $tempdate = eval { output_pref( { dt => dt_from_string( $tempdate ), dateonly => 1, dateformat => 'iso' } ); }; + if ($tempdate) { $borrower{$_} = $tempdate; } else { $borrower{$_} = ''; -- 1.9.1