Page MenuHomeIn-Portal Phabricator

D291.diff
No OneTemporary

File Metadata

Created
Mon, Jan 6, 1:42 AM

D291.diff

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