Many item calls are now isolated in a single function

This commit is contained in:
Michael 2018-02-06 12:40:22 +00:00
parent c8cc7f13f1
commit e609de2957
23 changed files with 161 additions and 387 deletions

View file

@ -2218,7 +2218,7 @@ function api_statuses_destroy($type)
$ret = api_statuses_show($type); $ret = api_statuses_show($type);
Item::delete($id); Item::deleteById($id);
return $ret; return $ret;
} }
@ -2459,9 +2459,7 @@ function api_favorites_create_destroy($type)
throw new BadRequestException("Invalid action ".$action); throw new BadRequestException("Invalid action ".$action);
} }
$r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user()); Item::update(['starred' => $item[0]['starred']], ['id' => $itemid]);
q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
if ($r === false) { if ($r === false) {
throw new InternalServerErrorException("DB error"); throw new InternalServerErrorException("DB error");
@ -3991,7 +3989,7 @@ function api_fr_photoalbum_delete($type)
if (!DBM::is_result($photo_item)) { if (!DBM::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured"); throw new InternalServerErrorException("problem with deleting items occured");
} }
Item::delete($photo_item[0]['id']); Item::deleteById($photo_item[0]['id']);
} }
// now let's delete all photos from the album // now let's delete all photos from the album
@ -4294,7 +4292,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 // 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) // 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::delete($photo_item[0]['id']); Item::deleteById($photo_item[0]['id']);
$answer = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.']; $answer = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.'];
return api_format_data("photo_delete", $type, ['$result' => $answer]); return api_format_data("photo_delete", $type, ['$result' => $answer]);

View file

@ -318,13 +318,8 @@ function event_store($arr) {
$object .= '<content>' . xmlify(format_event_bbcode($arr)) . '</content>'; $object .= '<content>' . xmlify(format_event_bbcode($arr)) . '</content>';
$object .= '</object>' . "\n"; $object .= '</object>' . "\n";
q("UPDATE `item` SET `body` = '%s', `object` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d", $fields = ['body' => format_event_bbcode($arr), 'object' => $object, 'edited' => $arr['edited']];
dbesc(format_event_bbcode($arr)), Item::update($fields, ['id' => $r[0]['id']]);
dbesc($object),
dbesc($arr['edited']),
intval($r[0]['id']),
intval($arr['uid'])
);
$item_id = $r[0]['id']; $item_id = $r[0]['id'];
} else { } else {
@ -402,11 +397,7 @@ function event_store($arr) {
$item_id = Item::insert($item_arr); $item_id = Item::insert($item_arr);
if ($item_id) { if ($item_id) {
q("UPDATE `item` SET `event-id` = %d WHERE `uid` = %d AND `id` = %d", Item::update(['event-id' => $event['id']], ['id' => $item_id]);
intval($event['id']),
intval($arr['uid']),
intval($item_id)
);
} }
Addon::callHooks("event_created", $event['id']); Addon::callHooks("event_created", $event['id']);

View file

@ -322,7 +322,7 @@ function drop_items($items) {
if (count($items)) { if (count($items)) {
foreach ($items as $item) { foreach ($items as $item) {
$owner = Item::delete($item); $owner = Item::deleteById($item);
if ($owner && !$uid) if ($owner && !$uid)
$uid = $owner; $uid = $owner;
} }
@ -394,7 +394,7 @@ function drop_item($id) {
} }
// delete the item // delete the item
Item::delete($item['id']); Item::deleteById($item['id']);
goaway(System::baseUrl() . '/' . $_SESSION['return_url']); goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
//NOTREACHED //NOTREACHED

View file

@ -1897,15 +1897,8 @@ function file_tag_save_file($uid, $item, $file)
intval($uid) intval($uid)
); );
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
if (! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) { $fields = ['file' => $r[0]['file'] . '[' . file_tag_encode($file) . ']'];
q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d", Item::update($fields, ['id' => $item]);
dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'),
intval($item),
intval($uid)
);
}
Term::insertFromFileFieldByItemId($item);
$saved = PConfig::get($uid, 'system', 'filetags'); $saved = PConfig::get($uid, 'system', 'filetags');
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) { if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
@ -1938,13 +1931,8 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false)
return false; return false;
} }
q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d", $fields = ['file' => str_replace($pattern,'',$r[0]['file'])];
dbesc(str_replace($pattern,'',$r[0]['file'])), Item::update($fields, ['id' => $item]);
intval($item),
intval($uid)
);
Term::insertFromFileFieldByItemId($item);
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d", $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
dbesc($file), dbesc($file),

