# Bulk un-deletion

**URL:** https://meta.discourse.org/t/bulk-un-deletion/277861
**Category:** Feature
**Tags:** bulk-actions
**Created:** [September 5, 2023, 1:43pm UTC](https://meta.discourse.org/t/bulk-un-deletion/277861 "2023-09-05T13:43:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rahim123](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rahim123](https://meta.discourse.org/u/rahim123)
#### Post date: [September 5, 2023, 1:43pm UTC](https://meta.discourse.org/t/bulk-un-deletion/277861/1 "2023-09-05T13:43:31Z")

</div>

Continuing the discussion from [Best way to temporarily remove public access to a user's topics?](https://meta.discourse.org/t/best-way-to-temporarily-remove-public-access-to-a-users-topics/277242):

Would it be possible to enable a bulk un-delete selector in the `/u/username/deleted-posts` list? From what I can tell it would require a technically [very challenging and potentially dangerous](https://meta.discourse.org/t/best-way-to-temporarily-remove-public-access-to-a-users-topics/277242/23) SQL/rails script to undelete them programatically.

For this feature to be most useful it would be best to differentiate between deleted topics and deleted replies. Maybe the existing `/u/username/deleted-posts` URL could be maintained, and then add to that `/u/username/deleted-posts/topics` and `/u/username/deleted-posts/replies` .

---

<div class="post-metadata">

### Author: ![rahim123](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rahim123](https://meta.discourse.org/u/rahim123)
#### Post date: [September 8, 2023, 2:37am UTC](https://meta.discourse.org/t/bulk-un-deletion/277861/2 "2023-09-08T02:37:39Z")

</div>

> [@Setting option to make unlisted topics inaccesible to public](https://meta.discourse.org/t/setting-option-to-make-unlisted-topics-inaccesible-to-public/277862/9):
>
> You’re not going to get a feature in time.
> 
> It shouldn’t be that hard to bulk move them all to a private category as a edit in rails and later revert those edits.

The topics are already deleted, and I don’t have an estimate for when the user might request restoration of the topics, so I guess I can wait for bulk un-deletion to be implemented. I don’t think I’m the only one that would find it useful, there are quite a few posts here requesting help for doing so.

This also looks like a potentially easier and safer way to programmatically un-delete, assuming I can figure out how to generate the list of the user’s deleted topic IDs:

> [@Bulk undelete topics](https://meta.discourse.org/t/bulk-undelete-topics-help/196533/3):
>
> There is no “undelete” bulk action that I know of, so you’ll need to write a script for this and use the [Discourse API](https://meta.discourse.org/t/discourse-api-documentation/22706). Everything you do in Discourse you can do through the API, check this topic to learn how [Reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576) As instructed in the topic, if you check your network tab (in your browser’s dev tools), you’ll see that whenever the “reverse delete” button is clicked, there is a PUT call made to /posts/\<post-id\>/recover So, if y…

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 8, 2023, 2:45pm UTC](https://meta.discourse.org/t/bulk-un-deletion/277861/3 "2023-09-08T14:45:23Z")

</div>

This will find deleted topics created by user\_id 1.

```plaintext
dts=Topic.with_deleted.where(user_id: 1).where("deleted_at is not null");
dts.pluck(:deleted_at, :id)

```

```plaintext
dps=Post.with_deleted.where(user_id: 1).where("deleted_at is not null");
dbs.pluck(:deleted_at, :id)

```

And it looks like you can un-delete posts with something like

```plaintext
dp=dps.first
dp.deleted_at=nil
dp.deleted_by=nil
dp.save

```

And you’d do something similar for topics.

If it comes time to un-delete the stuff, the above should be enough for someone who knows a tiny bit about rails to be able to un-delete them all.

FWIW, if you had moved them to a hidden category, it would have been perhaps somewhat easier to bulk-revert-to-last-revision them all. But when neither of those things is possible for you at all, I think that’s a distinction without a difference.

Lastly, I’ll apologize for once again, treating a feature request as #Support . I think I do it because I have no power to make features, but I can solve problems.

---

<div class="post-metadata">

### Author: ![rahim123](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rahim123](https://meta.discourse.org/u/rahim123)
#### Post date: [September 8, 2023, 3:19pm UTC](https://meta.discourse.org/t/bulk-un-deletion/277861/4 "2023-09-08T15:19:29Z")

</div>

Not a problem at all Jay, really appreciate it. Of course I would prefer if a GUI method could be implemented in Discourse, but if not I really appreciate you walking me through that.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [September 8, 2023, 3:38pm UTC](https://meta.discourse.org/t/bulk-un-deletion/277861/5 "2023-09-08T15:38:25Z")

</div>

> [@rahim123](#):
>
> Of course I would prefer if a GUI method could be implemented in Discourse

It’s certainly an edge case, but we try to keep track when a feature is asked multiple times (especially from customers) to have a better idea of when to move forward 🙂
