Loading...
 
Skip to main content

Tracker Import from csv does not set created and lastModif properly

Status
Closed
Subject
Tracker Import from csv does not set created and lastModif properly
Version
3.x
4.x
5.x
6.x
7.x
8.x
9.x
Category
  • Usability
Feature
Trackers
Import-Export
Resolution status
Fix on the Way
Submitted by
Beestje
Lastmod by
Uwe Altmann
Rating
(0)
Description

Importing tracker items through CSV only sets the created and lastModif value properly if the dates from the CSV file are in the numerical php date format.

When you import a csv file where the created and lastModif dates are written as proper dates, the imported tracker items have a created and lastModif date/timestamp of the date & time of the import action.

example csv :

"itemId","status","created","lastModif","VRID — 265"
"849","o","07/12/2009 13:24","07/12/2009 13:24","4"

Whenever I export a csv file, it contains the dates as shown above, so you can't just export data and import data on the fly without modifying all the values...

c.f. bug 3500

Workaround

in lib/trackers/trackerlib.php starting at line 1627

replace the following code

incorrect code
Copy to clipboard
for ($i = 0; $i < $max; $i++) { if ($encoding == 'ISO-8859-1') { $data[$i] = utf8_encode($data[$i]); } if ($header[$i] == 'status') { if ($data[$i] == 'o' || $data[$i] =='p' || $data[$i] == 'c') $status = $data[$i]; } elseif ($header[$i] == 'itemId') { $itemId = $data[$i]; } elseif ($header[$i] == 'created' && is_numeric($data[$i])) { $created = $data[$i]; } elseif ($header[$i] == 'lastModif' && is_numeric($data[$i])) { $lastModif = $data[$i]; } elseif ($header[$i] == 'categs') { // for old compatibility $cats = split(',',trim($data[$i])); } }


With the following code :

Correct Code
Copy to clipboard
for ($i = 0; $i < $max; $i++) { if ($encoding == 'ISO-8859-1') { $data[$i] = utf8_encode($data[$i]); } if ($header[$i] == 'status') { if ($data[$i] == 'o' || $data[$i] =='p' || $data[$i] == 'c') $status = $data[$i]; } elseif ($header[$i] == 'itemId') { $itemId = $data[$i]; } elseif ($header[$i] == 'created') || ($header[$i] == 'lastModif') { if (is_numeric($data[$i]) { // If created is numeric, datetime is in php format if ($header[$i] == 'created') { $created = $data[$i]; } else { $lastModif = $data[$i]; } } else { // date time needs to be converted to php format $l = strlen($data[$i]); switch ($l) { case ($l == 10): # Field does not contain the time if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } break; case ($l == 16): # Field contains HH:MM list($fd, $ft) = explode(' ', $data[$i]); list($hh, $mm) = explode(':', $ft); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } break; case ($l == 19): # Field contains HH:MM:SS list($fd, $ft) = explode(' ', $data[$i]); list($hh, $mm, $ss) = explode(':', $ft); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } break; } if ($header[$i] == 'created') { $created = $data[$i]; } else { $lastModif = $data[$i]; } } } elseif ($header[$i] == 'categs') { // for old compatibility $cats = split(',',trim($data[$i])); } }
Importance
7
Priority
35
Demonstrate Bug on Tiki 19+
Please demonstrate your bug on show2.tiki.org
Demonstrate Bug (older Tiki versions)
Ticket ID
4176
Created
Wednesday 29 February, 2012 15:06:53 UTC
by Beestje
LastModif
Saturday 12 January, 2013 19:10:37 UTC


Collapse/expand modules below
Show PHP error messages