View file

@ -505,7 +505,7 @@ function admin_page_deleteitem_post(App $a)
// associated threads. // associated threads.
$r = dba::select('item', ['id'], ['guid' => $guid]); $r = dba::select('item', ['id'], ['guid' => $guid]);
while ($row = dba::fetch($r)) { while ($row = dba::fetch($r)) {
Item::delete($row['id']); Item::deleteById($row['id']);
} }
dba::close($r); dba::close($r);
} }

View file

@ -348,9 +348,6 @@ function _contact_archive($contact_id, $orig_record)
intval($contact_id), intval($contact_id),
intval(local_user()) intval(local_user())
); );
if ($archived) {
q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
}
return DBM::is_result($r); return DBM::is_result($r);
} }

View file

@ -550,7 +550,7 @@ function events_content(App $a) {
// Delete only real events (no birthdays) // Delete only real events (no birthdays)
if (DBM::is_result($ev) && $ev[0]['type'] == 'event') { if (DBM::is_result($ev) && $ev[0]['type'] == 'event') {
$del = Item::delete($ev[0]['itemid']); $del = Item::deleteById($ev[0]['itemid']);
} }
if ($del == 0) { if ($del == 0) {

View file

@ -876,7 +876,7 @@ function item_content(App $a) {
$o = ''; $o = '';
if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
if (is_ajax()) { if (is_ajax()) {
$o = Item::delete($a->argv[2]); $o = Item::deleteById($a->argv[2]);
} else { } else {
$o = drop_item($a->argv[2]); $o = drop_item($a->argv[2]);
} }

View file

@ -17,6 +17,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -326,7 +327,7 @@ function networkSetSeen($condition)
$unseen = dba::exists('item', $condition); $unseen = dba::exists('item', $condition);
if ($unseen) { if ($unseen) {
$r = dba::update('item', ['unseen' => false], $condition); $r = Item::update(['unseen' => false], $condition);
} }
} }

View file

@ -285,25 +285,12 @@ function photos_post(App $a)
); );
// find and delete the corresponding item with all the comments and likes/dislikes // find and delete the corresponding item with all the comments and likes/dislikes
$r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d", $r = q("SELECT `id` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
intval($page_owner_uid) intval($page_owner_uid)
); );
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", Item::deleteById($rr['id']);
dbesc(DateTimeFormat::utcNow()),
dbesc($rr['parent-uri']),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemUri($rr['parent-uri'], $page_owner_uid);
Item::deleteThreadByUri($rr['parent-uri'], $page_owner_uid);
$drop_id = intval($rr['id']);
// send the notification upstream/downstream as the case may be
if ($rr['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
} }
} }
@ -358,29 +345,15 @@ function photos_post(App $a)
intval($page_owner_uid), intval($page_owner_uid),
dbesc($r[0]['resource-id']) dbesc($r[0]['resource-id'])
); );
$i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1", $i = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
dbesc($r[0]['resource-id']), dbesc($r[0]['resource-id']),
intval($page_owner_uid) intval($page_owner_uid)
); );
if (DBM::is_result($i)) { if (DBM::is_result($i)) {
q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", Item::deleteById($i[0]['id']);
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
dbesc($i[0]['uri']),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemUri($i[0]['uri'], $page_owner_uid);
Item::deleteThreadByUri($i[0]['uri'], $page_owner_uid);
$url = System::baseUrl();
$drop_id = intval($i[0]['id']);
// Update the photo albums cache // Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid); Photo::clearAlbumCache($page_owner_uid);
if ($i[0]['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
} }
} }
@ -646,16 +619,9 @@ function photos_post(App $a)
} }
$newinform .= $inform; $newinform .= $inform;
$r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
dbesc($newtag), $condition = ['id' => $item_id];
dbesc($newinform), Item::update($fields, $condition);
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
intval($item_id),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemId($item_id);
Item::updateThread($item_id);
$best = 0; $best = 0;
foreach ($p as $scales) { foreach ($p as $scales) {
@ -1427,11 +1393,7 @@ function photos_content(App $a)
); );
if (local_user() && (local_user() == $link_item['uid'])) { if (local_user() && (local_user() == $link_item['uid'])) {
q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
intval($link_item['parent']),
intval(local_user())
);
Item::updateThread($link_item['parent']);
} }
if ($link_item['coord']) { if ($link_item['coord']) {

View file

@ -135,11 +135,6 @@ function poke_init(App $a) {
$item_id = Item::insert($arr); $item_id = Item::insert($arr);
if($item_id) { if($item_id) {
//q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
// dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
// intval($uid),
// intval($item_id)
//);
Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id); Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
} }

View file

@ -13,6 +13,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
@ -359,7 +360,7 @@ function profile_content(App $a, $update = 0)
if ($is_owner) { if ($is_owner) {
$unseen = dba::exists('item', ['wall' => true, 'unseen' => true, 'uid' => local_user()]); $unseen = dba::exists('item', ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
if ($unseen) { if ($unseen) {
$r = dba::update('item', ['unseen' => false], $r = Item::update(['unseen' => false],
['wall' => true, 'unseen' => true, 'uid' => local_user()]); ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
} }
} }

View file

@ -32,13 +32,7 @@ function starred_init(App $a) {
$starred = 1; $starred = 1;
} }
$r = q("UPDATE `item` SET `starred` = %d WHERE `uid` = %d AND `id` = %d", Item::update(['starred' => $starred], ['id' => $message_id]);
intval($starred),
intval(local_user()),
intval($message_id)
);
Item::updateThread($message_id);
// See if we've been passed a return path to redirect to // See if we've been passed a return path to redirect to
$return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');

View file

@ -153,10 +153,7 @@ EOT;
$post_id = Item::insert($arr); $post_id = Item::insert($arr);
if (!$item['visible']) { if (!$item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", Item::update(['visible' => true], ['id' => $item['id']]);
intval($item['id']),
intval($owner_uid)
);
} }
$arr['id'] = $post_id; $arr['id'] = $post_id;

View file

@ -149,23 +149,15 @@ EOT;
$post_id = Item::insert($arr); $post_id = Item::insert($arr);
if (!$item['visible']) { if (!$item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", Item::update(['visible' => true], ['id' => $item['id']]);
intval($item['id']),
intval($owner_uid)
);
} }
$term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST ); $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
$t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'", $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
intval($item['id']), intval($item['id']),
dbesc($term) dbesc($term)
); );
if((! $blocktags) && $t[0]['tcount']==0 ) { if((! $blocktags) && $t[0]['tcount']==0 ) {
/*q("update item set tag = '%s' where id = %d",
dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
intval($item['id'])
);*/
q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)", q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
intval($item['id']), intval($item['id']),
$term_objtype, $term_objtype,
@ -199,14 +191,6 @@ EOT;
intval($owner_uid) intval($owner_uid)
); );
} }
/*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
q("update item set tag = '%s' where id = %d",
dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
intval($r[0]['id'])
);
}*/
} }
@ -219,6 +203,4 @@ EOT;
killme(); killme();
return; // NOTREACHED return; // NOTREACHED
} }

