From dea1ccfe8674df816aa80849c5618854035ebed7 Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sat, 5 Oct 2024 11:14:26 +1000 Subject: [PATCH] Overrides can delete entries by not specifying a replacement field. --- csv-generic/gen-generic.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/csv-generic/gen-generic.php b/csv-generic/gen-generic.php index fcbf907..ccc6cca 100644 --- a/csv-generic/gen-generic.php +++ b/csv-generic/gen-generic.php @@ -122,13 +122,17 @@ foreach ($lga_list as $lga) { foreach ($lines as $line_key => $line) { $match_index = array_search($override['Match Field'], $header); $replace_index = array_search($override['Replace Field'], $header); - if ($line[$match_index] === $override['Match Value']) { - $lines[$line_key][$replace_index] = $override['Replace Value']; + if ($line[$match_index] === $override['Match Value']) { + if ($replace_index !== false) + $lines[$line_key][$replace_index] = $override['Replace Value']; + else /* If 'Replace Field' is not matched - delete this entry */ + $lines[$line_key]['Delete'] = 'y'; } } } foreach ($lines as $line) { + if (isset($line['Delete'])) continue; if (fputcsv($handle, $line) === FALSE) { error_log('Error writing candidate to output file'); exit(3);