Built Playpen icon updating into Misuzu.

Was previously handled by a stinky script.
This commit is contained in:
flash 2024-05-30 22:00:39 +00:00
parent 5d3e1d4960
commit 36bcf1ab1d

View file

@ -149,6 +149,88 @@ msz_sched_task_func('Recalculate permissions (maybe)...', false, function() use
$msz->getPerms()->precalculatePermissions($msz->getForumContext()->getCategories());
});
msz_sched_task_func('Omega disliking comments...', true, function() use ($msz) {
$commentIds = $msz->getConfig()->getArray('comments.omegadislike');
if(!is_array($commentIds))
return;
$dbConn = $msz->getDbConn();
$stmt = $dbConn->prepare('REPLACE INTO msz_comments_votes (comment_id, user_id, comment_vote) SELECT ?, user_id, -1 FROM msz_users');
foreach($commentIds as $commentId) {
$stmt->addParameter(1, $commentId);
$stmt->execute();
}
});
msz_sched_task_func('Announcing random topics...', true, function() use ($msz) {
$categoryIds = $msz->getConfig()->getArray('forum.rngannounce');
if(!is_array($categoryIds))
return;
$dbConn = $msz->getDbConn();
$stmtRevert = $dbConn->prepare('UPDATE msz_forum_topics SET topic_type = 0 WHERE forum_id = ? AND topic_type = 2');
$stmtRandom = $dbConn->prepare('SELECT topic_id FROM msz_forum_topics WHERE forum_id = ? AND topic_deleted IS NULL ORDER BY RAND() LIMIT 1');
$stmtAnnounce = $dbConn->prepare('UPDATE msz_forum_topics SET topic_type = 2 WHERE topic_id = ?');
foreach($categoryIds as $categoryId) {
$stmtRevert->addParameter(1, $categoryId);
$stmtRevert->execute();
$stmtRandom->addParameter(1, $categoryId);
$stmtRandom->execute();
$resultRandom = $stmtRandom->getResult();
if($resultRandom->next()) {
$stmtAnnounce->addParameter(1, $resultRandom->getInteger(0));
$stmtAnnounce->execute();
}
}
});
msz_sched_task_func('Changing category icons...', false, function() use ($msz) {
$config = $msz->getConfig();
$categoryIds = $config->getArray('forum.rngicon');
if(!is_array($categoryIds))
return;
$dbConn = $msz->getDbConn();
$stmtIcon = $dbConn->prepare('UPDATE msz_forum_categories SET forum_icon = COALESCE(?, forum_icon), forum_name = COALESCE(?, forum_name), forum_colour = ((ROUND(RAND() * 255) << 16) | (ROUND(RAND() * 255) << 8) | ROUND(RAND() * 255)) WHERE forum_id = ?');
$stmtUnlock = $dbConn->prepare('UPDATE msz_forum_topics SET topic_locked = IF(?, NULL, COALESCE(topic_locked, NOW())) WHERE topic_id = ?');
foreach($categoryIds as $categoryId) {
$scoped = $config->scopeTo(sprintf('forum.rngicon.fc%d', $categoryId));
$icons = $scoped->getArray('icons');
$icon = $icons[array_rand($icons)];
$name = null;
$names = $scoped->getArray('names');
for($i = 0; $i < count($names); $i += 2)
if($names[$i] === $icon) {
$name = $names[$i + 1] ?? null;
break;
}
$name ??= $scoped->getString('name');
$stmtIcon->addParameter(1, $icon);
$stmtIcon->addParameter(2, empty($name) ? null : $name);
$stmtIcon->addParameter(3, $categoryId);
$stmtIcon->execute();
$unlockModes = $scoped->getArray('unlock');
foreach($unlockModes as $unlockMode) {
$unlockScoped = $scoped->scopeTo(sprintf('unlock.%s', $unlockMode));
$topicId = $unlockScoped->getInteger('topic');
$match = $unlockScoped->getArray('match');
$matches = in_array($icon, $match);
$stmtUnlock->addParameter(1, $matches ? 1 : 0);
$stmtUnlock->addParameter(2, $topicId);
$stmtUnlock->execute();
}
}
});
echo 'Running ' . count($schedTasks) . ' tasks...' . PHP_EOL;
$dbConn = $msz->getDbConn();