Auto-close old topics from a migrated forum


(Rodrigo Farcas) #1

We migrated to Discourse from another forum software, and I want to close a batch of old topics at once.

I’ve tried using the forum setting for auto-close:

But this seems not to be affecting migrated old topics, as they are still open. How can I achieve this? (want to close all topics which are older than 720 hours=30 days)

Thanks


(Régis Hanol) #2

You’ll need to do that via the rails console.


(Rodrigo Farcas) #3

Can you elaborate more on how?


(Kane York) #4

Click the “menu” icon next to the Topic column header, select the topics to close, click the wrench in the upper right, and select “Close Topics” in the Bulk Actions menu.

@zogstrip console not required!


(Jeff Atwood) #5

That is true, but will be painful with more than a few screens worth of topics…


(Sander Jensen) #6

I’m in the same situation, but have around 24000 topics to close manually.
We moved to Discourse software 3 weeks ago.

Manually I have now closed old topics from the years 2003 and 2004.

I still have to manually close old topics from the years
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 and 2015.

Quite a big job ahead of me… !!!

Is there an easier way to do this job?


(Sander Jensen) #7

Maybe the number of old topics I have to close manually is much bigger than I have thought.

The exact number for January 2005 was 820.


(Régis Hanol) #8

I would use the rails console to close all the old topics.


(Sander Jensen) #9

Thank You for your reply, Zogstrip.

I do not know the console You are referring to.

I have been clicking the radio buttons to select the unclosed topics and then using the close batch function in the “wrench-tool”.

But my experience with this function is, that I regularly gets an error-message if choosing more than 40 to 50 topics to close at one time.

So its very elaborate to close thousands of topics, 30 at a time.


(Régis Hanol) #10

I would SSH into the server and then

cd /var/discourse
./launcher enter app
rails c
Topic.where(closed: false).where("created_at < '2015-01-01'").find_each do |topic| 
  topic.update_status("closed", true, Discourse.system_user)
end

And you should have all the topics created before January 1st 2015 closed :wink:


Topics older than auto-close age should auto-close
Mass close topics?
CommonMark testing started here!
(Sander Jensen) #11

Thank You so much, Zogstrip!
:+1:

I’ve shown Your tip to our serveradministrator, and he’ll take action.

You have helped us a lot.
Thank You!


(Sander Jensen) #12

Once more: Thank You, Zogstrip!

Our server worked hard for one day :hourglass_flowing_sand:and one night :sparkles:

Your tip deserves a tip :gift:

It saved me and my fingers from thousands and thousands and thousands of clicks.


(Régis Hanol) #13