无法删除没有类别的主题

我数据库中有一个主题,它的 category_id 对应的类别已被删除。我可以通过它的 id 直接打开这个主题:
url: …/t/3

在 topics 表中,id = 3 的主题的 category = 4。但是这个类别已经被删除,不在 categories 表中。许多这样的丢失主题我可以删除。但是这个主题无法删除,因为属性 closed 和 archived 都是 true。

如果我在弹出菜单中选择“永久删除”这个主题,我会收到错误消息:
“发生错误:此主题有未删除的帖子。请先永久删除它们,然后再永久删除该主题。”

有什么办法可以在数据库中插入一个 id 为 4 的虚拟类别,或者删除这个丢失的主题吗?

我认为那是 General 类别的主题?通常情况下,主题是无法在用户界面中删除的。

您想彻底删除这个主题的原因是什么?

1 个赞

因为这个类别不太容易找到,但哪个更重要:侧边栏中所有类别的链接不再起作用。 如果我尝试打开 …/categories,我会收到错误消息:“出错,出了些问题。”,并且在浏览器控制台中显示错误消息:

Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    Ember 2
    _join client-error-handler.js:88
    join client-error-handler.js:88
    p bookmark.js:114
    h bookmark.js:114
    $ topic.js:1017
    trigger composer-action-title.js:62
    transitionStarted add-translation.js:27
    loading ace-editor.js:176
    D upload.js:65
    triggerEvent upload.js:65
    trigger form-template-validation.js:54
    _handleSlowTransition upload.js:65
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54
binary.js:7
Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    success base.js:71
    l loader.js:1286
    fireWith loader.js:1286
    jQuery 4
    a base.js:71
    e named-references.js:49
    e named-references.js:49
    A base.js:71
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54

TypeError: t.category_list.categories 未定义
s form-template-validation.js:54
categoriesFrom form-template-validation.js:54
_findCategoriesAndTopics item.js:166
k named-references.js:49
w named-references.js:49
invoke client-error-handler.js:88
flush client-error-handler.js:88
flush client-error-handler.js:88
_end client-error-handler.js:88
end client-error-handler.js:88
_run client-error-handler.js:88
run client-error-handler.js:88
d bookmark.js:114
success base.js:71
l loader.js:1286
fireWith loader.js:1286
jQuery 4
a base.js:71
e named-references.js:49
e named-references.js:49
A base.js:71
_findCategoriesAndTopics item.js:166
k named-references.js:49
w named-references.js:49
invoke client-error-handler.js:88
flush client-error-handler.js:88
flush client-error-handler.js:88
_end client-error-handler.js:88
end client-error-handler.js:88
_runExpiredTimers client-error-handler.js:88
setTimeout handler*setTimeout client-error-handler.js:88
_installTimerTimeout client-error-handler.js:88
_later client-error-handler.js:88
later client-error-handler.js:88

2 个赞

听起来好像有人在类别包含主题时删除了它?这不应该发生。我认为你需要做类似的事情:

rails c
c=Category.last; # 或者其他获取类别的方法
Topic.where(category_id: 4).update_all(category_id: c.id)

如果您的 General 类别已通过 UI 安全删除,那么 About 主题预计也会被软删除,就像您看到的那样。这不应该引起任何问题。:thinking:

我认为可能还有其他问题。您的 /logs 页面上是否有关于该错误的更多详细信息?

1 个赞

这似乎不起作用:

discourse(prod)> Topic.where(category_id: 4).update_all(category_id: 20)
=> 0
discourse(prod)> Topic.where(id: 3).update_all(category_id: 20)
=> 0

在数据浏览器中,我得到:

Select id, closed, archived, title,category_id
from topics
where id = '3'

result:
id 	closed 	archived 	title 	category_id
3 	true 	true 	Über die Kategorie Team 	4

嗯。我以为你那个坏掉的主题的 category_id 是 4。

那是我最好的猜测。如果你有预算,可以在 Marketplace 中寻求帮助。我认为你需要找人进入 rails 来看看是否能弄清楚。

1 个赞

Marketplace 始终是一个选项,尤其是在紧急情况下。 :heart:

不过,这里提供更多细节可能有助于激发社区的响应。 :crossed_fingers:

你们似乎都确信根本原因就是这个话题。如果数据浏览器能找到它,那么你们应该能在 rails 控制台中找到它。如果你们能找到它,那么你们应该能使用 post_destroyer 来删除它?

(不过我不太敢推荐它,因为我还没有完全弄清楚问题的根源所在)

3 个赞

是的,在 Ruby 控制台中,我可以看到该主题:

result = ActiveRecord::Base.lease_connection.exec_query('SELECT id, category_id FROM topics WHERE id = 3')
result.rows
=> [[3, 4]]

但是在 Topic 中什么也没有

Topic.where(id: 3)
=> []

正如你所见,找到它是可能的。但我不知道 Ruby 语法如何精确删除这个表项。

嗯。 :thinking: 能够单向找到但无法双向找到,这很不寻常。

rails console 可能有点像一把锋利的刀,所以最好弄清楚到底出了什么问题,以尽量减少任何意外/连锁反应。

这个分类最初是如何被删除的?

(以防万一问题不是由这个孤立的主题引起的,我也会顺便介绍一下检查安全模式以及在您的 YourSite/logs 页面上查看有关错误的更多信息的基本知识)

不过我不知道您的数据是否处于分类删除捕获机制可以提供帮助的状态? Bulk delete all topics in a category

问得好。这是多年前由另一位管理员完成的。

与此同时,我通过以下方式直接在 rails 控制台中删除了这个主题:

result = ActiveRecord::Base.lease_connection.exec_delete('DELETE FROM topics WHERE id = 3')

之后,主题就被删除了 :grinning_face:

1 个赞

这是否也解决了你侧边栏中那个不正常的分类链接?

有趣的是,它明明已经正常运行了好几年,现在才出现问题。

如果你弄清楚了其中的联系,请告诉我。:slight_smile:

1 个赞

不幸的是,这并没有解决类别链接的错误。但目前不可删除的帖子的问题已经解决了。类别问题也没有记录在日志中。我将在未来几天内解决这个问题。

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.