From 8e488e291347857407dbedaf05d63941701d82d2 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 14 Dec 2020 21:56:19 +0000 Subject: handle removal of terms in attach_delete() when deleting a ressource --- Zotlabs/Module/Attach_edit.php | 11 +---------- include/attach.php | 8 +++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Module/Attach_edit.php b/Zotlabs/Module/Attach_edit.php index 0a41dbb22..667a0b7aa 100644 --- a/Zotlabs/Module/Attach_edit.php +++ b/Zotlabs/Module/Attach_edit.php @@ -110,15 +110,7 @@ class Attach_edit extends Controller { if ($delete) { attach_delete($channel_id, $resource, $is_photo); - - q("DELETE FROM term WHERE uid = %d AND oid = %d AND otype = %d", - intval($channel_id), - intval($attach_id), - intval(TERM_OBJ_FILE) - ); - $actions_done .= 'delete,'; - } if ($copy) { @@ -161,9 +153,8 @@ class Attach_edit extends Controller { store_item_tag($channel_id, $attach_id, TERM_OBJ_FILE, TERM_CATEGORY, $term, $term_link); } } + $actions_done .= 'cat_add,'; } - $actions_done .= 'cat_add,'; - } else { q("DELETE FROM term WHERE uid = %d AND oid = %d AND otype = %d", diff --git a/include/attach.php b/include/attach.php index 515de9b4d..7ef5c4d0e 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1432,7 +1432,7 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { $channel_address = (($c) ? $c[0]['channel_address'] : 'notfound'); $photo_sql = (($is_photo) ? " and is_photo = 1 " : ''); - $r = q("SELECT hash, os_storage, flags, is_dir, is_photo, folder FROM attach WHERE hash = '%s' AND uid = %d $photo_sql limit 1", + $r = q("SELECT id, hash, os_storage, flags, is_dir, is_photo, folder FROM attach WHERE hash = '%s' AND uid = %d $photo_sql limit 1", dbesc($resource), intval($channel_id) ); @@ -1453,6 +1453,12 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { return; } + q("DELETE FROM term WHERE uid = %d AND oid = %d AND otype = %d", + intval($channel_id), + intval($r[0]['id']), + intval(TERM_OBJ_FILE) + ); + // If resource is a directory delete everything in the directory recursive if(intval($r[0]['is_dir'])) { $x = q("SELECT hash, os_storage, is_dir, flags FROM attach WHERE folder = '%s' AND uid = %d", -- cgit v1.2.3