From: Michael Vogel Date: Sun, 8 Mar 2015 23:45:53 +0000 (+0100) Subject: There is now a "global" field in the item table that tells if this item is present... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ea06a1ec4584c298a1d71c139bed196a0e54dcec;p=friendica.git There is now a "global" field in the item table that tells if this item is present as global copy as well. --- diff --git a/include/dbstructure.php b/include/dbstructure.php index 630eb4fb29..c078e40510 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -778,6 +778,7 @@ function db_definition() { "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), "rendered-html" => array("type" => "mediumtext", "not null" => "1"), + "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), ), "indexes" => array( "PRIMARY" => array("id"), diff --git a/include/items.php b/include/items.php index 8f9eb5aa64..3ec476ad6b 100644 --- a/include/items.php +++ b/include/items.php @@ -1346,6 +1346,17 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa return 0; } + // Is this item available in the global items (with uid=0)? + if ($arr["uid"] == 0) { + $arr["global"] = true; + + q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($arr["guid"])); + } else { + $isglobal = q("SELECT `global` FROM `item` WHERE `uid` = 0 AND `guid` = '%s'", dbesc($arr["guid"])); + + $arr["global"] = (count($isglobal) > 0); + } + // Fill the cache field put_item_in_cache($arr); diff --git a/include/tags.php b/include/tags.php index e3e4edfa17..fc1b57db4b 100644 --- a/include/tags.php +++ b/include/tags.php @@ -112,8 +112,7 @@ function create_tags_from_itemuri($itemuri, $uid) { function update_items() { global $db; -// $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true); - $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1", true); + $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true); logger("fetched messages: ".count($messages)); while ($message = $db->qfetch()) { @@ -129,12 +128,21 @@ function update_items() { $global = (count($isglobal) > 0); } -echo $message["created"]." - ".$message["guid"]."\n"; + q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s', `global` = %d WHERE `otype` = %d AND `oid` = %d", dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]), intval($global), intval(TERM_OBJ_POST), intval($message["oid"])); } $db->qclose(); + + $messages = $db->q("SELECT `guid` FROM `item` WHERE `uid` = 0", true); + + logger("fetched messages: ".count($messages)); + while ($message = $db->qfetch()) { + q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"])); + } + + $db->qclose(); } ?> diff --git a/mod/search.php b/mod/search.php index 670df299e5..b9bad64059 100644 --- a/mod/search.php +++ b/mod/search.php @@ -143,8 +143,8 @@ function search_content(&$a) { INNER JOIN `item` ON `item`.`id`=`term`.`oid` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` - AND `term`.`uid` IN (%d,0) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' AND `term`.`guid` != '' - GROUP BY `term`.`guid` ORDER BY term.created DESC LIMIT %d , %d ", + AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' + ORDER BY term.created DESC LIMIT %d , %d ", intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), intval($a->pager['start']), intval($a->pager['itemspage'])); } else {