# Remove images from PMs that have been inactive for \>1 year

**URL:** https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077
**Category:** Feature
**Created:** [January 2, 2018, 2:10am UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077 "2018-01-02T02:10:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [January 2, 2018, 2:10am UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077/1 "2018-01-02T02:10:01Z")

</div>

What would be the correct way to remove all images from all PM topics with no activity for e.g. 1+ years. I’d like to do so as a means to reduce storage occupied by uploads.

By making so in a “correct way” I mean in such a way that the images will be then automatically removed / cleaned up as not used ones (orphan ones).

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 2, 2018, 10:19am UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077/2 "2018-01-02T10:19:59Z")

</div>

I would write a plugin with a background job that runs daily and replace all images with some text (eg “`[image removed after 1 year]`”) in the `raw` version of posts in PM older than 365 days. Discourse will do the rest.

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [January 2, 2018, 10:28am UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077/3 "2018-01-02T10:28:46Z")

</div>

Should be achievable by a sql query? I could run it manually once a year 🙂 What field should I update to trigger re-cooking a message in which the “raw” content gets changed

---

<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: [May 14, 2018, 10:29pm UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077/4 "2018-05-14T22:29:52Z")

</div>

I think your solution might involve this: [Replace a string in all posts](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 30, 2020, 1:18am UTC](https://meta.discourse.org/t/remove-images-from-pms-that-have-been-inactive-for-1-year/77077/5 "2020-10-30T01:18:42Z")

</div>


