From: Michael Vogel Date: Sun, 8 Mar 2015 02:27:14 +0000 (+0100) Subject: "global" flag for terms that indicate if the term is present in the global posts. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2260415ca9be83e3389175d994d1d10c3b24c7e6;p=friendica.git "global" flag for terms that indicate if the term is present in the global posts. --- diff --git a/include/dbstructure.php b/include/dbstructure.php index ff24be5de9..630eb4fb29 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -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( diff --git a/include/tags.php b/include/tags.php index 72cac1d639..e3e4edfa17 100644 --- a/include/tags.php +++ b/include/tags.php @@ -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();