From 69b7ad245064354ba946f3ff1f679ebea515e45b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 16 Mar 2014 18:19:19 +0100 Subject: [PATCH] Functions for the new threas table, script for updating this table --- include/threads.php | 99 ++++++++++++++++++++++++++++++++++++++++ include/threadupdate.php | 23 ++++++++++ 2 files changed, 122 insertions(+) create mode 100644 include/threads.php create mode 100644 include/threadupdate.php diff --git a/include/threads.php b/include/threads.php new file mode 100644 index 0000000000..6b1c4342f7 --- /dev/null +++ b/include/threads.php @@ -0,0 +1,99 @@ + $data) { + if ($sql != "") + $sql .= ", "; + + $sql .= "`".$field."` = '".$data."'"; + } + + $result = q("UPDATE `thread` SET ".$sql." WHERE `iid` = %d", $itemid); + + logger("update_thread: Update thread for item ".$itemid." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG); +} + +function delete_thread_uri($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) + delete_thread($message["id"]); +} + +function delete_thread($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); +} + +function update_threads() { + global $db; + + logger("update_threads: start"); + + $messages = $db->q("SELECT `id` FROM `item` WHERE `id` = `parent`", true); + + logger("update_threads: fetched messages: ".count($messages)); + + while ($message = $db->qfetch()) + add_thread($message["id"]); + $db->qclose(); +} + +function update_threads_mention() { + $a = get_app(); + + $users = q("SELECT `uid`, `nickname` FROM `user` ORDER BY `uid`"); + + foreach ($users AS $user) { + $self = normalise_link($a->get_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"]); + } +} +?> diff --git a/include/threadupdate.php b/include/threadupdate.php new file mode 100644 index 0000000000..e9d9bf6e6b --- /dev/null +++ b/include/threadupdate.php @@ -0,0 +1,23 @@ +