diff --git a/src/Model/Post/Delayed.php b/src/Model/Post/Delayed.php index 0bae1a8e2e..dd26869d1c 100644 --- a/src/Model/Post/Delayed.php +++ b/src/Model/Post/Delayed.php @@ -44,7 +44,7 @@ class Delayed * @param array $taglist * @param array $attachments * @return int ID of the created delayed post entry - */ + */ public static function add(string $uri, array $item, int $notify = 0, bool $unprepared = false, string $delayed = '', array $taglist = [], array $attachments = []) { if (empty($item['uid']) || self::exists($uri, $item['uid'])) { @@ -98,6 +98,23 @@ class Delayed return DBA::delete('delayed-post', ['uri' => $uri, 'uid' => $uid]); } + /** + * Delete scheduled posts and the associated workerqueue entry + * + * @param integer $id + * @return void + */ + public static function deleteById(int $id) + { + $post = DBA::selectFirst('delayed-post', ['wid'], ['id' => $id]); + if (empty($post['wid'])) { + return; + } + + DBA::delete('delayed-post', ['id' => $id]); + DBA::delete('workerqueue', ['id' => $post['wid']]); + } + /** * Check if an entry exists * @@ -192,7 +209,7 @@ class Delayed if (self::exists($uri, $item['uid'])) { self::delete($uri, $item['uid']); } - + return $id; } $id = Item::insert($item, $notify); diff --git a/src/Module/Api/Mastodon/ScheduledStatuses.php b/src/Module/Api/Mastodon/ScheduledStatuses.php index 7f34900524..5b43f4515a 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -25,6 +25,7 @@ use Friendica\App\Router; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Post; use Friendica\Module\BaseApi; /** @@ -49,19 +50,11 @@ class ScheduledStatuses extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $condtion = ['id' => $parameters['id'], 'uid' => $uid]; - $post = DBA::selectFirst('delayed-post', ['id', 'wid'], $condtion); - if (empty($post['id'])) { + if (!DBA::exists('delayed-post', ['id' => $parameters['id'], 'uid' => $uid])) { DI::mstdnError()->RecordNotFound(); } - if (!DBA::delete('delayed-post', $condtion)) { - DI::mstdnError()->RecordNotFound(); - } - - if (!DBA::delete('workerqueue', ['id' => $post['wid']])) { - DI::mstdnError()->RecordNotFound(); - } + Post\Delayed::deleteById($parameters['id']); System::jsonExit([]); } diff --git a/src/Module/Profile/Schedule.php b/src/Module/Profile/Schedule.php index 675e132db9..ae76c57f1d 100644 --- a/src/Module/Profile/Schedule.php +++ b/src/Module/Profile/Schedule.php @@ -41,7 +41,12 @@ class Schedule extends BaseProfile if (empty($_REQUEST['delete'])) { throw new HTTPException\BadRequestException(); } - self::deleteSchedule($_REQUEST['delete']); + + if (!DBA::exists('delayed-post', ['id' => $_REQUEST['delete'], 'uid' => local_user()])) { + throw new HTTPException\NotFoundException(); + } + + Post\Delayed::deleteById($_REQUEST['delete']); } public static function content(array $parameters = []) @@ -83,16 +88,4 @@ class Schedule extends BaseProfile return $o; } - - private static function deleteSchedule($id) - { - $condtion = ['id' => $id, 'uid' => local_user()]; - $post = DBA::selectFirst('delayed-post', ['id', 'wid'], $condtion); - if (empty($post['id'])) { - return; - } - - DBA::delete('delayed-post', ['id' => $id, 'uid' => local_user()]); - DBA::delete('workerqueue', ['id' => $post['wid']]); - } }