]> git.mxchange.org Git - friendica.git/commitdiff
There is now a "global" field in the item table that tells if this item is present...
authorMichael Vogel <icarus@dabo.de>
Sun, 8 Mar 2015 23:45:53 +0000 (00:45 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 8 Mar 2015 23:45:53 +0000 (00:45 +0100)
include/dbstructure.php
include/items.php
include/tags.php
mod/search.php

index 630eb4fb290b4211fb562b6fbaa93998fdb493fa..c078e405102332ac32005e5653e45ead93190597 100644 (file)
@@ -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"),
index 8f9eb5aa6454353d78bb803de1ea7c5b831485e3..3ec476ad6bab9ea1aaa69609dcc3f42cbfbdc731 100644 (file)
@@ -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);
 
index e3e4edfa17f9c21a024083b01b365839b7b496de..fc1b57db4b9343da5ac0e41735fd6b0eed9d96f0 100644 (file)
@@ -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();
 }
 ?>
index 670df299e5b673645bb2ca9ad9f1836880f7a996..b9bad6405928097c2ce328ea693f08a0cd025826 100644 (file)
@@ -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 {