$ret = api_statuses_show($type);
- Item::deleteById($id, PRIORITY_HIGH, api_user());
+ Item::deleteForUser(['id' => $id], api_user());
return $ret;
}
if (!DBM::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
- Item::deleteById($photo_item[0]['id'], PRIORITY_HIGH, api_user());
+ Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
}
// now let's delete all photos from the album
}
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
// to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
- Item::deleteById($photo_item[0]['id'], PRIORITY_HIGH, api_user());
+ Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
$answer = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.'];
return api_format_data("photo_delete", $type, ['$result' => $answer]);
if (count($items)) {
foreach ($items as $item) {
- $owner = Item::deleteById($item, PRIORITY_HIGH, local_user());
+ $owner = Item::deleteForUser(['id' => $item], local_user());
if ($owner && !$uid)
$uid = $owner;
}
}
// delete the item
- Item::deleteById($item['id'], PRIORITY_HIGH, local_user());
+ Item::deleteForUser(['id' => $item['id']], local_user());
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
//NOTREACHED
if (strpos($guid, '/')) {
$guid = substr($guid, strrpos($guid, '/') + 1);
}
- // Now that we have the GUID get all IDs of the associated entries in the
- // item table of the DB and drop those items, which will also delete the
+ // Now that we have the GUID, drop those items, which will also delete the
// associated threads.
- $r = dba::select('item', ['id'], ['guid' => $guid]);
- while ($row = dba::fetch($r)) {
- Item::deleteById($row['id']);
- }
- dba::close($r);
+ Item::delete(['guid' => $guid]);
}
info(L10n::t('Item marked for deletion.') . EOL);
// Delete only real events (no birthdays)
if (DBM::is_result($ev) && $ev[0]['type'] == 'event') {
- $del = Item::deleteById($ev[0]['itemid'], PRIORITY_HIGH, local_user());
+ $del = Item::deleteForUser(['id' => $ev[0]['itemid']], local_user());
}
if ($del == 0) {
$o = '';
if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
if (is_ajax()) {
- $o = Item::deleteById($a->argv[2], PRIORITY_HIGH, local_user());
+ $o = Item::deleteForUser(['id' => $a->argv[2]], local_user());
} else {
$o = drop_item($a->argv[2]);
}
);
// find and delete the corresponding item with all the comments and likes/dislikes
- $r = q("SELECT `id` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
- intval($page_owner_uid)
- );
- if (DBM::is_result($r)) {
- foreach ($r as $rr) {
- Item::deleteById($rr['id'], PRIORITY_HIGH, $page_owner_uid);
- }
- }
+ Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
// Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid);
intval($page_owner_uid),
dbesc($r[0]['resource-id'])
);
- $i = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($r[0]['resource-id']),
- intval($page_owner_uid)
- );
- if (DBM::is_result($i)) {
- Item::deleteById($i[0]['id'], PRIORITY_HIGH, $page_owner_uid);
- // Update the photo albums cache
- Photo::clearAlbumCache($page_owner_uid);
- }
+ Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
+
+ // Update the photo albums cache
+ Photo::clearAlbumCache($page_owner_uid);
}
goaway('photos/' . $a->data['user']['nickname']);
);
if (DBM::is_result($i)) {
- Item::deleteById($i[0]['id'], PRIORITY_HIGH, local_user());
+ Item::deleteForUser(['id' => $i[0]['id']], local_user());
}
}
*
* @param array $condition The condition for finding the item entries
* @param integer $priority Priority for the notification
- * @param integer $uid User who wants to delete the item
*/
- public static function delete($condition, $priority = PRIORITY_HIGH, $uid = 0)
+ public static function delete($condition, $priority = PRIORITY_HIGH)
{
$items = dba::select('item', ['id'], $condition);
while ($item = dba::fetch($items)) {
- self::deleteById($item['id'], $priority, $uid);
+ self::deleteById($item['id'], $priority);
+ }
+ dba::close($items);
+ }
+
+ /**
+ * @brief Delete an item for an user and notify others about it - if it was ours
+ *
+ * @param array $condition The condition for finding the item entries
+ * @param integer $uid User who wants to delete this item
+ */
+ public static function deleteForUser($condition, $uid)
+ {
+ if ($uid == 0) {
+ return;
+ }
+
+ $items = dba::select('item', ['id', 'uid'], $condition);
+ while ($item = dba::fetch($items)) {
+ // "Deleting" global items just means hiding them
+ if ($item['uid'] == 0) {
+ dba::update('user-item', ['hidden' => true], ['iid' => $item['id'], 'uid' => $uid], true);
+ } elseif ($item['uid'] == $uid) {
+ self::deleteById($item['id'], PRIORITY_HIGH);
+ } else {
+ logger('Wrong ownership. Not deleting item ' . $item['id']);
+ }
}
dba::close($items);
}
*
* @param integer $item_id Item ID that should be delete
* @param integer $priority Priority for the notification
- * @param integer $uid User who wants to delete the item
*
* @return boolean success
*/
- public static function deleteById($item_id, $priority = PRIORITY_HIGH, $uid = 0)
+ private static function deleteById($item_id, $priority = PRIORITY_HIGH)
{
// locate item to be deleted
$fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin',
$parent = ['origin' => false];
}
- // "Deleting" global items just means hiding them
- if (($item['uid'] == 0) && ($uid != 0)) {
- dba::update('user-item', ['hidden' => true], ['iid' => $item_id, 'uid' => $uid], true);
- return true;
- }
-
// clean up categories and tags so they don't end up as orphans
$matches = false;
}
}
- $entrytype = self::getEntryType($importer, $item);
-
- if (!$item["deleted"]) {
- logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG);
- } else {
+ if ($item["deleted"]) {
return;
}
- Item::deleteById($item["id"]);
+ logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG);
+
+ Item::delete(['id' => $item["id"]]);
}
/**
while ($item = dba::fetch($r)) {
// Fetch the parent item
- $parent = dba::selectFirst('item', ['author-link', 'origin'], ['id' => $item["parent"]]);
+ $parent = dba::selectFirst('item', ['author-link'], ['id' => $item["parent"]]);
// Only delete it if the parent author really fits
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
continue;
}
- Item::deleteById($item["id"]);
+ Item::delete(['id' => $item["id"]]);
logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG);
}
private static function deleteNotice($item)
{
$condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
- $deleted = dba::selectFirst('item', ['id', 'parent-uri'], $condition);
- if (!DBM::is_result($deleted)) {
- logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
+ if (!dba::exists('item', $condition)) {
+ logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it.");
return;
}
- Item::deleteById($deleted["id"]);
+ Item::delete($condition);
logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
}