Use a centralized function to delete delayed entries
This commit is contained in:
parent
5a2fa2f81a
commit
6c8a4a2552
|
@ -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);
|
||||
|
|
|
@ -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([]);
|
||||
}
|
||||
|
|
|
@ -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']]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user