From 7d5a81132807ea8332d0f0de69a8bc7488538103 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 18 Mar 2024 16:11:25 +0100 Subject: [PATCH] csv_replace & csv_ignore Signed-off-by: Kamil Tekiela --- src/Plugins/Import/ImportCsv.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Plugins/Import/ImportCsv.php b/src/Plugins/Import/ImportCsv.php index 7025945080..9cee17f1f0 100644 --- a/src/Plugins/Import/ImportCsv.php +++ b/src/Plugins/Import/ImportCsv.php @@ -54,6 +54,8 @@ class ImportCsv extends AbstractImportCsv */ private bool $analyze = false; + private bool $replace = false; + private bool $ignore = false; private string $terminated = ''; private string $enclosed = ''; private string $escaped = ''; @@ -163,6 +165,8 @@ class ImportCsv extends AbstractImportCsv public function setImportOptions(ServerRequest $request): void { + $this->replace = $request->getParsedBodyParam('csv_replace') !== null; + $this->ignore = $request->getParsedBodyParam('csv_ignore') !== null; $this->terminated = (string) $request->getParsedBodyParam('csv_terminated'); $this->enclosed = (string) $request->getParsedBodyParam('csv_enclosed'); $this->escaped = (string) $request->getParsedBodyParam('csv_escaped'); @@ -183,9 +187,6 @@ class ImportCsv extends AbstractImportCsv $GLOBALS['message'] ??= null; $GLOBALS['errorUrl'] ??= null; - // $csv_replace and $csv_ignore should have been here, - // but we use directly from $_POST - $replacements = ['\\n' => "\n", '\\t' => "\t", '\\r' => "\r"]; $this->terminated = strtr($this->terminated, $replacements); $this->enclosed = strtr($this->enclosed, $replacements); @@ -523,7 +524,7 @@ class ImportCsv extends AbstractImportCsv } $sql .= ')'; - if (isset($_POST['csv_replace'])) { + if ($this->replace) { $sql .= ' ON DUPLICATE KEY UPDATE '; foreach ($fields as $field) { $fieldName = Util::backquote($field); @@ -738,7 +739,7 @@ class ImportCsv extends AbstractImportCsv $fields = []; if (! $this->analyze && $db !== null && $table !== null) { $sqlTemplate = 'INSERT'; - if (isset($_POST['csv_ignore'])) { + if ($this->ignore) { $sqlTemplate .= ' IGNORE'; }