]> git.mxchange.org Git - friendica.git/blobdiff - include/tags.php
New fields for the term table, improved query for the tag search. Changed the cache...
[friendica.git] / include / tags.php
index 489ca47d2bd89df8651dbb808014abb70dc08d71..72cac1d6399115530df1fda13977abeb7da585e6 100644 (file)
@@ -9,7 +9,7 @@ function create_tags_from_item($itemid) {
 
        $searchpath = $a->get_baseurl()."/search?tag=";
 
-       $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
+       $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `created`, `received`, `title`, `body`, `tag`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
 
        if (!$messages)
                return;
@@ -69,8 +69,10 @@ function create_tags_from_item($itemid) {
                        $term = $tag;
                }
 
-               $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')",
-                       intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term), dbesc($link));
+               $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"]));
 
                // Search for mentions
                if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
@@ -96,10 +98,17 @@ function create_tags_from_itemuri($itemuri, $uid) {
 }
 
 function update_items() {
-       //$messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC limit 10");
-       $messages = q("SELECT `id` FROM `item` where tag !=''");
+       global $db;
 
-       foreach ($messages as $message)
-               create_tags_from_item($message["id"]);
+        $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()) {
+               q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s' WHERE `otype` = %d AND `oid` = %d",
+                       dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]),
+                       intval(TERM_OBJ_POST), intval($message["oid"]));
+       }
+
+        $db->qclose();
 }
 ?>