]> git.mxchange.org Git - friendica.git/commitdiff
New post class in protocol and worker classes
authorMichael <heluecht@pirati.ca>
Sat, 16 Jan 2021 04:14:58 +0000 (04:14 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 16 Jan 2021 04:14:58 +0000 (04:14 +0000)
14 files changed:
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Protocol/OStatus.php
src/Protocol/Relay.php
src/Worker/APDelivery.php
src/Worker/Delivery.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
src/Worker/RemoveContact.php
src/Worker/RemoveUser.php

index 52aaa9741efe3e1707546aa3d4e6e8109711e2d5..9e8ea2976e5ad3046c5f5c18e4acaddd11a0780b 100644 (file)
@@ -215,7 +215,7 @@ class Processor
         */
        public static function updateItem($activity)
        {
-               $item = Item::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
+               $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
                if (!DBA::isResult($item)) {
                        Logger::warning('No existing item, item will be created', ['uri' => $activity['id']]);
                        $item = self::createItem($activity);
@@ -259,7 +259,7 @@ class Processor
                        $item['object-type'] = Activity\ObjectType::COMMENT;
                }
 
-               if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
+               if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
                        Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id']]);
                        self::fetchMissingActivity($activity['reply-to-id'], $activity);
                }
@@ -267,7 +267,7 @@ class Processor
                $item['diaspora_signed_text'] = $activity['diaspora:comment'] ?? '';
 
                /// @todo What to do with $activity['context']?
-               if (empty($activity['directmessage']) && ($item['gravity'] != GRAVITY_PARENT) && !Item::exists(['uri' => $item['thr-parent']])) {
+               if (empty($activity['directmessage']) && ($item['gravity'] != GRAVITY_PARENT) && !Post::exists(['uri' => $item['thr-parent']])) {
                        Logger::info('Parent not found, message will be discarded.', ['thr-parent' => $item['thr-parent']]);
                        return [];
                }
@@ -378,7 +378,7 @@ class Processor
                }
 
                foreach ($activity['receiver'] as $receiver) {
-                       $item = Item::selectFirst(['id', 'uri-id', 'tag', 'origin', 'author-link'], ['uri' => $activity['target_id'], 'uid' => $receiver]);
+                       $item = Post::selectFirst(['id', 'uri-id', 'tag', 'origin', 'author-link'], ['uri' => $activity['target_id'], 'uid' => $receiver]);
                        if (!DBA::isResult($item)) {
                                // We don't fetch missing content for this purpose
                                continue;
@@ -479,7 +479,7 @@ class Processor
                } else {
                        if (empty($activity['directmessage']) && ($item['thr-parent'] != $item['uri']) && ($item['gravity'] == GRAVITY_COMMENT)) {
                                $item_private = !in_array(0, $activity['item_receiver']);
-                               $parent = Item::selectFirst(['id', 'uri-id', 'private', 'author-link', 'alias'], ['uri' => $item['thr-parent']]);
+                               $parent = Post::selectFirst(['id', 'uri-id', 'private', 'author-link', 'alias'], ['uri' => $item['thr-parent']]);
                                if (!DBA::isResult($parent)) {
                                        Logger::warning('Unknown parent item.', ['uri' => $item['thr-parent']]);
                                        return false;
@@ -868,7 +868,7 @@ class Processor
                }
 
                $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
-               if (Item::exists(['uri' => $replyto])) {
+               if (Post::exists(['uri' => $replyto])) {
                        Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
                        return true;
                }
index 024d9d4591591f89223a241ac2f1a6a20a1215c3..f48135f77272b0ee9f1d1f286d64e491b4068b93 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
 use Friendica\Model\APContact;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
@@ -230,7 +231,7 @@ class Receiver
                        }
                }
 
-               if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
+               if (Post::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
                        // We just assume "note" since it doesn't make a difference for the further processing
                        return 'as:Note';
                }
@@ -650,10 +651,11 @@ class Receiver
                }
 
                if (!empty($reply)) {
-                       $parents = Item::select(['uid'], ['uri' => $reply]);
-                       while ($parent = Item::fetch($parents)) {
+                       $parents = Post::select(['uid'], ['uri' => $reply]);
+                       while ($parent = Post::fetch($parents)) {
                                $receivers[$parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER];
                        }
+                       DBA::close($parents);
                }
 
                if (!empty($actor)) {
@@ -928,7 +930,7 @@ class Receiver
                        } else {
                                Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
 
-                               $item = Item::selectFirst([], ['uri' => $object_id]);
+                               $item = Post::selectFirst([], ['uri' => $object_id]);
                                if (!DBA::isResult($item)) {
                                        Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
                                        return false;
index 04e3e14f69fbde4e45fbedc8e89df215ab093d79..749931c20db601ec7ef67db542e52e4a03d8634e 100644 (file)
@@ -87,7 +87,7 @@ class Transmitter
         */
        public static function addRelayServerInboxesForItem(int $item_id, array $inboxes = [])
        {
-               $item = Item::selectFirst(['uid'], ['id' => $item_id]);
+               $item = Post::selectFirst(['uid'], ['id' => $item_id]);
                if (empty($item)) {
                        return $inboxes;
                }
@@ -275,8 +275,8 @@ class Transmitter
 
                        $condition['parent-network'] = Protocol::NATIVE_SUPPORT;
 
-                       $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
-                       while ($item = Item::fetch($items)) {
+                       $items = Post::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
+                       while ($item = Post::fetch($items)) {
                                $activity = self::createActivityFromItem($item['id'], true);
                                $activity['type'] = $activity['type'] == 'Update' ? 'Create' : $activity['type'];
 
@@ -285,6 +285,7 @@ class Transmitter
                                        $list[] = $activity['object'];
                                }
                        }
+                       DBA::close($items);
 
                        if (!empty($list)) {
                                $data['next'] = DI::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
@@ -481,7 +482,7 @@ class Transmitter
                        return false;
                }
 
-               return Item::exists(['id' => $item_id, 'network' => Protocol::ACTIVITYPUB]);
+               return Post::exists(['id' => $item_id, 'network' => Protocol::ACTIVITYPUB]);
        }
 
        /**
@@ -593,8 +594,8 @@ class Transmitter
                }
 
                if (!empty($item['parent'])) {
-                       $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
-                       while ($parent = Item::fetch($parents)) {
+                       $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
+                       while ($parent = Post::fetch($parents)) {
                                if ($parent['gravity'] == GRAVITY_PARENT) {
                                        $profile = APContact::getByURL($parent['owner-link'], false);
                                        if (!empty($profile)) {
@@ -1044,7 +1045,7 @@ class Transmitter
        public static function createActivityFromItem(int $item_id, bool $object_mode = false)
        {
                Logger::info('Fetching activity', ['item' => $item_id]);
-               $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
+               $item = Post::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
                if (!DBA::isResult($item)) {
                        return false;
                }
@@ -1055,7 +1056,7 @@ class Transmitter
                        if (!empty($author['nurl'])) {
                                $self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]);
                                if (!empty($self['uid'])) {
-                                       $forum_item = Item::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
+                                       $forum_item = Post::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
                                        if (DBA::isResult($item)) {
                                                $item = $forum_item; 
                                        }
@@ -1644,7 +1645,7 @@ class Transmitter
                        return [];
                }
 
-               $reshared_item = Item::selectFirst([], ['guid' => $reshared['guid']]);
+               $reshared_item = Post::selectFirst([], ['guid' => $reshared['guid']]);
                if (!DBA::isResult($reshared_item)) {
                        return [];
                }
@@ -1903,7 +1904,7 @@ class Transmitter
 
                $condition = ['verb' => Activity::FOLLOW, 'uid' => 0, 'parent-uri' => $object,
                        'author-id' => Contact::getPublicIdByUserId($uid)];
-               if (Item::exists($condition)) {
+               if (Post::exists($condition)) {
                        Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
                        return false;
                }
index a322327b0ec79e92de9ca5e14f940c41f795c4f7..4d5a9289778812795ac68dd45b29b90bdf9b7550 100644 (file)
@@ -273,8 +273,7 @@ class DFRN
                }
 
                if (!empty($ids)) {
-                       $ret = Item::select(Item::DELIVER_FIELDLIST, ['id' => $ids]);
-                       $items = Item::inArray($ret);
+                       $items = Post::selectToArray(Item::DELIVER_FIELDLIST, ['id' => $ids]);
                } else {
                        $items = [];
                }
@@ -361,8 +360,7 @@ class DFRN
                        $condition = ['id' => $item_id];
                }
 
-               $ret = Item::select(Item::DELIVER_FIELDLIST, $condition);
-               $items = Item::inArray($ret);
+               $items = Post::selectToArray(Item::DELIVER_FIELDLIST, $condition);
                if (!DBA::isResult($items)) {
                        return '';
                }
@@ -957,7 +955,7 @@ class DFRN
                $entry->appendChild($dfrnowner);
 
                if ($item['gravity'] != GRAVITY_PARENT) {
-                       $parent = Item::selectFirst(['guid', 'plink'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
+                       $parent = Post::selectFirst(['guid', 'plink'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
                        if (DBA::isResult($parent)) {
                                $attributes = ["ref" => $item['thr-parent'], "type" => "text/html",
                                        "href" => $parent['plink'],
@@ -1934,7 +1932,7 @@ class DFRN
 
                        $is_a_remote_action = false;
 
-                       $parent = Item::selectFirst(['thr-parent'], ['uri' => $item["thr-parent"]]);
+                       $parent = Post::selectFirst(['thr-parent'], ['uri' => $item["thr-parent"]]);
                        if (DBA::isResult($parent)) {
                                $r = q(
                                        "SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
@@ -2008,7 +2006,7 @@ class DFRN
                        if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . "/profile/" . $importer["nickname"])) {
                                $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
 
-                               $parent = Item::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer["importer_uid"]]);
+                               $parent = Post::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer["importer_uid"]]);
                                $item['parent'] = $parent['id'];
 
                                // send a notification
@@ -2087,13 +2085,13 @@ class DFRN
                                // split into two queries for performance issues
                                $condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"], 'gravity' => GRAVITY_ACTIVITY,
                                        'verb' => $item['verb'], 'parent-uri' => $item['thr-parent']];
-                               if (Item::exists($condition)) {
+                               if (Post::exists($condition)) {
                                        return false;
                                }
 
                                $condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"], 'gravity' => GRAVITY_ACTIVITY,
                                        'verb' => $item['verb'], 'thr-parent' => $item['thr-parent']];
-                               if (Item::exists($condition)) {
+                               if (Post::exists($condition)) {
                                        return false;
                                }
 
@@ -2111,7 +2109,7 @@ class DFRN
                                $xt = XML::parseString($item["target"]);
 
                                if ($xt->type == Activity\ObjectType::NOTE) {
-                                       $item_tag = Item::selectFirst(['id', 'uri-id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
+                                       $item_tag = Post::selectFirst(['id', 'uri-id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
 
                                        if (!DBA::isResult($item_tag)) {
                                                Logger::log("Query failed to execute, no result returned in " . __FUNCTION__);
@@ -2214,7 +2212,7 @@ class DFRN
 
                $item["edited"] = XML::getFirstNodeValue($xpath, "atom:updated/text()", $entry);
 
-               $current = Item::selectFirst(['id', 'uid', 'edited', 'body'],
+               $current = Post::selectFirst(['id', 'uid', 'edited', 'body'],
                        ['uri' => $item["uri"], 'uid' => $importer["importer_uid"]]
                );
                // Is there an existing item?
@@ -2559,7 +2557,7 @@ class DFRN
                }
 
                $condition = ['uri' => $uri, 'uid' => $importer["importer_uid"]];
-               $item = Item::selectFirst(['id', 'parent', 'contact-id', 'file', 'deleted', 'gravity'], $condition);
+               $item = Post::selectFirst(['id', 'parent', 'contact-id', 'file', 'deleted', 'gravity'], $condition);
                if (!DBA::isResult($item)) {
                        Logger::log("Item with uri " . $uri . " for user " . $importer["importer_uid"] . " wasn't found.", Logger::DEBUG);
                        return;
@@ -2579,7 +2577,7 @@ class DFRN
                // Comments can be deleted by the thread owner or comment owner
                if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer["id"])) {
                        $condition = ['id' => $item['parent'], 'contact-id' => $importer["id"]];
-                       if (!Item::exists($condition)) {
+                       if (!Post::exists($condition)) {
                                Logger::log("Item with uri " . $uri . " wasn't found or mustn't be deleted by contact " . $importer["id"] . " - ignoring deletion.", Logger::DEBUG);
                                return;
                        }
index 90c6e12edd20b6806c10e1ad87dd58181e77d4d0..34dc941400bf525c3622742a76476b26dd8be524 100644 (file)
@@ -76,9 +76,9 @@ class Diaspora
                        return $contacts;
                }
 
-               $items = Item::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
+               $items = Post::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
                        ['parent' => $item['parent'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
-               while ($item = DBA::fetch($items)) {
+               while ($item = Post::fetch($items)) {
                        $contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
                                ['id' => $item['author-id']]);
                        if (!DBA::isResult($contact) || empty($contact['batch']) ||
@@ -931,7 +931,7 @@ class Diaspora
         */
        private static function messageExists($uid, $guid)
        {
-               $item = Item::selectFirst(['id'], ['uid' => $uid, 'guid' => $guid]);
+               $item = Post::selectFirst(['id'], ['uid' => $uid, 'guid' => $guid]);
                if (DBA::isResult($item)) {
                        Logger::log("message ".$guid." already exists for user ".$uid);
                        return $item["id"];
@@ -1151,7 +1151,7 @@ class Diaspora
 
                $guid = urldecode($matches[2]);
 
-               $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
+               $item = Post::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
                if (DBA::isResult($item)) {
                        Logger::info('Found', ['id' => $item['id']]);
                        return $item['id'];
@@ -1161,7 +1161,7 @@ class Diaspora
                $ret = self::storeByGuid($guid, $matches[1], $uid);
                Logger::info('Result', ['ret' => $ret]);
 
-               $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
+               $item = Post::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
                if (DBA::isResult($item)) {
                        Logger::info('Found', ['id' => $item['id']]);
                        return $item['id'];
@@ -1188,7 +1188,7 @@ class Diaspora
                        'author-name', 'author-link', 'author-avatar', 'gravity',
                        'owner-name', 'owner-link', 'owner-avatar'];
                $condition = ['uid' => $uid, 'guid' => $guid];
-               $item = Item::selectFirst($fields, $condition);
+               $item = Post::selectFirst($fields, $condition);
 
                if (!DBA::isResult($item)) {
                        $person = FContact::getByURL($author);
@@ -1202,7 +1202,7 @@ class Diaspora
                        if ($result) {
                                Logger::log("Fetched missing item ".$guid." - result: ".$result, Logger::DEBUG);
 
-                               $item = Item::selectFirst($fields, $condition);
+                               $item = Post::selectFirst($fields, $condition);
                        }
                }
 
@@ -1410,7 +1410,7 @@ class Diaspora
         */
        private static function getUriFromGuid($author, $guid, $onlyfound = false)
        {
-               $item = Item::selectFirst(['uri'], ['guid' => $guid]);
+               $item = Post::selectFirst(['uri'], ['guid' => $guid]);
                if (DBA::isResult($item)) {
                        return $item["uri"];
                } elseif (!$onlyfound) {
@@ -1426,25 +1426,6 @@ class Diaspora
                return "";
        }
 
-       /**
-        * Fetch the guid from our database with a given uri
-        *
-        * @param string $uri Message uri
-        * @param string $uid Author handle
-        *
-        * @return string The post guid
-        * @throws \Exception
-        */
-       private static function getGuidFromUri($uri, $uid)
-       {
-               $item = Item::selectFirst(['guid'], ['uri' => $uri, 'uid' => $uid]);
-               if (DBA::isResult($item)) {
-                       return $item["guid"];
-               } else {
-                       return false;
-               }
-       }
-
        /**
         * Store the mentions in the tag table
         *
@@ -1815,7 +1796,7 @@ class Diaspora
 
                // like on comments have the comment as parent. So we need to fetch the toplevel parent
                if ($toplevel_parent_item['gravity'] != GRAVITY_PARENT) {
-                       $toplevel = Item::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]);
+                       $toplevel = Post::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]);
                        $origin = $toplevel["origin"];
                } else {
                        $origin = $toplevel_parent_item["origin"];
@@ -1993,9 +1974,9 @@ class Diaspora
                Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
 
                // Send all existing comments and likes to the requesting server
-               $comments = Item::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb'],
+               $comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb'],
                        ['parent' => $toplevel_parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
-               while ($comment = Item::fetch($comments)) {
+               while ($comment = Post::fetch($comments)) {
                        if (in_array($comment['verb'], [Activity::FOLLOW, Activity::TAG])) {
                                Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
                                continue;
@@ -2285,7 +2266,7 @@ class Diaspora
                $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
                        'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
-               $item = Item::selectFirst($fields, $condition);
+               $item = Post::selectFirst($fields, $condition);
 
                if (DBA::isResult($item)) {
                        Logger::log("reshared message ".$guid." already exists on system.");
@@ -2329,7 +2310,7 @@ class Diaspora
                                $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
                                        'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
                                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
-                               $item = Item::selectFirst($fields, $condition);
+                               $item = Post::selectFirst($fields, $condition);
 
                                if (DBA::isResult($item)) {
                                        // If it is a reshared post from another network then reformat to avoid display problems with two share elements
@@ -2355,7 +2336,7 @@ class Diaspora
         */
        private static function addReshareActivity($item, $parent_message_id, $guid, $author)
        {
-               $parent = Item::selectFirst(['uri', 'guid'], ['id' => $parent_message_id]);
+               $parent = Post::selectFirst(['uri', 'guid'], ['id' => $parent_message_id]);
 
                $datarray = [];
 
@@ -2554,20 +2535,20 @@ class Diaspora
                        $condition = ['guid' => $target_guid, 'deleted' => false, 'uid' => $importer['uid']];
                }
 
-               $r = Item::select($fields, $condition);
+               $r = Post::select($fields, $condition);
                if (!DBA::isResult($r)) {
                        Logger::log("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
                        return false;
                }
 
-               while ($item = Item::fetch($r)) {
+               while ($item = Post::fetch($r)) {
                        if (strstr($item['file'], '[')) {
                                Logger::log("Target guid " . $target_guid . " for user " . $item['uid'] . " is filed. So it won't be deleted.", Logger::DEBUG);
                                continue;
                        }
 
                        // Fetch the parent item
-                       $parent = Item::selectFirst(['author-link'], ['id' => $item['parent']]);
+                       $parent = Post::selectFirst(['author-link'], ['id' => $item['parent']]);
 
                        // Only delete it if the parent author really fits
                        if (!Strings::compareLink($parent["author-link"], $contact["url"]) && !Strings::compareLink($item["author-link"], $contact["url"])) {
@@ -2579,6 +2560,7 @@ class Diaspora
 
                        Logger::log("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item['parent'], Logger::DEBUG);
                }
+               DBA::close($r);
 
                return true;
        }
@@ -3263,7 +3245,7 @@ class Diaspora
 
                if (!empty($reshared['guid']) && $complete) {
                        $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
-                       $item = Item::selectFirst(['contact-id'], $condition);
+                       $item = Post::selectFirst(['contact-id'], $condition);
                        if (DBA::isResult($item)) {
                                $ret = [];
                                $ret["root_handle"] = self::handleFromContact($item["contact-id"]);
@@ -3540,7 +3522,7 @@ class Diaspora
         */
        private static function constructLike(array $item, array $owner)
        {
-               $parent = Item::selectFirst(['guid', 'uri', 'thr-parent'], ['uri' => $item["thr-parent"]]);
+               $parent = Post::selectFirst(['guid', 'uri', 'thr-parent'], ['uri' => $item["thr-parent"]]);
                if (!DBA::isResult($parent)) {
                        return false;
                }
@@ -3572,7 +3554,7 @@ class Diaspora
         */
        private static function constructAttend(array $item, array $owner)
        {
-               $parent = Item::selectFirst(['guid'], ['uri' => $item['thr-parent']]);
+               $parent = Post::selectFirst(['guid'], ['uri' => $item['thr-parent']]);
                if (!DBA::isResult($parent)) {
                        return false;
                }
@@ -3617,7 +3599,7 @@ class Diaspora
                        return $result;
                }
 
-               $toplevel_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item['parent'], 'parent' => $item['parent']]);
+               $toplevel_item = Post::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item['parent'], 'parent' => $item['parent']]);
                if (!DBA::isResult($toplevel_item)) {
                        Logger::error('Missing parent conversation item', ['parent' => $item['parent']]);
                        return false;
@@ -3625,7 +3607,7 @@ class Diaspora
 
                $thread_parent_item = $toplevel_item;
                if ($item['thr-parent'] != $item['parent-uri']) {
-                       $thread_parent_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
+                       $thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
                }
 
                $body = $item["body"];
@@ -4056,7 +4038,7 @@ class Diaspora
                        return false;
                }
 
-               $parent = Item::selectFirst(['parent-uri'], ['uri' => $item['thr-parent']]);
+               $parent = Post::selectFirst(['parent-uri'], ['uri' => $item['thr-parent']]);
                if (!DBA::isResult($parent)) {
                        return;
                }
index 41b63def5865f3632cf5ce55ed88797c8fe607f2..6fd5ea7f87f096e50d03d96c348c7a17cb2a4d0b 100644 (file)
@@ -341,7 +341,7 @@ class Feed
                        if (!$dryRun) {
                                $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
                                        $importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
-                               $previous = Item::selectFirst(['id', 'created'], $condition);
+                               $previous = Post::selectFirst(['id', 'created'], $condition);
                                if (DBA::isResult($previous)) {
                                        // Use the creation date when the post had been stored. It can happen this date changes in the feed.
                                        $creation_dates[] = $previous['created'];
@@ -556,7 +556,7 @@ class Feed
                        }
 
                        $condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
-                       if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
+                       if (!Post::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
                                if (!$notify) {
                                        Post\Delayed::publish($item, $notify, $taglist, $attachments);
                                } else {
@@ -1041,7 +1041,7 @@ class Feed
 
                $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => Protocol::FEDERATED];
-               $repeated_item = Item::selectFirst([], $condition);
+               $repeated_item = Post::selectFirst([], $condition);
                if (!DBA::isResult($repeated_item)) {
                        return false;
                }
@@ -1133,9 +1133,9 @@ class Feed
                $mentioned = [];
 
                if ($item['gravity'] != GRAVITY_PARENT) {
-                       $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
+                       $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
 
-                       $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
+                       $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
 
                        if (DBA::isResult($thrparent)) {
                                $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
index f55fd4dadba0185dd5188df7690015404d5f4ebb..64ed6ae511f5c59aeae6838356f78598125b1077 100644 (file)
@@ -445,7 +445,7 @@ class OStatus
                        }
 
                        // Deletions come with the same uri, so we check for duplicates after processing deletions
-                       if (Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
+                       if (Post::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
                                Logger::log('Post with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', Logger::DEBUG);
                                continue;
                        } else {
@@ -533,7 +533,7 @@ class OStatus
                                                }
                                        }
                                        foreach (self::$itemlist as $item) {
-                                               $found = Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
+                                               $found = Post::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
                                                if ($found) {
                                                        Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", Logger::DEBUG);
                                                } elseif ($item['contact-id'] < 0) {
@@ -561,7 +561,7 @@ class OStatus
        private static function deleteNotice(array $item)
        {
                $condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'uri' => $item['uri']];
-               if (!Item::exists($condition)) {
+               if (!Post::exists($condition)) {
                        Logger::log('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it.");
                        return;
                }
@@ -697,7 +697,7 @@ class OStatus
                }
 
                if (isset($item["thr-parent"])) {
-                       if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['thr-parent']])) {
+                       if (!Post::exists(['uid' => $importer["uid"], 'uri' => $item['thr-parent']])) {
                                if ($related != '') {
                                        self::fetchRelated($related, $item["thr-parent"], $importer);
                                }
@@ -1593,7 +1593,7 @@ class OStatus
 
                $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]];
-               $repeated_item = Item::selectFirst([], $condition);
+               $repeated_item = Post::selectFirst([], $condition);
                if (!DBA::isResult($repeated_item)) {
                        return false;
                }
@@ -1659,7 +1659,7 @@ class OStatus
                $verb = ActivityNamespace::ACTIVITY_SCHEMA . "favorite";
                self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
 
-               $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
+               $parent = Post::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
                if (DBA::isResult($parent)) {
                        $as_object = $doc->createElement("activity:object");
 
@@ -1927,9 +1927,9 @@ class OStatus
                $mentioned = [];
 
                if ($item['gravity'] != GRAVITY_PARENT) {
-                       $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
+                       $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
 
-                       $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
+                       $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
 
                        if (DBA::isResult($thrparent)) {
                                $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
index c982e0bc291aad2dc2e57bd93049d1787c81bd69..7eed4f71a504ffd429f63b34237fa53871c9520f 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\GServer;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\Search;
 use Friendica\Model\Tag;
 use Friendica\Util\DateTimeFormat;
@@ -253,7 +254,7 @@ class Relay
 
                if (DI::config()->get("system", "relay_directly", false)) {
                        // We distribute our stuff based on the parent to ensure that the thread will be complete
-                       $parent = Item::selectFirst(['uri-id'], ['id' => $item_id]);
+                       $parent = Post::selectFirst(['uri-id'], ['id' => $item_id]);
                        if (!DBA::isResult($parent)) {
                                return;
                        }
index 2bf869b4dec1fe0bc3048cd9817243239eea6ee0..9f0af133e67aae6563d5bf2a827e4a0a784b8264 100644 (file)
@@ -48,7 +48,7 @@ class APDelivery
                if (ActivityPub\Transmitter::archivedInbox($inbox)) {
                        Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]);
                        if (in_array($cmd, [Delivery::POST])) {
-                               $item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
+                               $item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
                                Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? 0);
                        }
                        return;
@@ -81,7 +81,7 @@ class APDelivery
                }
 
                // This should never fail and is temporariy (until the move to the "post" structure)
-               $item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
+               $item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
                $uriid = $item['uri-id'] ?? 0;
                $gsid = null;
 
index bd97b267222b799bc6ae5c31d8bcad4c25597f4b..3c6b8775b8cef459d5d4844e83c16b42e144050a 100644 (file)
@@ -74,7 +74,7 @@ class Delivery
                        $uid = $target_id;
                        $target_item = [];
                } else {
-                       $item = Model\Item::selectFirst(['parent'], ['id' => $target_id]);
+                       $item = Model\Post::selectFirst(['parent'], ['id' => $target_id]);
                        if (!DBA::isResult($item) || empty($item['parent'])) {
                                return;
                        }
@@ -82,9 +82,9 @@ class Delivery
 
                        $condition = ['id' => [$target_id, $parent_id], 'visible' => true, 'moderated' => false];
                        $params = ['order' => ['id']];
-                       $itemdata = Model\Item::select([], $condition, $params);
+                       $itemdata = Model\Post::select([], $condition, $params);
 
-                       while ($item = Model\Item::fetch($itemdata)) {
+                       while ($item = Model\Post::fetch($itemdata)) {
                                if ($item['verb'] == Activity::ANNOUNCE) {
                                        continue;
                                }
@@ -121,7 +121,7 @@ class Delivery
                        }
 
                        $condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']];
-                       $thr_parent = Model\Item::selectFirst(['network', 'object'], $condition);
+                       $thr_parent = Model\Post::selectFirst(['network', 'object'], $condition);
                        if (!DBA::isResult($thr_parent)) {
                                // Shouldn't happen. But when this does, we just take the parent as thread parent.
                                // That's totally okay for what we use this variable here.
@@ -593,13 +593,13 @@ class Delivery
 
                        if (empty($target_item['title'])) {
                                $condition = ['uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
-                               $title = Model\Item::selectFirst(['title'], $condition);
+                               $title = Model\Post::selectFirst(['title'], $condition);
 
                                if (DBA::isResult($title) && ($title['title'] != '')) {
                                        $subject = $title['title'];
                                } else {
                                        $condition = ['parent-uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
-                                       $title = Model\Item::selectFirst(['title'], $condition);
+                                       $title = Model\Post::selectFirst(['title'], $condition);
 
                                        if (DBA::isResult($title) && ($title['title'] != '')) {
                                                $subject = $title['title'];
index 93fa2b57e59b3bb5e2f5420fa5249f9aa26c54f5..7a78e985c171277d905a803729fa3eb7f802438f 100644 (file)
@@ -101,7 +101,7 @@ class Notifier
                } else {
                        // find ancestors
                        $condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
-                       $target_item = Item::selectFirst([], $condition);
+                       $target_item = Post::selectFirst([], $condition);
 
                        if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
                                Logger::info('No target item', ['cmd' => $cmd, 'target' => $target_id]);
@@ -119,13 +119,13 @@ class Notifier
 
                        $condition = ['parent' => $target_item['parent'], 'visible' => true, 'moderated' => false];
                        $params = ['order' => ['id']];
-                       $items_stmt = Item::select([], $condition, $params);
+                       $items_stmt = Post::select([], $condition, $params);
                        if (!DBA::isResult($items_stmt)) {
                                Logger::info('No item found', ['cmd' => $cmd, 'target' => $target_id]);
                                return;
                        }
 
-                       $items = Item::inArray($items_stmt);
+                       $items = Post::inArray($items_stmt);
 
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {
@@ -165,7 +165,7 @@ class Notifier
 
                        $fields = ['network', 'author-id', 'author-link', 'author-network', 'owner-id'];
                        $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]];
-                       $thr_parent = Item::selectFirst($fields, $condition);
+                       $thr_parent = Post::selectFirst($fields, $condition);
                        if (empty($thr_parent)) {
                                $thr_parent = $parent;
                        }
index bb3dd97198fe5dde383f6c1436beae935ea23fb1..7a674c87d0d8c6b41e62a42eb0a84c3f588f8077 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
@@ -249,7 +250,7 @@ class OnePoll
                                        // Have we seen it before?
                                        $fields = ['deleted', 'id'];
                                        $condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
-                                       $item = Item::selectFirst($fields, $condition);
+                                       $item = Post::selectFirst($fields, $condition);
                                        if (DBA::isResult($item)) {
                                                Logger::log("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],Logger::DEBUG);
 
@@ -298,7 +299,7 @@ class OnePoll
                                                        }
                                                }
                                                $condition = ['uri' => $refs_arr, 'uid' => $importer_uid];
-                                               $parent = Item::selectFirst(['uri'], $condition);
+                                               $parent = Post::selectFirst(['uri'], $condition);
                                                if (DBA::isResult($parent)) {
                                                        $datarray['thr-parent'] = $parent['uri'];
                                                }
@@ -331,7 +332,7 @@ class OnePoll
                                        if (empty($datarray['thr-parent']) && $reply) {
                                                $condition = ['title' => $datarray['title'], 'uid' => $importer_uid, 'network' => Protocol::MAIL];
                                                $params = ['order' => ['created' => true]];
-                                               $parent = Item::selectFirst(['uri'], $condition, $params);
+                                               $parent = Post::selectFirst(['uri'], $condition, $params);
                                                if (DBA::isResult($parent)) {
                                                        $datarray['thr-parent'] = $parent['uri'];
                                                }
index a84cb0d53760701f9eb9a825b5a24c22fbf3255d..6662e58a58201bbc91303534ed0a3f4cde6382d1 100644 (file)
@@ -23,8 +23,8 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
-use Friendica\Model\Item;
 use Friendica\Model\Photo;
+use Friendica\Model\Post;
 
 /**
  * Removes orphaned data from deleted contacts
@@ -47,13 +47,13 @@ class RemoveContact {
                        $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
                }
                do {
-                       $items = Item::select(['id', 'guid'], $condition, ['limit' => 100]);
-                       while ($item = Item::fetch($items)) {
+                       $items = Post::select(['id', 'guid'], $condition, ['limit' => 100]);
+                       while ($item = Post::fetch($items)) {
                                Logger::info('Delete removed contact item', ['id' => $item['id'], 'guid' => $item['guid']]);
                                DBA::delete('item', ['id' => $item['id']]);
                        }
                        DBA::close($items);
-               } while (Item::exists($condition));
+               } while (Post::exists($condition));
 
                Photo::delete(['contact-id' => $id]);
                $ret = DBA::delete('contact', ['id' => $id]);
index 018d17a46e68e0a415666f2e038395587e8a0128..997329e014b9329cb2645e655cb9a244ba6bad0a 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Worker;
 
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 
 /**
  * Removes orphaned data from deleted users
@@ -39,11 +40,11 @@ class RemoveUser {
                // Now we delete all user items
                $condition = ['uid' => $uid, 'deleted' => false];
                do {
-                       $items = Item::select(['id'], $condition, ['limit' => 100]);
-                       while ($item = Item::fetch($items)) {
+                       $items = Post::select(['id'], $condition, ['limit' => 100]);
+                       while ($item = Post::fetch($items)) {
                                Item::markForDeletionById($item['id'], PRIORITY_NEGLIGIBLE);
                        }
                        DBA::close($items);
-               } while (Item::exists($condition));
+               } while (Post::exists($condition));
        }
 }