The delete function is now changed to the new function

This commit is contained in:
Michael 2018-01-17 23:22:01 +00:00
parent 000e6457b4
commit 2d66242b4f
8 changed files with 42 additions and 212 deletions

View file

@ -64,10 +64,18 @@ class Item
return $rows;
}
/**
* @brief Delete an item and notify others about it - if it was ours
*
* @param integer $item_id Item ID that should be delete
*
* @return $boolean success
*/
public static function delete($item_id, $priority = PRIORITY_HIGH)
{
// locate item to be deleted
$item = dba::selectFirst('item', [], ['id' => $item_id]);
$fields = ['id', 'uid', 'parent', 'parent-uri', 'origin', 'deleted', 'file', 'resource-id', 'event-id', 'attach'];
$item = dba::selectFirst('item', $fields, ['id' => $item_id]);
if (!DBM::is_result($item)) {
return false;
}
@ -76,6 +84,11 @@ class Item
return false;
}
$parent = dba::selectFirst('item', ['origin'], ['id' => $item['parent']]);
if (!DBM::is_result($parent)) {
$parent = ['origin' => false];
}
logger('delete item: ' . $item['id'], LOGGER_DEBUG);
// clean up categories and tags so they don't end up as orphans
@ -119,7 +132,7 @@ class Item
}
// When it is our item we don't delete it here, since we have to send delete messages
if ($item['origin'] || $item['wall']) {
if ($item['origin'] || $parent['origin']) {
// Set the item to "deleted"
dba::update('item', ['deleted' => true, 'title' => '', 'body' => '',
'edited' => datetime_convert(), 'changed' => datetime_convert()],
@ -144,21 +157,6 @@ class Item
dba::delete('item', ['id' => $item['id']]);
}
if ($item['id'] != $item['parent']) {
// ensure that last-child is set in case the comment that had it just got wiped.
dba::update('item', ['last-child' => false, 'changed' => datetime_convert()],
['parent' => $item['parent']]);
// who is the last child now?
$r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1",
dbesc($item['parent-uri']),
intval($item['uid'])
);
if (DBM::is_result($r)) {
dba::update('item', ['last-child' => true], ['id' => $r[0]['id']]);
}
}
return true;
}