From 03b0c828876a7031e2768598448e195b1b7fe0f7 Mon Sep 17 00:00:00 2001 From: HungryFeline Date: Sat, 6 Jul 2013 00:33:31 +0200 Subject: [PATCH] Better CSV validation When uploading a CSV, check every entry before executing the INSERT. The checks are the same as with the normal add except that no errors are shown. --- ext/alias_editor/main.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 4ef4e565..0173ff05 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -138,7 +138,12 @@ class AliasEditor extends Extension { foreach(explode("\n", $csv) as $line) { $parts = explode(",", $line); if(count($parts) == 2) { - $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", array("oldtag" => $parts[0], "newtag" => $parts[1])); + $pair = array("oldtag" => $parts[0], "newtag" => $parts[1]); + if(!$database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)){ + if(!$database->get_row("SELECT * FROM aliases WHERE oldtag=:newtag", array("newtag" => $pair['newtag']))){ + $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); + } + } } } }