View file

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Item;
require_once 'include/bbcode.php'; require_once 'include/bbcode.php';
@ -41,17 +42,12 @@ function tagrm_post(App $a) {
$tag_str = implode(',',$arr); $tag_str = implode(',',$arr);
q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d", Item::update(['tag' => $tag_str], ['id' => $item]);
dbesc($tag_str),
intval($item),
intval(local_user())
);
info(L10n::t('Tag removed') . EOL ); info(L10n::t('Tag removed') . EOL );
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']); goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
// NOTREACHED // NOTREACHED
} }

View file

@ -165,27 +165,13 @@ function videos_post(App $a) {
intval(local_user()), intval(local_user()),
dbesc($video_id) dbesc($video_id)
); );
$i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1", $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
dbesc($video_id), dbesc($video_id),
intval(local_user()) intval(local_user())
); );
//echo "<pre>"; var_dump($i); killme();
if (DBM::is_result($i)) { if (DBM::is_result($i)) {
q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", Item::deleteById($i[0]['id']);
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
dbesc($i[0]['uri']),
intval(local_user())
);
Term::insertFromTagFieldByItemUri($i[0]['uri'], local_user());
Item::deleteThreadByUri($i[0]['uri'], local_user());
$url = System::baseUrl();
$drop_id = intval($i[0]['id']);
if ($i[0]['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
} }
} }

