4 * Perform the cleanup task for removing any obsolete images saved by PaintWeb.
8 function paintweb_cron_cleanup () {
11 if (empty($CFG->paintwebImagesFolder
)) {
12 $CFG->paintwebImagesFolder
= 'paintweb_images';
15 $pwtable = 'paintweb_images';
16 $pwfolder = $CFG->dataroot
. '/' . $CFG->paintwebImagesFolder
;
18 // Get the list of tables being tracked, known to have records with images
20 $tables = get_fieldset_select($pwtable, 'DISTINCT(tbl)');
25 // Delete obsolete images in the PaintWeb table.
26 foreach ($tables as $tbl) {
27 delete_records_select($pwtable, "NOT EXISTS (SELECT b.id FROM
28 {$CFG->prefix}$tbl AS b WHERE {$CFG->prefix}$pwtable.tbl='$tbl' AND
29 {$CFG->prefix}$pwtable.rid=b.id)");
32 // Get the list of image file names being tracked in the PaintWeb table.
33 $tblimages = get_fieldset_select($pwtable, 'DISTINCT(img)');
41 // Get the list of image file names inside the physical folder of PaintWeb.
42 $images = glob("*.{png,jpg}", GLOB_BRACE
);
47 // Remove any file which is not in the database.
48 foreach ($images as $img) {
49 if (!in_array($img, $tblimages)) {
58 // vim:set spell spl=en fo=tanqrowcb tw=80 ts=4 sw=4 sts=4 sta et noai nocin fenc=utf-8 ff=unix: