Bug 14998: Remove C4::Dates from installer and maintenance folders
authorMarc Véron <veron@veron.ch>
Sat, 10 Oct 2015 09:38:20 +0000 (11:38 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 11 Nov 2015 14:07:20 +0000 (11:07 -0300)
- installer/data/mysql/updatedatabase.pl
- misc/maintenance/fix_accountlines_date.pl

To test for updatedatabase.pl

- perl installer/data/mysql/updatedatabase.pl
- review code. Difficult to test, because the code affects
  $DBversion = '3.03.00.035'

To test for misc/maintenance/fix_accountlines_date.pl
 - review code
 - The file seems to be a file used for an update, could it be obsolete?
   If yes, remove it in a follow-up

Signed-off-by: Frederic Demians <f.demians@tamil.fr>
  Code OK. Tested updatedatabase.pl with an old DB backup: OK.
  fix_accountlines_date.pl still working after the patch. Could be removed from
  master IMO.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

installer/data/mysql/updatedatabase.pl
misc/maintenance/fix_accountlines_date.pl

index b66371a..79f6062 100755 (executable)
@@ -36,9 +36,9 @@ use Getopt::Long;
 # Koha modules
 use C4::Context;
 use C4::Installer;
-use C4::Dates;
 use Koha::Database;
 use Koha;
+use Koha::DateUtils;
 
 use MARC::Record;
 use MARC::File::XML ( BinaryEncoding => 'utf8' );
@@ -4170,10 +4170,10 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE `issuingrules` ADD hardduedatecompare tinyint NOT NULL default 0 AFTER hardduedate");
     my $duedate;
     if (C4::Context->preference("globalDueDate")) {
-      $duedate = C4::Dates::format_date_in_iso(C4::Context->preference("globalDueDate"));
+      $duedate = eval { output_pref( { dt => dt_from_string( C4::Context->preference("globalDueDate") ), dateonly => 1, dateformat => 'iso' } ); };
       $dbh->do("UPDATE `issuingrules` SET hardduedate = '$duedate', hardduedatecompare = 0");
     } elsif (C4::Context->preference("ceilingDueDate")) {
-      $duedate = C4::Dates::format_date_in_iso(C4::Context->preference("ceilingDueDate"));
+      $duedate = eval { output_pref( { dt => dt_from_string( C4::Context->preference("ceilingDueDate") ), dateonly => 1, dateformat => 'iso' } ); };
       $dbh->do("UPDATE `issuingrules` SET hardduedate = '$duedate', hardduedatecompare = -1");
     }
     $dbh->do("DELETE FROM `systempreferences` WHERE variable = 'globalDueDate' OR variable = 'ceilingDueDate'");
index 896edfa..e0c97f6 100755 (executable)
@@ -27,9 +27,9 @@ BEGIN {
 }
 
 use C4::Context;
-use C4::Dates;
 use Getopt::Long;
 use Pod::Usage;
+use Koha::DateUtils;
 
 =head1 NAME
 
@@ -146,16 +146,16 @@ while (my $accountline = $sth->fetchrow_hashref) {
 
     if ($mode eq 'us') {
         if ($description =~ /$US_DATE/) { # mm/dd/yyyy
-            my $date = C4::Dates->new($1, 'us');
-            print "Converting $1 (us) to " . $date->output() . "\n" if $DEBUG;
-            $description =~ s/$US_DATE/$date->output()/;
+            my $date = eval { output_pref( { dt => dt_from_string( $1 ), dateonly => 1, dateformat => 'us' } ); };
+            print "Converting $1 (us) to " . $date . "\n" if $DEBUG;i
+            $description =~ s/$US_DATE/$date/;
             $updated = 1;
         }
     } elsif ($mode eq 'metric') {
         if ($description =~ /$METRIC_DATE/) { # dd/mm/yyyy
-            my $date = C4::Dates->new($1, 'metric');
-            print "Converting $1 (metric) to " . $date->output() . "\n" if $DEBUG;
-            $description =~ s/$METRIC_DATE/$date->output()/;
+            my $date = eval { output_pref( { dt => dt_from_string( $1 ), dateonly => 1, dateformat => 'metric' } ); };
+            print "Converting $1 (metric) to " . $date . "\n" if $DEBUG;
+            $description =~ s/$METRIC_DATE/$date/;
             $updated = 2;
         }
     }