Delete deleted-posts permanently in bulk?

I think the attachments will be cleaned up by one of the daily jobs, as long as they’re not part of the latest version of the post. So changing the deleted post to ‘(deleted by admin)’ or something would make its attachment part of the edit history and would then orphan it (thus scooping it up in the ‘clear orphan’ clean-up).

I am only theorising though, so this may be wrong. :slightly_smiling_face:

Source:

1 Like

if you log into postgres, you can delete it out of the DB.

I am looking at the current rake destoy tasks and tying to understand how it works. Maybe the ppl that created the current destroy task can implement something for us to del deleted posts

3 Likes

Yes, that is correct.
In order to get rid of an attachment, you need to remove the contents of the post and then delete the post.

2 Likes

if you got command aur anything helpful and quick then please share with me!

1 Like

Thanks Richard and @JammyDodger!

My only issue is that I have 20,000 posts to do this to. Know any shortcuts?

2 Likes

I’m afraid I’m at the start of my Discourse journey, so lack the necessary expertise for that. :slightly_smiling_face:

Is it possible to amend this to target deleted posts rather than a user’s posts to achieve a similar thing?

1 Like

Post.with_deleted.where('deleted_at is not null').update_all(raw: 'This post has been deleted', cooked: 'This post has been deleted')

6 Likes

Sorry if that’s a stupid question …
Why with Discourse it is not possible to easily delete messages from the database?

2 Likes

Discourse uses a mechanism called a ‘soft delete’ which makes it easy to correct mistakes. It also allows to make a difference between ‘deleted for other users’ and ‘deleted for admins’.

It also maintains database integrity. What if a deleted post was quoted (before it was deleted) ? Then the quoting post has a reference to a post that does not exist any more. That could lead to all kinds of errors.

2 Likes

Thanks now i understand… the only problem is if there are a lot of deleted messages.

1 Like

It’s been discussed and requested before, more than once e.g.

While I understand that soft-delete maybe useful, after some period (e.g. 1 week or month) it would be nice if deleted things were actually removed to save space and also ensure legal compliance e.g because some thing illegal was posted, or personal details need removing for GDPR compliance.

Having to log on and run a rake task to replace the message with ‘this has been deleted’ is a bit naff.

3 Likes

Opss… sorry, coming from phpBB I thought it could be done.

1 Like

its now implemented

6 Likes

Best,

But how we do that ???

2 Likes

I’ve been playing with that this morning, and I can’t figure it out. :slightly_smiling_face: Any pointers?

1 Like

well, the setting needs to be set in admin > settings > security (currently hidden for some reason) and then each admin would need it to be granted like moderator.

Once Granted, it would appear in the post admin menu

3 Likes

Ah, that might be my stumbling block. I was looking for can_permanently_delete in the admin settings and couldn’t see it.

1 Like

The site setting is hidden because we do not encourage its use. That was developed for the cases when some sensitive information was posted and it must be scrubbed from the database completely. One more thing, that operation is not a bulk operation anyway.

Since it is a hidden site setting, the only way to enable it is from the console.

5 Likes

This is almost exactly what I need! Thank you.

How would I do the syntax so that it only covers all posts deleted before xxxx date?

1 Like

That would be Post.with_deleted.where("deleted_at < 'YYYY-mm-dd'").update_all(...)

7 Likes