From caea9951a3d30fc8e6d098c59005866dc15f8e4e Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Thu, 10 Oct 2013 20:28:18 +0200 Subject: [PATCH] Don't delete existing downloads --- lib/update_downloads.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/update_downloads.php b/lib/update_downloads.php index 89cde5c..26638dc 100755 --- a/lib/update_downloads.php +++ b/lib/update_downloads.php @@ -3,15 +3,30 @@ define("SITE_ROOT", realpath(dirname(__file__) . "/..")); require_once SITE_ROOT . "/lib/init.php"; + +function get_downloads() +{ + global $DB; + + $ret = array(); + + if (!$res = $DB->query("select file_name from downloads")) return; + + while ($row = $DB->fetchRow($res)) { + $ret[] = $row["file_name"]; + } + + return $ret; +} + +$all_downloads = get_downloads(); $sync = array("bz2", "log", "exe", "dmg"); -$DB->query("begin"); -$DB->query("delete from downloads"); if ($dh = opendir(SITE_ROOT)) { while (($file = readdir($dh)) !== false) { $ext = pathinfo($file, PATHINFO_EXTENSION); - if (in_array($ext, $sync)) { + if (in_array($ext, $sync) && !in_array($file, $all_downloads)) { $q = kl_str_sql("insert into downloads(file_name) values (!s)", $file); $DB->query($q); } @@ -19,4 +34,4 @@ if ($dh = opendir(SITE_ROOT)) { closedir($dh); } -$DB->query("commit"); + \ No newline at end of file