]> git.mxchange.org Git - friendica.git/commitdiff
"global" flag for terms that indicate if the term is present in the global posts.
authorMichael Vogel <icarus@dabo.de>
Sun, 8 Mar 2015 02:27:14 +0000 (03:27 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 8 Mar 2015 02:27:14 +0000 (03:27 +0100)
include/dbstructure.php
include/tags.php

index ff24be5de9e7fc552ac8b04ae0ddc6f65698a8fd..630eb4fb290b4211fb562b6fbaa93998fdb493fa 100644 (file)
@@ -1193,6 +1193,7 @@ function db_definition() {
                                        "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                        "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
                                        "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
+                                       "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
                                        "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
                                        ),
@@ -1203,6 +1204,7 @@ function db_definition() {
                                        "type_term" => array("type","term"),
                                        "uid_otype_type_term_created" => array("uid","otype","type","term","created"),
                                        "otype_type_term_tid" => array("otype","type","term","tid"),
+                                       "guid" => array("guid"),
                                        )
                        );
        $database["thread"] = array(
index 72cac1d6399115530df1fda13977abeb7da585e6..e3e4edfa17f9c21a024083b01b365839b7b496de 100644 (file)
@@ -69,10 +69,22 @@ function create_tags_from_item($itemid) {
                        $term = $tag;
                }
 
-               $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `guid`, `created`, `received`)
-                               VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')",
-                       intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type),
-                       dbesc($term), dbesc($link), dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]));
+               if ($message["uid"] == 0) {
+                       $global = true;
+
+                       q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
+                               intval(TERM_OBJ_POST), dbesc($message["guid"]));
+               } else {
+                       $isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
+                               intval(TERM_OBJ_POST), dbesc($message["guid"]));
+
+                       $global = (count($isglobal) > 0);
+               }
+
+               $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `guid`, `created`, `received`, `global`)
+                               VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d)",
+                       intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term),
+                       dbesc($link), dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]), intval($global));
 
                // Search for mentions
                if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
@@ -100,13 +112,27 @@ 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 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);
 
         logger("fetched messages: ".count($messages));
         while ($message = $db->qfetch()) {
-               q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s' WHERE `otype` = %d AND `oid` = %d",
+
+               if ($message["uid"] == 0) {
+                       $global = true;
+
+                       q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
+                               intval(TERM_OBJ_POST), dbesc($message["guid"]));
+               } else {
+                       $isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
+                               intval(TERM_OBJ_POST), dbesc($message["guid"]));
+
+                       $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(TERM_OBJ_POST), intval($message["oid"]));
+                       intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
        }
 
         $db->qclose();