# Change all posts by user to wiki

**URL:** https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298
**Category:** Support
**Tags:** wiki-posts
**Created:** [26 augustus 2016 om 20:05 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298 "2016-08-26T20:05:27Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [26 augustus 2016 om 20:05 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/1 "2016-08-26T20:05:27Z")

</div>

We just finished migrating from our knowledgebase from MediaWiki to Discourse. Yeah!

We had 4 users manually add all the posts (no migration scripts that I saw), and then used @techAPJ’s guide to convert all the posts to a single user.

> [@Change ownership of all posts by a specific user](https://meta.discourse.org/t/change-ownership-of-all-the-posts-by-a-specific-user/48921):
>
> bookmark This guide outlines the process to change the ownership of all posts by a specific user. This task requires console access. person_raising_hand Required user level: Server administrator with SSH access In Discourse, there may be situations where you need to change the ownership of all posts by a specific user. This guide provides the steps for achieving this on self-hosted Discourse instances. If you’re using Discourse hosting, please contact the support team at [team@discourse.o…](mailto:team@discourse.org)

Now that all the topics are owned by the same user, is there any way to change them all to wiki via a rake command?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [26 augustus 2016 om 21:25 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/2 "2016-08-26T21:25:59Z")

</div>

Not that I’m aware of, at the moment.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [26 augustus 2016 om 21:27 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/3 "2016-08-26T21:27:09Z")

</div>

> [@codinghorror](#):
>
> at the moment.

Alrighty then, I’ve changed this topic to #Contribute > Feature. Hope #wiki-posts can get some love in 1.7!

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [26 augustus 2016 om 21:34 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/4 "2016-08-26T21:34:15Z")

</div>

You can do it via the Rails console.

Something along the lines of

```plaintext
p = Post.find_each(user_id: X)
p.each_entry(wiki: true)

```

Then you have to figure out how to call .save on each entry… I’m struggling with that part, but it should be possible.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [26 augustus 2016 om 21:35 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/5 "2016-08-26T21:35:44Z")

</div>

My knowledge of the codebase is minuscule compared to yours - I’ll do some digging.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [26 augustus 2016 om 21:36 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/6 "2016-08-26T21:36:55Z")

</div>

I think this is mostly knowing Ruby/Rails at this point, p becomes an enumeration, so figuring out how to call a method on each item in the enumeration would be the solution. I just haven’t had a chance to google that yet.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [26 augustus 2016 om 23:16 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/7 "2016-08-26T23:16:30Z")

</div>

```plaintext
u = User.find_by_username('abc')
Post.where(user: u).each do |p|
  p.wiki = true
  p.save
end

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [26 augustus 2016 om 23:21 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/8 "2016-08-26T23:21:23Z")

</div>

Is this for stonehearth or another site you are self-hosting, if it is for stonehearth we can run the commands for you.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [26 augustus 2016 om 23:32 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/9 "2016-08-26T23:32:29Z")

</div>

Another site, thanks @sam. We’re self hosting a site at the university where I work for an internal help desk knowledge base. We’re just finishing manually importing from MediaWiki.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [27 augustus 2016 om 01:18 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/10 "2016-08-27T01:18:38Z")

</div>

Thanks @riking! Just tried that and it worked! Unfortunately, I overlooked the fact that `About this Category` pages were owned by the user, but it was easy enough to disable wiki via the UI for the 10 or so category topics.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [8 juni 2024 om 12:45 UTC](https://meta.discourse.org/t/change-all-posts-by-user-to-wiki/49298/11 "2024-06-08T12:45:19Z")

</div>

This topic was automatically closed after 2842 days. New replies are no longer allowed.
