From 9cfd70474f67037977f98f0e0e2cb3505f6446f3 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 6 Oct 2008 23:08:11 +0000 Subject: feature 884 added: ability to delete photos uploaded via web API method pwg.images.add, ie without storage_category_id. pLoader uses this method and photos cannot be removed in any other way. git-svn-id: http://piwigo.org/svn/trunk@2678 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'admin/include/functions.php') diff --git a/admin/include/functions.php b/admin/include/functions.php index 932578963..4b0713226 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -127,7 +127,7 @@ DELETE FROM '.OLD_PERMALINKS_TABLE.' // - all the comments related to elements // - all the links between categories and elements // - all the favorites associated to elements -function delete_elements($ids) +function delete_elements($ids, $physical_deletion=false) { if (count($ids) == 0) { @@ -135,6 +135,45 @@ function delete_elements($ids) } trigger_action('begin_delete_elements', $ids); + if ($physical_deletion) + { + include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); + + // we can currently delete physically only photo with no + // storage_category_id (added via pLoader) + // + // we assume that the element is a photo, with no representative + $query = ' +SELECT + id, + path, + tn_ext, + has_high + FROM '.IMAGES_TABLE.' + WHERE id IN ('.implode(',', $ids).') + AND storage_category_id IS NULL +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_assoc($result)) + { + $file_path = $row['path']; + $thumbnail_path = get_thumbnail_path($row); + $high_path = null; + if (isset($row['has_high']) and get_boolean($row['has_high'])) + { + $high_path = get_high_path($row); + } + + foreach (array($file_path, $thumbnail_path, $high_path) as $path) + { + if (isset($path) and !unlink($path)) + { + die('"'.$path.'" cannot be removed'); + } + } + } + } + // destruction of the comments on the image $query = ' DELETE FROM '.COMMENTS_TABLE.' -- cgit v1.2.3