Skip to content

Commit 82a99d7

Browse files
bramleymarianaballa
authored andcommitted
Try to identify when the import file has a different field delimiter to that entered and allow the file to be reprocessed.
1 parent 229e322 commit 82a99d7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

public_html/lists/admin/import2.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@
170170
$_SESSION['throttle_import'] = !empty($_POST['throttle_import']) ? sprintf('%d', $_POST['throttle_import']) : 0;
171171
}
172172

173+
if (isset($_GET['delimiter'])) {
174+
// Reprocess the file using the selected delimiter
175+
$_SESSION['import_field_delimiter'] = $_GET['delimiter'];
176+
$_SESSION['import_attribute'] = [];
177+
unset($_GET['delimiter']);
178+
}
179+
173180
if (!empty($_GET['confirm'])) {
174181
$_SESSION['test_import'] = '';
175182
}
@@ -354,6 +361,23 @@
354361
}
355362
if ($request_mapping) {
356363
$ls->addButton($GLOBALS['I18N']->get('Continue'), 'javascript:document.importform.submit()');
364+
365+
if (count($headers) == 1) {
366+
// try to identify the actual field delimiter from commonly-used values
367+
if (preg_match('/([,;:|])/', $headers[0], $matches)) {
368+
$delimiter = $matches[1];
369+
$warning = s(
370+
"The file appears to be using '%s' as the field delimiter. Click Resubmit to use '%s' as the delimiter.",
371+
$delimiter,
372+
$delimiter
373+
);
374+
$url = sprintf('import2&delimiter=%s', urlencode($delimiter));
375+
printf('<p class="information">%s</p>%s', $warning, PageLinkButton($url, s('Resubmit')));
376+
} else {
377+
$warning = s('The entered field delimiter might not be correct.');
378+
printf('<p class="information">%s</p>', $warning);
379+
}
380+
}
357381
echo '<p class="information">'.$GLOBALS['I18N']->get('Please identify the target of the following unknown columns').'</p>';
358382
echo '<form name="importform" method="post">';
359383
echo $ls->display();

0 commit comments

Comments
 (0)