View file

@ -29,6 +29,7 @@ use Text_LanguageDetect;
require_once 'boot.php'; require_once 'boot.php';
require_once 'include/items.php'; require_once 'include/items.php';
require_once 'include/text.php'; require_once 'include/text.php';
require_once 'include/event.php';
class Item extends BaseObject class Item extends BaseObject
{ {
@ -78,17 +79,35 @@ class Item extends BaseObject
return $rows; return $rows;
} }
/**
* @brief Delete an item and notify others about it - if it was ours
*
* @param array $condition The condition for finding the item entries
* @param integer $priority Priority for the notification
*/
public static function delete($condition, $priority = PRIORITY_HIGH)
{
$items = dba::select('item', ['id'], $condition);
while ($item = dba::fetch($items)) {
self::deleteById($item['id'], $priority);
}
dba::close($items);
}
/** /**
* @brief Delete an item and notify others about it - if it was ours * @brief Delete an item and notify others about it - if it was ours
* *
* @param integer $item_id Item ID that should be delete * @param integer $item_id Item ID that should be delete
* @param integer $priority Priority for the notification
* *
* @return $boolean success * @return $boolean success
*/ */
public static function delete($item_id, $priority = PRIORITY_HIGH) public static function deleteById($item_id, $priority = PRIORITY_HIGH)
{ {
// locate item to be deleted // locate item to be deleted
$fields = ['id', 'uid', 'parent', 'parent-uri', 'origin', 'deleted', 'file', 'resource-id', 'event-id', 'attach']; $fields = ['id', 'uid', 'parent', 'parent-uri', 'origin', 'deleted',
'file', 'resource-id', 'event-id', 'attach',
'verb', 'object-type', 'object', 'target', 'contact-id'];
$item = dba::selectFirst('item', $fields, ['id' => $item_id]); $item = dba::selectFirst('item', $fields, ['id' => $item_id]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
return false; return false;
@ -134,9 +153,9 @@ class Item extends BaseObject
dba::delete('photo', ['resource-id' => $item['resource-id'], 'uid' => $item['uid']]); dba::delete('photo', ['resource-id' => $item['resource-id'], 'uid' => $item['uid']]);
} }
// If item is a link to an event, nuke the event record. // If item is a link to an event, delete the event.
if (intval($item['event-id'])) { if (intval($item['event-id'])) {
dba::delete('event', ['id' => $item['event-id'], 'uid' => $item['uid']]); event_delete($item['event-id']);
} }
// If item has attachments, drop them // If item has attachments, drop them
@ -145,6 +164,9 @@ class Item extends BaseObject
dba::delete('attach', ['id' => $matches[1], 'uid' => $item['uid']]); dba::delete('attach', ['id' => $matches[1], 'uid' => $item['uid']]);
} }
// Delete tags that had been attached to other items
self::deleteTagsFromItem($item);
// Set the item to "deleted" // Set the item to "deleted"
dba::update('item', ['deleted' => true, 'title' => '', 'body' => '', dba::update('item', ['deleted' => true, 'title' => '', 'body' => '',
'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()],
@ -156,10 +178,7 @@ class Item extends BaseObject
// If it's the parent of a comment thread, kill all the kids // If it's the parent of a comment thread, kill all the kids
if ($item['id'] == $item['parent']) { if ($item['id'] == $item['parent']) {
$items = dba::select('item', ['id'], ['parent' => $item['parent']]); self::delete(['parent' => $item['parent']]);
while ($row = dba::fetch($items)) {
self::delete($row['id'], $priority);
}
} }
// send the notification upstream/downstream // send the notification upstream/downstream
@ -170,6 +189,44 @@ class Item extends BaseObject
return true; return true;
} }
private static function deleteTagsFromItem($item)
{
if (($item["verb"] != ACTIVITY_TAG) || ($item["object-type"] != ACTIVITY_OBJ_TAGTERM)) {
return;
}
$xo = XML::parseString($item["object"], false);
$xt = XML::parseString($item["target"], false);
if ($xt->type != ACTIVITY_OBJ_NOTE) {
return;
}
$i = dba::selectFirst('item', ['id', 'contact-id', 'tag'], ['uri' => $xt->id, 'uid' => $item['uid']]);
if (!DBM::is_result($i)) {
return;
}
// For tags, the owner cannot remove the tag on the author's copy of the post.
$owner_remove = ($item["contact-id"] == $i["contact-id"]);
$author_copy = $item["origin"];
if (($owner_remove && $author_copy) || !$owner_remove) {
return;
}
$tags = explode(',', $i["tag"]);
$newtags = [];
if (count($tags)) {
foreach ($tags as $tag) {
if (trim($tag) !== trim($xo->body)) {
$newtags[] = trim($tag);
}
}
}
self::update(['tag' => implode(',', $newtags)], ['id' => $i["id"]]);
}
public static function insert($arr, $force_parent = false, $notify = false, $dontcache = false) public static function insert($arr, $force_parent = false, $notify = false, $dontcache = false)
{ {
$a = get_app(); $a = get_app();
@ -1626,7 +1683,7 @@ class Item extends BaseObject
continue; continue;
} }
self::delete($item['id'], PRIORITY_LOW); self::deleteByID($item['id'], PRIORITY_LOW);
} }
} }
@ -1851,13 +1908,11 @@ EOT;
'unseen' => 1, 'unseen' => 1,
]; ];
$new_item_id = Item::insert($new_item); $new_item_id = self::insert($new_item);
// @todo: Explain this block // If the parent item isn't visible then set it to visible
if (!$item['visible']) { if (!$item['visible']) {
q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d", self::update(['visible' => true], ['id' => $item['id']]);
intval($item['id'])
);
} }
// Save the author information for the like in case we need to relay to Diaspora // Save the author information for the like in case we need to relay to Diaspora
@ -1893,18 +1948,7 @@ EOT;
} }
} }
public static function updateThreadByUri($itemuri, $uid) private static function updateThread($itemid, $setmention = false)
{
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
if (DBM::is_result($messages)) {
foreach ($messages as $message) {
self::updateThread($message["id"]);
}
}
}
public static function updateThread($itemid, $setmention = false)
{ {
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); `deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
@ -1950,18 +1994,7 @@ EOT;
logger("Updating public shadow for post ".$items["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG); logger("Updating public shadow for post ".$items["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
} }
public static function deleteThreadByUri($itemuri, $uid) private static function deleteThread($itemid, $itemuri = "")
{
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
if (DBM::is_result($messages)) {
foreach ($messages as $message) {
self::deleteThread($message["id"], $itemuri);
}
}
}
public static function deleteThread($itemid, $itemuri = "")
{ {
$item = dba::selectFirst('thread', ['uid'], ['iid' => $itemid]); $item = dba::selectFirst('thread', ['uid'], ['iid' => $itemid]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {

View file

@ -122,19 +122,6 @@ class Term
} }
} }
public static function insertFromTagFieldByItemUri($itemuri, $uid)
{
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
if (DBM::is_result($messages)) {
while ($message = dba::fetch($messages)) {
self::insertFromTagFieldByItemId($message['id']);
}
dba::close($messages);
}
}
/** /**
* @param integer $itemid item id * @param integer $itemid item id
* @return void * @return void
@ -181,20 +168,4 @@ class Term
} }
} }
} }
/**
* @param string $itemuri item uri
* @param integer $uid uid
* @return void
*/
public static function insertFromFileFieldByItemUri($itemuri, $uid)
{
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if (count($messages)) {
foreach ($messages as $message) {
self::insertFromFileFieldByItemId($message["id"]);
}
}
}
} }

View file

@ -2088,10 +2088,7 @@ class DFRN
'edited' => DateTimeFormat::utc($item["edited"])]; 'edited' => DateTimeFormat::utc($item["edited"])];
$condition = ["`uri` = ? AND `uid` IN (0, ?)", $item["uri"], $importer["importer_uid"]]; $condition = ["`uri` = ? AND `uid` IN (0, ?)", $item["uri"], $importer["importer_uid"]];
dba::update('item', $fields, $condition); Item::update($fields, $condition);
Term::insertFromTagFieldByItemUri($item["uri"], $importer["importer_uid"]);
Item::updateThreadByUri($item["uri"], $importer["importer_uid"]);
$changed = true; $changed = true;
@ -2328,13 +2325,9 @@ class DFRN
// extract tag, if not duplicate, add to parent item // extract tag, if not duplicate, add to parent item
if ($xo->content) { if ($xo->content) {
if (!(stristr($r[0]["tag"], trim($xo->content)))) { if (!stristr($r[0]["tag"], trim($xo->content))) {
q( $tag = $r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
"UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", Item::update(['tag' => $tag], ['id' => $r[0]["id"]]);
dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
intval($r[0]["id"])
);
Term::insertFromTagFieldByItemId($r[0]["id"]);
} }
} }
} }
@ -2746,33 +2739,19 @@ class DFRN
if ($attributes->name == "ref") { if ($attributes->name == "ref") {
$uri = $attributes->textContent; $uri = $attributes->textContent;
} }
if ($attributes->name == "when") {
$when = $attributes->textContent;
}
}
if ($when) {
$when = DateTimeFormat::utc($when);
} else {
$when = DateTimeFormat::utcNow();
} }
if (!$uri || !$importer["id"]) { if (!$uri || !$importer["id"]) {
return false; return false;
} }
/// @todo Only select the used fields $condition = ["`uri` = ? AND `uid` = ? AND `contact-id` = ? AND NOT `file` LIKE '%[%'",
$r = q( $uri, $importer["uid"], $importer["id"]];
"SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` $item = dba::selectFirst('item', ['id'], $condition);
WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", if (!DBM::is_result($item)) {
dbesc($uri),
intval($importer["uid"]),
intval($importer["id"])
);
if (!DBM::is_result($r)) {
logger("Item with uri " . $uri . " from contact " . $importer["id"] . " for user " . $importer["uid"] . " wasn't found.", LOGGER_DEBUG); logger("Item with uri " . $uri . " from contact " . $importer["id"] . " for user " . $importer["uid"] . " wasn't found.", LOGGER_DEBUG);
return; return;
} else { }
$item = $r[0];
$entrytype = self::getEntryType($importer, $item); $entrytype = self::getEntryType($importer, $item);
@ -2782,88 +2761,16 @@ class DFRN
return; return;
} }
if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { Item::deleteById($item["id"]);
logger("Deleting event ".$item["event-id"], LOGGER_DEBUG);
event_delete($item["event-id"]);
}
if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
$xo = XML::parseString($item["object"], false);
$xt = XML::parseString($item["target"], false);
if ($xt->type == ACTIVITY_OBJ_NOTE) {
$i = q(
"SELECT `id`, `contact-id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($xt->id),
intval($importer["importer_uid"])
);
if (DBM::is_result($i)) {
// For tags, the owner cannot remove the tag on the author's copy of the post.
$owner_remove = (($item["contact-id"] == $i[0]["contact-id"]) ? true: false);
$author_remove = (($item["origin"] && $item["self"]) ? true : false);
$author_copy = (($item["origin"]) ? true : false);
if ($owner_remove && $author_copy) {
return;
}
if ($author_remove || $owner_remove) {
$tags = explode(',', $i[0]["tag"]);
$newtags = [];
if (count($tags)) {
foreach ($tags as $tag) {
if (trim($tag) !== trim($xo->body)) {
$newtags[] = trim($tag);
}
}
}
q(
"UPDATE `item` SET `tag` = '%s' WHERE `id` = %d",
dbesc(implode(',', $newtags)),
intval($i[0]["id"])
);
Term::insertFromTagFieldByItemId($i[0]["id"]);
}
}
}
}
if ($entrytype == DFRN_TOP_LEVEL) {
$r = q(
"UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
dbesc($when),
dbesc(DateTimeFormat::utcNow()),
dbesc($uri),
intval($importer["uid"])
);
Term::insertFromTagFieldByItemUri($uri, $importer["uid"]);
Term::insertFromFileFieldByItemUri($uri, $importer["uid"]);
Item::updateThreadByUri($uri, $importer["uid"]);
} else {
$r = q(
"UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `uri` = '%s' AND `uid` IN (0, %d)",
dbesc($when),
dbesc(DateTimeFormat::utcNow()),
dbesc($uri),
intval($importer["uid"])
);
Term::insertFromTagFieldByItemUri($uri, $importer["uid"]);
Term::insertFromFileFieldByItemUri($uri, $importer["uid"]);
Item::updateThreadByUri($uri, $importer["importer_uid"]);
if ($entrytype != DFRN_TOP_LEVEL) {
// if this is a relayed delete, propagate it to other recipients // if this is a relayed delete, propagate it to other recipients
if ($entrytype == DFRN_REPLY_RC) { if ($entrytype == DFRN_REPLY_RC) {
logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG); logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG);
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $item["id"]); Worker::add(PRIORITY_HIGH, "Notifier", "drop", $item["id"]);
} }
} }
} }
}
/** /**
* @brief Imports a DFRN message * @brief Imports a DFRN message

View file

@ -2842,23 +2842,7 @@ class Diaspora
continue; continue;
} }
// Currently we don't have a central deletion function that we could use in this case. Item::deleteById($item["id"]);
// The function "item_drop" doesn't work for that case
dba::update(
'item',
[
'deleted' => true,
'title' => '',
'body' => '',
'edited' => DateTimeFormat::utcNow(),
'changed' => DateTimeFormat::utcNow()],
['id' => $item["id"]]
);
// Delete the thread - if it is a starting post and not a comment
if ($target_type != 'Comment') {
Item::deleteThread($item["id"], $item["parent-uri"]);
}
logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG); logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG);

View file

@ -552,16 +552,7 @@ class OStatus
return; return;
} }
// Currently we don't have a central deletion function that we could use in this case Item::deleteById($deleted["id"]);
// The function "item_drop" doesn't work for that case
dba::update(
'item',
['deleted' => true, 'title' => '', 'body' => '',
'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()],
['id' => $deleted["id"]]
);
Item::deleteThread($deleted["id"], $deleted["parent-uri"]);
logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']); logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
} }

View file

@ -395,7 +395,7 @@ class OnePoll
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3)) if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
if ($meta->deleted && ! $item['deleted']) { if ($meta->deleted && ! $item['deleted']) {
$fields = ['deleted' => true, 'changed' => DateTimeFormat::utcNow()]; $fields = ['deleted' => true, 'changed' => DateTimeFormat::utcNow()];
dba::update('item', $fields, ['id' => $item['id']]); Item::update($fields, ['id' => $item['id']]);
} }
switch ($mailconf['action']) { switch ($mailconf['action']) {