X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fthreads.php;h=3cfa02564036b4d38577da017a31ee48f1b243a7;hb=c0e87b2beac1f326f97eac6e7f97f95e12498405;hp=6b1c4342f78dae883ed2887b21fa12553269515d;hpb=69b7ad245064354ba946f3ff1f679ebea515e45b;p=friendica.git diff --git a/include/threads.php b/include/threads.php index 6b1c4342f7..3cfa025640 100644 --- a/include/threads.php +++ b/include/threads.php @@ -1,5 +1,5 @@ $data) { - if ($sql != "") - $sql .= ", "; + foreach ($item AS $field => $data) + if (!in_array($field, array("guid", "title", "body"))) { + if ($sql != "") + $sql .= ", "; - $sql .= "`".$field."` = '".$data."'"; - } + $sql .= "`".$field."` = '".dbesc($data)."'"; + } + + $result = q("UPDATE `thread` SET ".$sql." WHERE `iid` = %d", intval($itemid)); + + logger("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG); - $result = q("UPDATE `thread` SET ".$sql." WHERE `iid` = %d", $itemid); + // Updating a shadow item entry + $items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"])); + + if (!$items) + return; - logger("update_thread: Update thread for item ".$itemid." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG); + $result = q("UPDATE `item` SET `title` = '%s', `body` = '%s' WHERE `id` = %d", + dbesc($item["title"]), + dbesc($item["body"]), + intval($items[0]["id"]) + ); + logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG); } function delete_thread_uri($itemuri, $uid) { @@ -57,17 +156,32 @@ function delete_thread_uri($itemuri, $uid) { if(count($messages)) foreach ($messages as $message) - delete_thread($message["id"]); + delete_thread($message["id"], $itemuri); } -function delete_thread($itemid) { +function delete_thread($itemid, $itemuri = "") { + $item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); + $result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid)); logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG); + + if ($itemuri != "") { + $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND NOT (`uid` IN (%d, 0))", + dbesc($itemuri), + intval($item["uid"]) + ); + if (!count($r)) { + $r = q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = 0)", + dbesc($itemuri) + ); + logger("delete_thread: Deleted shadow for item ".$itemuri." - ".print_r($result, true), LOGGER_DEBUG); + } + } } function update_threads() { - global $db; + global $db; logger("update_threads: start"); @@ -96,4 +210,21 @@ function update_threads_mention() { q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", $parent["parent"]); } } + + +function update_shadow_copy() { + global $db; + + logger("start"); + + $messages = $db->q(sprintf("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', '%s', '%s', '%s') + AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`", + NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS), true); + + logger("fetched messages: ".count($messages)); + while ($message = $db->qfetch()) + add_thread($message["iid"], true); + + $db->qclose(); +} ?>