]> git.mxchange.org Git - friendica.git/commitdiff
New class for delayed postings
authorMichael <heluecht@pirati.ca>
Mon, 30 Nov 2020 06:59:00 +0000 (06:59 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 30 Nov 2020 06:59:00 +0000 (06:59 +0000)
src/Protocol/Feed.php
src/Worker/DelayedPublish.php [new file with mode: 0644]

index eb6f71ff50f32279233ab050bdd3f71c61852298..0c945a1809db6ea7274a2c31960a0b7b779d2a45 100644 (file)
@@ -29,6 +29,7 @@ use Friendica\Content\Text\HTML;
 use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
+use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -634,20 +635,8 @@ class Feed
                                        $post_delay += $delay;
                                }
 
-                               $id = Item::insert($posting['item'], $posting['notify']);
-
-                               Logger::notice("Feed for contact " . $contact["url"] . " stored under id " . $id);
-
-                               if (!empty($id) && (!empty($posting['taglist']) || !empty($posting['attachments']))) {
-                                       $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
-                                       foreach ($posting['taglist'] as $tag) {
-                                               Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
-                                       }
-                                       foreach ($posting['attachments'] as $attachment) {
-                                               $attachment['uri-id'] = $feeditem['uri-id'];
-                                               Post\Media::insert($attachment);
-                                       }
-                               }
+                               Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $post_delay],
+                                       'DelayedPublish', $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
                        }
                }
 
diff --git a/src/Worker/DelayedPublish.php b/src/Worker/DelayedPublish.php
new file mode 100644 (file)
index 0000000..3dad540
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Worker;
+
+use Friendica\Core\Logger;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
+use Friendica\Model\Tag;
+
+class DelayedPublish
+{
+        /**
+        * Publish a post, used for delayed postings
+         *
+         * @param array $item
+         * @param integer $notify
+         * @param array $taglist
+         * @param array $attachments
+         * @return void
+         */
+       public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [])
+       {
+               $id = Item::insert($item, $notify);
+
+               Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);
+
+               if (!empty($id) && (!empty($taglist) || !empty($attachments))) {
+                       $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
+                       foreach ($taglist as $tag) {
+                               Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
+                       }
+                       foreach ($attachments as $attachment) {
+                               $attachment['uri-id'] = $feeditem['uri-id'];
+                               Post\Media::insert($attachment);
+                       }
+               }
+
+       }
+}