diff --git a/models/article.js b/models/article.js index ca510ad..977a6ed 100644 --- a/models/article.js +++ b/models/article.js @@ -91,6 +91,19 @@ class Article extends Model { return user && (this.allow_comment || user.is_admin || this.user_id === user.id); } + async resetReplyCountAndTime() { + let ArticleComment = syzoj.model('article-comment'); + await syzoj.utils.lock(['Article::resetReplyCountAndTime', this.id], async () => { + this.comments_num = await ArticleComment.count({ article_id: this.id }); + if (this.comments_num === 0) { + this.sort_time = this.public_time; + } else { + this.sort_time = await ArticleComment.model.max('public_time', { where: { article_id: this.id } }); + } + await this.save(); + }); + } + getModel() { return model; } }; diff --git a/modules/admin.js b/modules/admin.js index e68228b..72673b9 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -320,6 +320,11 @@ app.post('/admin/other', async (req, res) => { for (const p of problems) { await p.resetSubmissionCount(); } + } else if (req.body.type === 'reset_discussion') { + const articles = await Article.query(); + for (const a of articles) { + await a.resetReplyCountAndTime(); + } } else { throw new ErrorMessage("操作类型不正确"); } diff --git a/views/admin_other.ejs b/views/admin_other.ejs index ee5a8dd..d0b1ef6 100644 --- a/views/admin_other.ejs +++ b/views/admin_other.ejs @@ -1,7 +1,8 @@ <% this.adminPage = 'other'; %> <% include admin_header %>
- +

+

<% include admin_footer %>