# Re-purposing a Discourse installation for a yearly event

**URL:** https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670
**Category:** Support
**Created:** [19.Октябрь.2015 14:12:43 UTC](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670 "2015-10-19T14:12:43Z")
**Posts on this page:** 1
**Showing post:** 17

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [19.Апрель.2017 14:22:20 UTC](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670/17 "2017-04-19T14:22:20Z")

</div>

Another year has passed, and we followed the same procedure. This time, we used actual Ruby scripts instead of my crazy API-based approach – maybe this is useful to someone else:

**Log out and deactivate (almost) all users:**

```ruby
protected_users = ["system", "codinghorror"] # do not process these users

# get all users that should be logged out
affected_users = User.all.select { |u| !(protected_users.include? u.username) }

affected_users.each { |u|
        u.admin = false
        u.moderator = false
        u.active = false
        u.save!
        u.user_auth_tokens.destroy_all
        u.logged_out
};

```

**Move all topics to an archive category and tag them appropriately:**

```ruby
protected_topics = [] # topics that will be ignored

# create a tag by running: Tag.create(name: "archive-2016")
year_tag = 19 # annotate all topics with this tag (represents the year)

categories = { # all categories that should be processed
    1 => { # move everything from category 1
        "target" => 2, # to category 2
        "tags" => [10, 11] # and add tags 10 and 11
    }
    # define additional entries as needed
}

categories.each { |id, data|
    c = Category.find(id)
    topics = c.topics.select { |t| t.id != c.topic_id } # get non-description topics

    topics.each { |t|
        if !(protected_topics.include? t.id)
        tags = t.tag_ids
        tags.push(year_tag)
        data["tags"].each { |tag| tags.push(tag) }
        t.tag_ids = tags
        t.category_id = data["target"]
        t.save!
        end
    }
}

# update all topic counts

Category.all.each { |c|
    c.topic_count = c.topics.length - 1 # -1 for about post
    c.save!
}

```

---

_[View the full topic](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670)._
