]> git.mxchange.org Git - friendica.git/commitdiff
Fetch items by given uri
authorMichael <heluecht@pirati.ca>
Thu, 18 Jul 2019 06:11:02 +0000 (06:11 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 18 Jul 2019 06:11:02 +0000 (06:11 +0000)
database.sql
src/Model/Item.php
static/dbstructure.config.php

index 95da79d2f33fa7bd4481b2e0f6c66cd34511d808..deaec5a24b2423af3b100a7f2f22acab2a7b8a1a 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2019.09-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1318
+-- DB_UPDATE_VERSION 1319
 -- ------------------------------------------
 
 
@@ -605,15 +605,15 @@ CREATE TABLE IF NOT EXISTS `item` (
         INDEX `extid` (`extid`(191)),
         INDEX `uid_id` (`uid`,`id`),
         INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
-        INDEX `uid_created` (`uid`,`created`),
+        INDEX `uid_received` (`uid`,`received`),
         INDEX `uid_commented` (`uid`,`commented`),
         INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
         INDEX `uid_network_received` (`uid`,`network`,`received`),
         INDEX `uid_network_commented` (`uid`,`network`,`commented`),
         INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
         INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
-        INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
-        INDEX `authorid_created` (`author-id`,`created`),
+        INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
+        INDEX `authorid_received` (`author-id`,`received`),
         INDEX `ownerid` (`owner-id`),
         INDEX `contact-id` (`contact-id`),
         INDEX `uid_uri` (`uid`,`uri`(190)),
@@ -667,6 +667,7 @@ CREATE TABLE IF NOT EXISTS `item-content` (
         PRIMARY KEY(`id`),
         UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`),
         INDEX `uri` (`uri`(191)),
+        INDEX `plink` (`plink`(191)),
         INDEX `uri-id` (`uri-id`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
 
@@ -1157,15 +1158,15 @@ CREATE TABLE IF NOT EXISTS `thread` (
        `bookmark` boolean COMMENT '',
         PRIMARY KEY(`iid`),
         INDEX `uid_network_commented` (`uid`,`network`,`commented`),
-        INDEX `uid_network_created` (`uid`,`network`,`created`),
+        INDEX `uid_network_received` (`uid`,`network`,`received`),
         INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
-        INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
+        INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
         INDEX `contactid` (`contact-id`),
         INDEX `ownerid` (`owner-id`),
         INDEX `authorid` (`author-id`),
-        INDEX `uid_created` (`uid`,`created`),
+        INDEX `uid_received` (`uid`,`received`),
         INDEX `uid_commented` (`uid`,`commented`),
-        INDEX `uid_wall_created` (`uid`,`wall`,`created`),
+        INDEX `uid_wall_received` (`uid`,`wall`,`received`),
         INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
 
index d43bdb0a1b44e83ec4d7e7fcda4cd5aaff1c3d97..941000e54354f6a2309ca8e96878c63086e035b4 100644 (file)
@@ -29,6 +29,7 @@ use Friendica\Util\Security;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 use Friendica\Worker\Delivery;
+use Friendica\Protocol\ActivityPub;
 use Text_LanguageDetect;
 
 class Item extends BaseObject
@@ -3575,4 +3576,69 @@ class Item extends BaseObject
 
                return Contact::isForum($item['contact-id']);
        }
+
+       /**
+        * Search item id for given URI or plink
+        *
+        * @param string $uri
+        * @param integer $uid
+        *
+        * @return integer item id
+        */
+       public static function searchByLink($uri, $uid = 0)
+       {
+               $ssl_uri = str_replace('http://', 'https://', $uri);
+               $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
+
+               $item = DBA::selectFirst('item', ['id'], ['uri' => $uris, 'uid' => $uid]);
+               if (DBA::isResult($item)) {
+                       return $item['id'];
+               }
+
+               $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
+               if (!DBA::isResult($itemcontent)) {
+                       return 0;
+               }
+
+               $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
+               if (!DBA::isResult($itemuri)) {
+                       return 0;
+               }
+
+               $item = DBA::selectFirst('item', ['id'], ['uri' => $itemuri['uri'], 'uid' => $uid]);
+               if (DBA::isResult($item)) {
+                       return $item['id'];
+               }
+
+               return 0;
+       }
+
+       /**
+        * Fetches item for given URI or plink
+        *
+        * @param string $uri
+        * @param integer $uid
+        *
+        * @return integer item id
+        */
+       public static function fetchByLink($uri, $uid = 0)
+       {
+               $item_id = self::searchByLink($uri, $uid);
+               if (!empty($item_id)) {
+echo "a\n";
+                       return $item_id;
+               }
+
+echo "b\n";
+               ActivityPub\Processor::fetchMissingActivity($uri);
+
+               $item_id = self::searchByLink($uri, $uid);
+               if (!empty($item_id)) {
+echo "c\n";
+                       return $item_id;
+               }
+
+echo "d\n";
+               return 0;
+       }
 }
index 787a439c4c4eecb51e1bd282a9468b6f10f581c0..4f75eac467cb5a0c85d48ed7ddf4a3163da2abec 100755 (executable)
@@ -34,7 +34,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1318);
+       define('DB_UPDATE_VERSION', 1319);
 }
 
 return [
@@ -736,6 +736,7 @@ return [
                        "PRIMARY" => ["id"],
                        "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
                        "uri" => ["uri(191)"],
+                       "plink" => ["plink(191)"],
                        "uri-id" => ["uri-id"]
                ]
        ],