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