Unlist a topic using rails console

AI 生成的摘要

A user, shahidh, needed to unlist all existing topics using the rails console. They tried updating the unlisted column, but it didn’t exist. bloomexperiment suggested trying the listed column, setting it to false, but that didn’t exist either. After checking the database, Mittineague provided the correct solution: updating the visible column to false. shahidh successfully unlisted the topics using the following command: topic.update_status("visible", false, Discourse.system_user).

We have a use case where we need to close all existing topics and unlist them. I have closed all topics using the rails console by executing

Topic.where(closed: false).find_each do |topic| 
  topic.update_status("closed", true, Discourse.system_user)
end

But, when I try to do the same to unlist topics by executing

topic.update_status("unlisted", true, Discourse.system_user)

I get this error:

ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "unlisted" of relation "topics" does not exist
LINE 1: UPDATE "topics" SET "unlisted" = 't' WHERE "topics"."id" = 1

From which I understand that there is no unlisted column for the topic object.

How can I unlist a topic using console?

I don’t have much idea :grin: and shouldn’t say anything, but what came to me was maybe try "listed" column and set to false? at least something to try until someone else sees :grin: (or I find something while peeking around)

Edit: I think I can see things like closed, visible, enabled, archived, disabled and autoclosed in /apps/models/topic_status_update.rb but again, I have no idea :slight_smile:

I tried the listed column. That one also does not exist. I am trying to get a peek into the table using phppgadmin now

I believe you are looking for “visible”.

But don’t let me stop you from learning about the database before you start running queries against it.

Please save a backup just in case you need it later.

a great idea :smiley:

visible it is.

topic.update_status("visible", false, Discourse.system_user)

Thanks guys