[pmg-devel] [PATCH pmg-api 2/3] close #2075: do not insert empty WL/BL

Dominik Csapak d.csapak at proxmox.com
Tue Feb 26 09:12:35 CET 2019


so that they do not appear in the list of users

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PMG/Quarantine.pm | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/PMG/Quarantine.pm b/PMG/Quarantine.pm
index c0455ab..77af8cc 100644
--- a/PMG/Quarantine.pm
+++ b/PMG/Quarantine.pm
@@ -69,12 +69,18 @@ sub add_to_blackwhite {
 		if length($blist) > $maxlen;
 	}
 
-	$dbh->do(
-	    "DELETE FROM UserPrefs WHERE pmail = $qu AND (Name = 'WL' OR Name = 'BL');" .
+	my $queries = "DELETE FROM UserPrefs WHERE pmail = $qu AND (Name = 'WL' OR Name = 'BL');";
+	if (scalar(keys %{$list->{WL}})) {
+	    $queries .=
 	    "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
-	    "VALUES ($qu, 'BL', $blist, EXTRACT (EPOCH FROM now()));" .
+	    "VALUES ($qu, 'WL', $wlist, EXTRACT (EPOCH FROM now()));";
+	}
+	if (scalar(keys %{$list->{BL}})) {
+	    $queries .=
 	    "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
-	    "VALUES ($qu, 'WL', $wlist, EXTRACT (EPOCH FROM now()));");
+	    "VALUES ($qu, 'BL', $blist, EXTRACT (EPOCH FROM now()));";
+	}
+	$dbh->do($queries);
     }
 
     my $values =  [ keys %{$list->{$name}} ];
-- 
2.11.0




More information about the pmg-devel mailing list