2014-03-16 17:19:19 +00:00
|
|
|
<?php
|
2017-04-30 04:07:00 +00:00
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
use Friendica\Database\DBM;
|
2017-04-30 04:07:00 +00:00
|
|
|
|
2014-12-21 20:19:37 +00:00
|
|
|
function add_thread($itemid, $onlyshadow = false) {
|
2016-06-18 23:07:20 +00:00
|
|
|
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`,
|
|
|
|
`moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
|
|
|
`deleted`, `origin`, `forum_mode`, `mention`, `network`, `author-id`, `owner-id`
|
|
|
|
FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
|
2014-03-16 17:19:19 +00:00
|
|
|
|
|
|
|
if (!$items)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$item = $items[0];
|
|
|
|
$item['iid'] = $itemid;
|
|
|
|
|
2014-12-21 20:19:37 +00:00
|
|
|
if (!$onlyshadow) {
|
2017-09-15 19:41:30 +00:00
|
|
|
$result = dba::insert('thread', $item);
|
2014-03-16 17:19:19 +00:00
|
|
|
|
2016-10-23 21:59:40 +00:00
|
|
|
logger("Add thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);
|
2014-12-21 20:19:37 +00:00
|
|
|
}
|
2016-10-23 21:59:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-16 17:19:19 +00:00
|
|
|
function update_thread_uri($itemuri, $uid) {
|
|
|
|
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
if (DBM::is_result($messages)) {
|
2017-04-04 17:48:25 +00:00
|
|
|
foreach ($messages as $message) {
|
2014-03-16 17:19:19 +00:00
|
|
|
update_thread($message["id"]);
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_thread($itemid, $setmention = false) {
|
2016-01-10 16:10:56 +00:00
|
|
|
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
2016-01-14 20:56:37 +00:00
|
|
|
`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));
|
2014-03-16 17:19:19 +00:00
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
if (!DBM::is_result($items)) {
|
2014-03-16 17:19:19 +00:00
|
|
|
return;
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
|
|
|
|
$item = $items[0];
|
|
|
|
|
2017-04-04 17:48:25 +00:00
|
|
|
if ($setmention) {
|
2014-03-16 17:19:19 +00:00
|
|
|
$item["mention"] = 1;
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
|
|
|
|
$sql = "";
|
|
|
|
|
2014-12-21 10:02:31 +00:00
|
|
|
foreach ($item AS $field => $data)
|
2018-01-15 13:05:12 +00:00
|
|
|
if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) {
|
2017-04-04 17:48:25 +00:00
|
|
|
if ($sql != "") {
|
2014-12-21 10:02:31 +00:00
|
|
|
$sql .= ", ";
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
|
2014-12-21 10:02:31 +00:00
|
|
|
$sql .= "`".$field."` = '".dbesc($data)."'";
|
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
|
2014-12-21 10:02:31 +00:00
|
|
|
$result = q("UPDATE `thread` SET ".$sql." WHERE `iid` = %d", intval($itemid));
|
2014-03-16 17:19:19 +00:00
|
|
|
|
2015-05-03 19:25:03 +00:00
|
|
|
logger("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG);
|
2014-12-21 10:02:31 +00:00
|
|
|
|
|
|
|
// Updating a shadow item entry
|
2015-05-03 19:25:03 +00:00
|
|
|
$items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"]));
|
2014-12-21 10:02:31 +00:00
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
if (!DBM::is_result($items)) {
|
2014-12-21 10:02:31 +00:00
|
|
|
return;
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
2014-12-21 10:02:31 +00:00
|
|
|
|
2016-01-14 20:56:37 +00:00
|
|
|
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
|
2014-12-21 10:02:31 +00:00
|
|
|
dbesc($item["title"]),
|
|
|
|
dbesc($item["body"]),
|
2016-01-14 20:56:37 +00:00
|
|
|
dbesc($item["rendered-html"]),
|
|
|
|
dbesc($item["rendered-hash"]),
|
2015-05-03 19:25:03 +00:00
|
|
|
intval($items[0]["id"])
|
2014-12-21 10:02:31 +00:00
|
|
|
);
|
2015-05-03 19:25:03 +00:00
|
|
|
logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
|
2014-03-16 17:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete_thread_uri($itemuri, $uid) {
|
|
|
|
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
if (DBM::is_result($messages)) {
|
2017-04-04 17:48:25 +00:00
|
|
|
foreach ($messages as $message) {
|
2015-01-07 00:46:13 +00:00
|
|
|
delete_thread($message["id"], $itemuri);
|
2017-04-04 17:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 00:46:13 +00:00
|
|
|
function delete_thread($itemid, $itemuri = "") {
|
|
|
|
$item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid));
|
2014-12-21 10:02:31 +00:00
|
|
|
|
2017-11-08 03:57:46 +00:00
|
|
|
if (!DBM::is_result($item)) {
|
2017-09-24 12:02:32 +00:00
|
|
|
logger('No thread found for id '.$itemid, LOGGER_DEBUG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 08:01:22 +00:00
|
|
|
// Using dba::delete at this time could delete the associated item entries
|
2017-11-22 07:21:19 +00:00
|
|
|
$result = dba::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid);
|
2014-03-16 17:19:19 +00:00
|
|
|
|
|
|
|
logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);
|
2014-12-21 10:02:31 +00:00
|
|
|
|
2015-01-07 00:46:13 +00:00
|
|
|
if ($itemuri != "") {
|
2017-09-17 08:01:22 +00:00
|
|
|
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND NOT `deleted` AND NOT (`uid` IN (%d, 0))",
|
2015-01-07 00:46:13 +00:00
|
|
|
dbesc($itemuri),
|
2014-12-21 10:02:31 +00:00
|
|
|
intval($item["uid"])
|
|
|
|
);
|
2017-11-08 03:57:46 +00:00
|
|
|
if (!DBM::is_result($r)) {
|
2018-01-15 13:05:12 +00:00
|
|
|
dba::delete('item', ['uri' => $itemuri, 'uid' => 0]);
|
2017-09-17 08:01:22 +00:00
|
|
|
logger("delete_thread: Deleted shadow for item ".$itemuri, LOGGER_DEBUG);
|
2014-12-21 10:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 17:19:19 +00:00
|
|
|
}
|