From edfcf4521a4bd8b55435f4fb7b39d11cd8fc2522 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 12 Feb 2022 12:24:09 +0000 Subject: [PATCH] Prevent misleading warning being printed to the lighttpd error log when attempting to flush tables that don't actually exist Signed-off-by: Adam Warner --- scripts/pi-hole/php/teleporter.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index 0e9740f20..774d10c7f 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -84,11 +84,15 @@ function archive_restore_table($file, $table, $flush=false) if(is_null($contents)) return 0; - // Flush table if requested, only flush each table once + // Flush table if requested. Only flush each table once, and only if it exists if($flush && !in_array($table, $flushed_tables)) { - $db->exec("DELETE FROM \"".$table."\""); - array_push($flushed_tables, $table); + $tableExists = $db->querySingle("SELECT name FROM sqlite_master WHERE type='table' AND name='".$table."';"); + if ($tableExists) + { + $db->exec("DELETE FROM \"".$table."\""); + array_push($flushed_tables, $table); + } } // Prepare fields depending on the table we restore to