Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F726844
D291.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 1:42 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Tue, Jan 7, 1:42 AM (2 d, 12 h ago)
Engine
blob
Format
Raw Data
Handle
536934
Attached To
D291: INP-1685 - Handle date fields during CSV import
D291.diff
View Options
Index: branches/5.2.x/core/units/helpers/csv_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/csv_helper.php
+++ branches/5.2.x/core/units/helpers/csv_helper.php
@@ -61,8 +61,7 @@
$file = fopen($export_data['file_name'], $first_step ? 'w' : 'a');
$prefix_elems = preg_split('/\.|_/', $export_data['prefix'], 2);
- $grids = $this->Application->getUnitOption($prefix_elems[0], 'Grids');
- $grid_config = $grids[$export_data['grid']]['Fields'];
+ $grid_config = $this->getGridColumns($export_data);
$list_params = Array ('per_page' => $export_data['step'], 'grid' => $export_data['grid']);
@@ -214,8 +213,7 @@
fclose($file);
$prefix_elems = preg_split('/\.|_/', $import_data['prefix'], 2);
- $grids = $this->Application->getUnitOption($prefix_elems[0], 'Grids');
- $grid_config = $grids[ $import_data['grid'] ]['Fields'];
+ $grid_config = $this->getGridColumns($import_data);
$field_list = Array();
foreach($grid_config as $field_name => $field_data) {
@@ -303,9 +301,32 @@
}
}
- // 2. set object fields
- foreach($import_data['field_list'] as $position => $field_name) {
- if(isset($data[$position])) {
+ // 2. set object fields.
+ $grid_config = $this->getGridColumns($import_data);
+
+ foreach ( $import_data['field_list'] as $position => $field_name ) {
+ if ( isset($data[$position]) ) {
+ $formatter_class = $object->GetFieldOption($field_name, 'formatter');
+
+ if ( $formatter_class !== false ) {
+ $formatter = $this->Application->recallObject($formatter_class);
+
+ if ( $formatter instanceof kDateFormatter ) {
+ if ( isset($grid_config[$field_name]['format']) ) {
+ $format = $grid_config[$field_name]['format'];
+ }
+ else {
+ $format = $object->GetFieldOption($field_name, 'format');
+ }
+
+ // Use export format during import.
+ $object->SetFieldOption($field_name, 'input_format', $format);
+
+ // Read date/time from single column.
+ $object->SetDBField($field_name . '_combined', 1);
+ }
+ }
+
$object->SetField($field_name, $data[$position]);
}
}
@@ -350,6 +371,21 @@
}
}
+ /**
+ * Returns grid columns.
+ *
+ * @param array $import_data Import data.
+ *
+ * @return array
+ */
+ protected function getGridColumns(array $import_data)
+ {
+ $prefix_elements = preg_split('/\.|_/', $import_data['prefix'], 2);
+ $grids = $this->Application->getUnitOption($prefix_elements[0], 'Grids');
+
+ return $grids[$import_data['grid']]['Fields'];
+ }
+
function ImportData($name)
{
$import_data = unserialize($this->Application->RecallVar('import_data'));
Event Timeline
Log In to Comment