Skip to main content
Topic: Delete all attachements in a specific topic (Read 3105 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Delete all attachements in a specific topic

I have a huge topic, about 180 pages which i just closed (it's a "Hello" topic), I would like to delete all the attachments in that topic, is there a quick way to do this without browsing all pages? Thank you
sorry for my bad english

Re: Delete all attachements in a specific topic

Reply #1

Admin>Attachments and Avatars>Browse Files

Select the ones to remove and click the Remove Selected icon at the bottom right of the page.

Re: Delete all attachements in a specific topic

Reply #2

Quote from: Lou – Admin>Attachments and Avatars>Browse Files
and here I have to browse 405 pages  :P
sorry for my bad english

Re: Delete all attachements in a specific topic

Reply #3

 :D   Hmm ... goood point!


You could play with the File Maintenance in the Attachements and Avatars but that may not be any easier. Another alternative is to remove them from the server with an FTP or with the server GUI ( cPanel ). But that may break links and if you did that you would need to do an Attachement Integrity Check ... I would think.

Re: Delete all attachements in a specific topic

Reply #4

You can do it by sql and remove the files afterwards from the attachement dir.

this sql script will give you the file names of the attachments in your attachment dir ( if you use the standard attachment file layout)
Replace XXXX with the id of the topic:

Quoteselect concat(id_attach,'_',file_hash,'.elk') from elkarte_attachments a where a.id_msg in (select id_msg from elkarte_messages where id_topic=XXXX);
to remove the entry's from the database:
Quotedelete  from elkarte_attachments a where a.id_msg in (select id_msg from elkarte_messages where id_topic=XXXX);

Make a full backup before you start !
[/size][/color]

Re: Delete all attachements in a specific topic

Reply #5

Yeah, there is no way to do that from the admin panel.
It may be worth (maybe even for 1.1) to add some more to the pruning options, now we have older-than and larger-than. It could be useful in a specific board, or even have a flexible interface allowing you to specify "rules" and so prune for example attachments larger than XX KiB and older than YY days and in a specific board.

 emanuele dreams :P
Bugs creator.
Features destroyer.
Template killer.

Re: Delete all attachements in a specific topic

Reply #6

Quote from: emanuele – It could be useful in a specific board
That will be perfect!

Thanks for answering Nifty, to be honest I am a little scared running that on my live site, I  prefer to test it first on localhost
sorry for my bad english

Re: Delete all attachements in a specific topic

Reply #7



:D

Re: Delete all attachements in a specific topic

Reply #8

I just tried on localhost, the first query show the attachments to delete, but the second one gave me an error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a where a.id_msg in (select id_msg from elkarte_messages where id_topic=2219)' at line 1
sorry for my bad english

Re: Delete all attachements in a specific topic

Reply #9

This will work:
Quotedelete from elkarte_attachments where id_msg in (select id_msg from elkarte_messages where id_topic=2219);

Re: Delete all attachements in a specific topic

Reply #10

Thank you, that worked for me  8)
It's enough to run the second query than Administration Center -> Attachments and Avatars -> File Maintenance -> Attachment integrity check -< then check the box "xx files do not have a corresponding entry in the database. (These will be deleted) "
sorry for my bad english

Re: Delete all attachements in a specific topic

Reply #11

Nice.