X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fthreads.php;h=61bc5292ff7621fba0c3f96d653d6c4ae8794db8;hb=104a03e82a1cc4c72de65f27cc5b7953a24bf069;hp=8e58a04b3104896842eba2907cc636fe00886b7a;hpb=9a0bcc402a4e5a78aadc65a8782837aa0df8e864;p=friendica.git diff --git a/include/threads.php b/include/threads.php index 8e58a04b31..61bc5292ff 100644 --- a/include/threads.php +++ b/include/threads.php @@ -1,7 +1,6 @@ $data) - if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) { + if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) { if ($sql != "") { $sql .= ", "; } @@ -213,7 +63,7 @@ function update_thread($itemid, $setmention = false) { // Updating a shadow item entry $items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"])); - if (!dbm::is_result($items)) { + if (!DBM::is_result($items)) { return; } @@ -230,7 +80,7 @@ function update_thread($itemid, $setmention = false) { function delete_thread_uri($itemuri, $uid) { $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); - if (dbm::is_result($messages)) { + if (DBM::is_result($messages)) { foreach ($messages as $message) { delete_thread($message["id"], $itemuri); } @@ -240,8 +90,13 @@ function delete_thread_uri($itemuri, $uid) { function delete_thread($itemid, $itemuri = "") { $item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); + if (!DBM::is_result($item)) { + logger('No thread found for id '.$itemid, LOGGER_DEBUG); + return; + } + // Using dba::delete at this time could delete the associated item entries - $result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid)); + $result = dba::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid); logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG); @@ -250,53 +105,9 @@ function delete_thread($itemid, $itemuri = "") { dbesc($itemuri), intval($item["uid"]) ); - if (!dbm::is_result($r)) { - dba::delete('item', array('uri' => $itemuri, 'uid' => 0)); + if (!DBM::is_result($r)) { + dba::delete('item', ['uri' => $itemuri, 'uid' => 0]); logger("delete_thread: Deleted shadow for item ".$itemuri, LOGGER_DEBUG); } } } - -function update_threads() { - logger("update_threads: start"); - - $messages = dba::select('item', array('id'), array("`id` = `parent`")); - - logger("update_threads: fetched messages: ".dba::num_rows($messages)); - - while ($message = dba::fetch($messages)) { - add_thread($message["id"]); - add_shadow_thread($message["id"]); - } - dba::close($messages); -} - -function update_threads_mention() { - $users = q("SELECT `uid`, `nickname` FROM `user` ORDER BY `uid`"); - - foreach ($users AS $user) { - $self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); - $selfhttps = str_replace("http://", "https://", $self); - $parents = q("SELECT DISTINCT(`parent`) FROM `item` WHERE `uid` = %d AND - ((`owner-link` IN ('%s', '%s')) OR (`author-link` IN ('%s', '%s')))", - $user["uid"], $self, $selfhttps, $self, $selfhttps); - - foreach ($parents AS $parent) - q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", $parent["parent"]); - } -} - - -function update_shadow_copy() { - logger("start"); - - $condition = "`uid` != 0 AND `network` IN ('', ?, ?, ?) AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private`"; - $messages = dba::select('thread', array('iid'), array($condition, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS), - array('order' => 'created')); - - logger("fetched messages: ".dba::num_rows($messages)); - while ($message = dba::fetch($messages)) - add_shadow_thread($message["iid"]); - - dba::close($messages); -}