mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
* Add new queue system * Amend creation of task from new * Fix unused terms * Prevent task returning error from running infinitely * Run tasks in transactions * Update gitignore and package-lock * Use PDO helpers for transaction * WIP convert forum post task * Trigger forum post conversion during upgrade * Fix task scheduling and increase forum posts converted to 50 * Rename ONE_OF to IN
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
class ConvertForumPostTask extends Task {
|
|
|
|
public function run(): string {
|
|
$start = $this->getFragmentNext() ?? 0;
|
|
$end = $start + 50;
|
|
$nextStatus = Task::STATUS_READY;
|
|
|
|
if ($end > $this->getFragmentTotal()) {
|
|
$end = $this->getFragmentTotal();
|
|
$nextStatus = Task::STATUS_COMPLETED;
|
|
}
|
|
|
|
$posts = DB::getInstance()->query(
|
|
<<<SQL
|
|
SELECT `id`,
|
|
`post_content`
|
|
FROM nl2_posts
|
|
LIMIT $start, 50
|
|
SQL
|
|
);
|
|
|
|
if ($posts->count()) {
|
|
$posts = $posts->results();
|
|
foreach ($posts as $post) {
|
|
DB::getInstance()->update('posts', $post->id, [
|
|
'post_content' => Output::getDecoded($post->post_content),
|
|
]);
|
|
}
|
|
}
|
|
|
|
$this->setOutput(['start' => $start, 'end' => $end, 'next_status' => $nextStatus]);
|
|
$this->setFragmentNext($end);
|
|
return $nextStatus;
|
|
}
|
|
|
|
/**
|
|
* Schedule this task
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function schedule() {
|
|
$hasBeenScheduled = DB::getInstance()->query('SELECT COUNT(*) c FROM nl2_queue WHERE `task` = \'ConvertForumPostTask\'')->first()->c;
|
|
|
|
if (!$hasBeenScheduled) {
|
|
$totalForumPosts = DB::getInstance()->query('SELECT COUNT(*) c FROM nl2_posts')->first()->c;
|
|
|
|
Queue::schedule((new ConvertForumPostTask())->fromNew(
|
|
Module::getIdFromName('Forum'),
|
|
'Convert forum posts',
|
|
[],
|
|
date('U'),
|
|
null,
|
|
null,
|
|
true,
|
|
$totalForumPosts
|
|
));
|
|
}
|
|
}
|
|
}
|