Use a centralized function to delete delayed entries

This commit is contained in:
Michael 2021-08-02 20:56:34 +00:00
parent 5a2fa2f81a
commit 6c8a4a2552
3 changed files with 28 additions and 25 deletions

View file

@ -98,6 +98,23 @@ class Delayed
return DBA::delete('delayed-post', ['uri' => $uri, 'uid' => $uid]); 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 * Check if an entry exists
* *

View file

@ -25,6 +25,7 @@ use Friendica\App\Router;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
/** /**
@ -49,19 +50,11 @@ class ScheduledStatuses extends BaseApi
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
$condtion = ['id' => $parameters['id'], 'uid' => $uid]; if (!DBA::exists('delayed-post', ['id' => $parameters['id'], 'uid' => $uid])) {
$post = DBA::selectFirst('delayed-post', ['id', 'wid'], $condtion);
if (empty($post['id'])) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
if (!DBA::delete('delayed-post', $condtion)) { Post\Delayed::deleteById($parameters['id']);
DI::mstdnError()->RecordNotFound();
}
if (!DBA::delete('workerqueue', ['id' => $post['wid']])) {
DI::mstdnError()->RecordNotFound();
}
System::jsonExit([]); System::jsonExit([]);
} }

View file

@ -41,7 +41,12 @@ class Schedule extends BaseProfile
if (empty($_REQUEST['delete'])) { if (empty($_REQUEST['delete'])) {
throw new HTTPException\BadRequestException(); 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 = []) public static function content(array $parameters = [])
@ -83,16 +88,4 @@ class Schedule extends BaseProfile
return $o; 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']]);
}
} }