mirror of
https://github.com/friendica/friendica
synced 2024-11-10 09:42:54 +00:00
Merge pull request #4400 from zeroadam/feature/Threads
Move include/threads to src/
This commit is contained in:
commit
99aa9bedd0
10 changed files with 136 additions and 139 deletions
|
@ -21,7 +21,6 @@ use Friendica\Util\Temporal;
|
|||
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/text.php';
|
||||
require_once 'include/threads.php';
|
||||
require_once 'mod/share.php';
|
||||
require_once 'include/enotify.php';
|
||||
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Friendica\Database\DBM;
|
||||
|
||||
function add_thread($itemid, $onlyshadow = false) {
|
||||
$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));
|
||||
|
||||
if (!$items)
|
||||
return;
|
||||
|
||||
$item = $items[0];
|
||||
$item['iid'] = $itemid;
|
||||
|
||||
if (!$onlyshadow) {
|
||||
$result = dba::insert('thread', $item);
|
||||
|
||||
logger("Add thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
function update_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)) {
|
||||
foreach ($messages as $message) {
|
||||
update_thread($message["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update_thread($itemid, $setmention = false) {
|
||||
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
||||
`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));
|
||||
|
||||
if (!DBM::is_result($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item = $items[0];
|
||||
|
||||
if ($setmention) {
|
||||
$item["mention"] = 1;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
|
||||
foreach ($item AS $field => $data)
|
||||
if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) {
|
||||
if ($sql != "") {
|
||||
$sql .= ", ";
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
// 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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
|
||||
dbesc($item["title"]),
|
||||
dbesc($item["body"]),
|
||||
dbesc($item["rendered-html"]),
|
||||
dbesc($item["rendered-hash"]),
|
||||
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) {
|
||||
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
||||
|
||||
if (DBM::is_result($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
delete_thread($message["id"], $itemuri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = dba::e("DELETE FROM `thread` WHERE `iid` = ?", $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 `deleted` AND NOT (`uid` IN (%d, 0))",
|
||||
dbesc($itemuri),
|
||||
intval($item["uid"])
|
||||
);
|
||||
if (!DBM::is_result($r)) {
|
||||
dba::delete('item', ['uri' => $itemuri, 'uid' => 0]);
|
||||
logger("delete_thread: Deleted shadow for item ".$itemuri, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,7 +32,6 @@ use Friendica\Util\DateTimeFormat;
|
|||
use Friendica\Util\Emailer;
|
||||
|
||||
require_once 'include/enotify.php';
|
||||
require_once 'include/threads.php';
|
||||
require_once 'include/text.php';
|
||||
require_once 'include/items.php';
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ require_once 'include/items.php';
|
|||
require_once 'include/acl_selectors.php';
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/security.php';
|
||||
require_once 'include/threads.php';
|
||||
|
||||
function photos_init(App $a) {
|
||||
|
||||
|
@ -297,7 +296,7 @@ function photos_post(App $a)
|
|||
intval($page_owner_uid)
|
||||
);
|
||||
Term::insertFromTagFieldByItemUri($rr['parent-uri'], $page_owner_uid);
|
||||
delete_thread_uri($rr['parent-uri'], $page_owner_uid);
|
||||
Item::deleteThreadByUri($rr['parent-uri'], $page_owner_uid);
|
||||
|
||||
$drop_id = intval($rr['id']);
|
||||
|
||||
|
@ -371,7 +370,7 @@ function photos_post(App $a)
|
|||
intval($page_owner_uid)
|
||||
);
|
||||
Term::insertFromTagFieldByItemUri($i[0]['uri'], $page_owner_uid);
|
||||
delete_thread_uri($i[0]['uri'], $page_owner_uid);
|
||||
Item::deleteThreadByUri($i[0]['uri'], $page_owner_uid);
|
||||
|
||||
$url = System::baseUrl();
|
||||
$drop_id = intval($i[0]['id']);
|
||||
|
@ -656,7 +655,7 @@ function photos_post(App $a)
|
|||
intval($page_owner_uid)
|
||||
);
|
||||
Term::insertFromTagFieldByItemId($item_id);
|
||||
update_thread($item_id);
|
||||
Item::updateThread($item_id);
|
||||
|
||||
$best = 0;
|
||||
foreach ($p as $scales) {
|
||||
|
@ -1432,7 +1431,7 @@ function photos_content(App $a)
|
|||
intval($link_item['parent']),
|
||||
intval(local_user())
|
||||
);
|
||||
update_thread($link_item['parent']);
|
||||
Item::updateThread($link_item['parent']);
|
||||
}
|
||||
|
||||
if ($link_item['coord']) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file mod/starred.php
|
||||
*/
|
||||
use Friendica\App;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\Item;
|
||||
|
||||
function starred_init(App $a) {
|
||||
|
||||
require_once("include/threads.php");
|
||||
|
||||
$starred = 0;
|
||||
|
||||
if (! local_user()) {
|
||||
|
@ -38,7 +38,7 @@ function starred_init(App $a) {
|
|||
intval($message_id)
|
||||
);
|
||||
|
||||
update_thread($message_id);
|
||||
Item::updateThread($message_id);
|
||||
|
||||
// See if we've been passed a return path to redirect to
|
||||
$return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
|
||||
|
|
|
@ -12,6 +12,7 @@ use Friendica\Core\Worker;
|
|||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Group;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Protocol\DFRN;
|
||||
|
@ -177,7 +178,7 @@ function videos_post(App $a) {
|
|||
intval(local_user())
|
||||
);
|
||||
Term::insertFromTagFieldByItemUri($i[0]['uri'], local_user());
|
||||
delete_thread_uri($i[0]['uri'], local_user());
|
||||
Item::deleteThreadByUri($i[0]['uri'], local_user());
|
||||
|
||||
$url = System::baseUrl();
|
||||
$drop_id = intval($i[0]['id']);
|
||||
|
|
|
@ -27,7 +27,6 @@ use dba;
|
|||
use Text_LanguageDetect;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/threads.php';
|
||||
require_once 'include/items.php';
|
||||
require_once 'include/text.php';
|
||||
|
||||
|
@ -71,7 +70,7 @@ class Item extends BaseObject
|
|||
|
||||
Term::insertFromTagFieldByItemId($item['id']);
|
||||
Term::insertFromFileFieldByItemId($item['id']);
|
||||
update_thread($item['id']);
|
||||
self::updateThread($item['id']);
|
||||
|
||||
Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
|
||||
}
|
||||
|
@ -153,7 +152,7 @@ class Item extends BaseObject
|
|||
|
||||
Term::insertFromTagFieldByItemId($item['id']);
|
||||
Term::insertFromFileFieldByItemId($item['id']);
|
||||
delete_thread($item['id'], $item['parent-uri']);
|
||||
self::deleteThread($item['id'], $item['parent-uri']);
|
||||
|
||||
// If it's the parent of a comment thread, kill all the kids
|
||||
if ($item['id'] == $item['parent']) {
|
||||
|
@ -779,9 +778,9 @@ class Item extends BaseObject
|
|||
}
|
||||
|
||||
if ($arr['parent-uri'] === $arr['uri']) {
|
||||
add_thread($current_post);
|
||||
self::addThread($current_post);
|
||||
} else {
|
||||
update_thread($parent_id);
|
||||
self::updateThread($parent_id);
|
||||
}
|
||||
|
||||
dba::commit();
|
||||
|
@ -1289,7 +1288,7 @@ class Item extends BaseObject
|
|||
dbesc($u[0]['deny_gid']),
|
||||
intval($item_id)
|
||||
);
|
||||
update_thread($item_id);
|
||||
self::updateThread($item_id);
|
||||
|
||||
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', 'tgroup', $item_id);
|
||||
|
||||
|
@ -1872,4 +1871,119 @@ EOT;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function addThread($itemid, $onlyshadow = false)
|
||||
{
|
||||
$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));
|
||||
|
||||
if (!$items) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item = $items[0];
|
||||
$item['iid'] = $itemid;
|
||||
|
||||
if (!$onlyshadow) {
|
||||
$result = dba::insert('thread', $item);
|
||||
|
||||
logger("Add thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateThreadByUri($itemuri, $uid)
|
||||
{
|
||||
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
|
||||
|
||||
if (DBM::is_result($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
self::updateThread($message["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateThread($itemid, $setmention = false)
|
||||
{
|
||||
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
||||
`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));
|
||||
|
||||
if (!DBM::is_result($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item = $items[0];
|
||||
|
||||
if ($setmention) {
|
||||
$item["mention"] = 1;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
|
||||
foreach ($item as $field => $data)
|
||||
if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) {
|
||||
if ($sql != "") {
|
||||
$sql .= ", ";
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
// Updating a shadow item entry
|
||||
$items = dba::selectFirst('item', ['id'], ['guid' => $item['guid'], 'uid' => 0]);
|
||||
|
||||
if (!DBM::is_result($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = dba::update(
|
||||
'item',
|
||||
['title' => $item['title'], 'body' => $item['body'], 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']],
|
||||
['id' => $items['id']]
|
||||
);
|
||||
|
||||
logger("Updating public shadow for post ".$items["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
public static function deleteThreadByUri($itemuri, $uid)
|
||||
{
|
||||
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
|
||||
|
||||
if (DBM::is_result($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
self::deleteThread($message["id"], $itemuri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteThread($itemid, $itemuri = "")
|
||||
{
|
||||
$item = dba::select('thread', ['uid'], ['iid' => $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 = dba::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid);
|
||||
|
||||
logger("deleteThread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);
|
||||
|
||||
if ($itemuri != "") {
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND NOT `deleted` AND NOT (`uid` IN (%d, 0))",
|
||||
dbesc($itemuri),
|
||||
intval($item["uid"])
|
||||
);
|
||||
if (!DBM::is_result($r)) {
|
||||
dba::delete('item', ['uri' => $itemuri, 'uid' => 0]);
|
||||
logger("deleteThread: Deleted shadow for item ".$itemuri, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ use HTMLPurifier_Config;
|
|||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
require_once "include/enotify.php";
|
||||
require_once "include/threads.php";
|
||||
require_once "include/items.php";
|
||||
require_once "include/event.php";
|
||||
require_once "include/text.php";
|
||||
|
@ -2092,7 +2091,7 @@ class DFRN
|
|||
dba::update('item', $fields, $condition);
|
||||
|
||||
Term::insertFromTagFieldByItemUri($item["uri"], $importer["importer_uid"]);
|
||||
update_thread_uri($item["uri"], $importer["importer_uid"]);
|
||||
Item::updateThreadByUri($item["uri"], $importer["importer_uid"]);
|
||||
|
||||
$changed = true;
|
||||
|
||||
|
@ -2841,7 +2840,7 @@ class DFRN
|
|||
);
|
||||
Term::insertFromTagFieldByItemUri($uri, $importer["uid"]);
|
||||
Term::insertFromFileFieldByItemUri($uri, $importer["uid"]);
|
||||
update_thread_uri($uri, $importer["uid"]);
|
||||
Item::updateThreadByUri($uri, $importer["uid"]);
|
||||
} else {
|
||||
$r = q(
|
||||
"UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
|
||||
|
@ -2854,7 +2853,7 @@ class DFRN
|
|||
);
|
||||
Term::insertFromTagFieldByItemUri($uri, $importer["uid"]);
|
||||
Term::insertFromFileFieldByItemUri($uri, $importer["uid"]);
|
||||
update_thread_uri($uri, $importer["importer_uid"]);
|
||||
Item::updateThreadByUri($uri, $importer["importer_uid"]);
|
||||
|
||||
// if this is a relayed delete, propagate it to other recipients
|
||||
|
||||
|
|
|
@ -2857,7 +2857,7 @@ class Diaspora
|
|||
|
||||
// Delete the thread - if it is a starting post and not a comment
|
||||
if ($target_type != 'Comment') {
|
||||
delete_thread($item["id"], $item["parent-uri"]);
|
||||
Item::deleteThread($item["id"], $item["parent-uri"]);
|
||||
}
|
||||
|
||||
logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG);
|
||||
|
|
|
@ -25,7 +25,6 @@ use DOMDocument;
|
|||
use DOMXPath;
|
||||
|
||||
require_once 'include/dba.php';
|
||||
require_once 'include/threads.php';
|
||||
require_once 'include/html2bbcode.php';
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/items.php';
|
||||
|
@ -562,7 +561,7 @@ class OStatus
|
|||
['id' => $deleted["id"]]
|
||||
);
|
||||
|
||||
delete_thread($deleted["id"], $deleted["parent-uri"]);
|
||||
Item::deleteThread($deleted["id"], $deleted["parent-uri"]);
|
||||
|
||||
logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue