From 5d464c353f2630e2b37a4b4d6afc4565dcd100e6 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sun, 18 Nov 2018 12:43:26 +0100 Subject: [PATCH 1/2] Delete comment from its guid and return to parent guid --- include/items.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/include/items.php b/include/items.php index 87f0a2d4e..0fc8fad60 100644 --- a/include/items.php +++ b/include/items.php @@ -352,7 +352,7 @@ function drop_item($id, $return = '') // locate item to be deleted - $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity']; + $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', parent]; $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]); if (!DBA::isResult($item)) { @@ -408,6 +408,11 @@ function drop_item($id, $return = '') } $is_comment = ($item['gravity'] == GRAVITY_COMMENT) ? true : false; + $parentitem = null; + if (!empty($item['parent'])){ + $fields = ['guid']; + $parentitem = Item::selectFirstForUser(local_user(), $fields, ['id' => $item['parent']]); + } // delete the item Item::deleteForUser(['id' => $item['id']], local_user()); @@ -417,14 +422,23 @@ function drop_item($id, $return = '') // removes update_* from return_url to ignore Ajax refresh $return_url = str_replace("update_", "", $return_url); - // if unknown location or top level post called from display - if (empty($return_url) || ((strpos($return_url, 'display') !== false) AND (!$is_comment))) { - $a->internalRedirect('network'); - //NOTREACHED + // Check if delete a comment + if ($is_comment) { + // Return to parent guid + if (!empty($parentitem)) { + $a->internalRedirect('display/' . $parentitem['guid']); + //NOTREACHED + } } else { - $a->internalRedirect($return_url); - //NOTREACHED + // if unknown location or deleting top level post called from display + if (empty($return_url) || strpos($return_url, 'display') !== false) { + $a->internalRedirect('network'); + //NOTREACHED + } else { + $a->internalRedirect($return_url); + //NOTREACHED + } } } else { notice(L10n::t('Permission denied.') . EOL); From a36a780b99a202f6134a9bdf271dbd83e1f5bda9 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sun, 18 Nov 2018 12:46:21 +0100 Subject: [PATCH 2/2] Add fallback if comment as no parent --- include/items.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/items.php b/include/items.php index 0fc8fad60..b9e1a0c99 100644 --- a/include/items.php +++ b/include/items.php @@ -429,6 +429,11 @@ function drop_item($id, $return = '') $a->internalRedirect('display/' . $parentitem['guid']); //NOTREACHED } + // In case something goes wrong + else { + $a->internalRedirect('network'); + //NOTREACHED + } } else { // if unknown location or deleting top level post called from display