From cd96955fcf903aded20c3da2b819fdcff396cca3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Dec 2020 18:17:50 +0000 Subject: [PATCH] Fix: posted unprepared posts hadn't been deleted --- src/Model/Post/Delayed.php | 23 ++++++++++++++++++----- src/Worker/DelayedPublish.php | 5 +++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Model/Post/Delayed.php b/src/Model/Post/Delayed.php index 913bcedae..0e6d8b921 100644 --- a/src/Model/Post/Delayed.php +++ b/src/Model/Post/Delayed.php @@ -63,7 +63,7 @@ class Delayed Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]); - if (!Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared)) { + if (!Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared, $uri)) { return false; } @@ -106,9 +106,10 @@ class Delayed * @param array $taglist * @param array $attachments * @param bool $unprepared + * @param string $uri * @return bool */ - public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false) + public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '') { if ($unprepared) { $_SESSION['authenticated'] = true; @@ -126,15 +127,27 @@ class Delayed require_once 'mod/item.php'; $id = item_post(DI::app()); - Logger::notice('Unprepared post stored', ['id' => $id, 'uid' => $item['uid'], 'extid' => $item['extid']]); + if (empty($uri) && !empty($item['extid'])) { + $uri = $item['extid']; + } + + Logger::notice('Unprepared post stored', ['id' => $id, 'uid' => $item['uid'], 'uri' => $uri]); + if (self::exists($uri, $item['uid'])) { + self::delete($uri, $item['uid']); + } + return $id; } $id = Item::insert($item, $notify); Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]); - if (!empty($item['uri']) && self::exists($item['uri'], $item['uid'])) { - self::delete($item['uri'], $item['uid']); + if (empty($uri) && !empty($item['uri'])) { + $uri = $item['uri']; + } + + if (!empty($uri) && self::exists($uri, $item['uid'])) { + self::delete($uri, $item['uid']); } if (!empty($id) && (!empty($taglist) || !empty($attachments))) { diff --git a/src/Worker/DelayedPublish.php b/src/Worker/DelayedPublish.php index 2d08b25b0..a76e26ef7 100644 --- a/src/Worker/DelayedPublish.php +++ b/src/Worker/DelayedPublish.php @@ -34,11 +34,12 @@ class DelayedPublish * @param array $taglist * @param array $attachments * @param bool $unprepared + * @param string $uri * @return void */ - public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false) + public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '') { - $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared); + $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared, $uri); Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id'], 'notify' => $notify, 'unprepared' => $unprepared]); } }