Unlist a topic using rails console


(Shahidh K Muhammed) #1

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?


#2

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:


(Shahidh K Muhammed) #3

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


(Mittineague) #4

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.


#5

a great idea :smiley:


(Shahidh K Muhammed) #6

visible it is.

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

Thanks guys


(RĂ©gis Hanol) #7