New function to delete items for users
This commit is contained in:
parent
deb015be12
commit
8329705eba
|
@ -2256,7 +2256,7 @@ function api_statuses_destroy($type)
|
|||
|
||||
$ret = api_statuses_show($type);
|
||||
|
||||
Item::deleteById($id, PRIORITY_HIGH, api_user());
|
||||
Item::deleteForUser(['id' => $id], api_user());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
@ -4148,7 +4148,7 @@ function api_fr_photoalbum_delete($type)
|
|||
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
|
||||
|
@ -4441,7 +4441,7 @@ function api_fr_photo_delete($type)
|
|||
}
|
||||
// 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]);
|
||||
|
|
|
@ -321,7 +321,7 @@ function drop_items($items) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ function drop_item($id) {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -555,14 +555,9 @@ function admin_page_deleteitem_post(App $a)
|
|||
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);
|
||||
|
|
|
@ -545,7 +545,7 @@ function events_content(App $a) {
|
|||
|
||||
// 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) {
|
||||
|
|
|
@ -877,7 +877,7 @@ function item_content(App $a) {
|
|||
$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]);
|
||||
}
|
||||
|
|
|
@ -284,14 +284,7 @@ function photos_post(App $a)
|
|||
);
|
||||
|
||||
// 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);
|
||||
|
@ -344,16 +337,11 @@ function photos_post(App $a)
|
|||
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']);
|
||||
|
|
|
@ -169,7 +169,7 @@ function videos_post(App $a) {
|
|||
);
|
||||
|
||||
if (DBM::is_result($i)) {
|
||||
Item::deleteById($i[0]['id'], PRIORITY_HIGH, local_user());
|
||||
Item::deleteForUser(['id' => $i[0]['id']], local_user());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,13 +92,38 @@ class Item extends BaseObject
|
|||
*
|
||||
* @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);
|
||||
}
|
||||
|
@ -108,11 +133,10 @@ class Item extends BaseObject
|
|||
*
|
||||
* @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',
|
||||
|
@ -134,12 +158,6 @@ class Item extends BaseObject
|
|||
$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;
|
||||
|
|
|
@ -2807,15 +2807,13 @@ class DFRN
|
|||
}
|
||||
}
|
||||
|
||||
$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"]]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2785,7 +2785,7 @@ class Diaspora
|
|||
|
||||
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"])) {
|
||||
|
@ -2793,7 +2793,7 @@ class Diaspora
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -537,13 +537,12 @@ class OStatus
|
|||
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']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue