From 3f50f537790858fb1da6e9332c662d50b8e3aa2b Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Fri, 20 Nov 2009 13:56:27 +0200 Subject: [PATCH] Fixes to the PaintWeb cron task. Made changes as suggested by Martin Langhoff. Thanks for the review! --- admin/cron.php | 1 + admin/cron_paintweb.php | 44 ++++++++++++++------------------------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/admin/cron.php b/admin/cron.php index 2c694885c2e..5ec96a4457d 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -387,6 +387,7 @@ // Run the clean-up task of PaintWeb. mtrace("Starting the PaintWeb images clean-up task..."); include_once("$CFG->dirroot/admin/cron_paintweb.php"); + paintweb_cron_cleanup(); mtrace("done."); if (empty($CFG->disablescheduledbackups)) { // Defined in config.php diff --git a/admin/cron_paintweb.php b/admin/cron_paintweb.php index 1fa2b76f7b7..70346127f22 100644 --- a/admin/cron_paintweb.php +++ b/admin/cron_paintweb.php @@ -1,9 +1,5 @@ prefix}$pwtable"); - + $tables = get_fieldset_select($pwtable, 'DISTINCT(tbl)'); if (!$tables) { $tables = array(); } - foreach ($tables as $tbl => $tobj) { - // Find obsolete images in the PaintWeb table. - $ids = get_records_sql("SELECT a.id FROM {$CFG->prefix}$pwtable AS a - LEFT OUTER JOIN {$CFG->prefix}$tbl as b ON a.rid=b.id WHERE - a.tbl='$tbl' AND b.id IS NULL"); - - if (empty($ids)) { - continue; - } - - // Delete the obsolete images from the PaintWeb table. - $where = ''; - foreach ($ids as $id => $obj) { - $where .= " OR id=$id"; - } - if (!empty($where)) { - $where = substr($where, 4); - delete_records_select($pwtable, $where); - } + // Delete obsolete images in the PaintWeb table. + foreach ($tables as $tbl) { + delete_records_select($pwtable, "NOT EXISTS (SELECT b.id FROM + {$CFG->prefix}$tbl AS b WHERE {$CFG->prefix}$pwtable.tbl='$tbl' AND + {$CFG->prefix}$pwtable.rid=b.id)"); } // Get the list of image file names being tracked in the PaintWeb table. - $tblimages = get_records_sql("SELECT DISTINCT(img) FROM - {$CFG->prefix}$pwtable"); + $tblimages = get_fieldset_select($pwtable, 'DISTINCT(img)'); + if (!$tblimages) { + $tblimages = array(); + } $cwd = getcwd(); chdir($pwfolder); // Get the list of image file names inside the physical folder of PaintWeb. $images = glob("*.{png,jpg}", GLOB_BRACE); + if (!$images) { + $images = array(); + } // Remove any file which is not in the database. foreach ($images as $img) { - if (!isset($tblimages[$img])) { + if (!in_array($img, $tblimages)) { unlink($img); } } @@ -69,7 +54,6 @@ function paintweb_cron_cleanup () { chdir($cwd); } -paintweb_cron_cleanup(); // vim:set spell spl=en fo=tanqrowcb tw=80 ts=4 sw=4 sts=4 sta et noai nocin fenc=utf-8 ff=unix: -- 2.11.4.GIT