redmine_custom_workflows
redmine_custom_workflows copied to clipboard
Delete specific attachments before save issue or comment
Hi, i try long time to find solution, how delete specific attachmets before save issues or comments.
Reason is simple. I use email as the one of the ways how create or comment issues. And emails usually have some logo (like corporation logo, etc.) and I have database full of logos. :-)
I think it will be quite easy to manage it, but I don't see light in the end of tunnel now. I know size of file on disk or size in px...
Someone to help? :-)
What do you think about digest? Can I use it as indentificator for specific attachments? It looks it can work...
I'm ruby beginner, but how said Jan Amos Komensky:"Learn, learn, learn." I try some script in console and this is my start point:
Attachment.where(digest: '<hexadecimal_code>').ids
It turn me back aray of ids of pictures/logos
May be I can start like this?
if subject.present? if self.has_attachment? ...
Any ideas? @picman
It has said Lenin.
Hi David,
Set the observable object to "Issue Attachments":
Use the below code in AFTER SAVE. You can modify the file size limit by changing it in this section: "< 200.to_i.kilobytes".
if @attachment.filesize < 200.to_i.kilobytes
if @attachment.container
@attachment.container.attachments.delete(@attachment)
else
@attachment.destroy
end
end
I hope its help!
@picman Sorry. I made mistake... You have right.
@AirTibu It works nice. Thank you!
if @attachment.filesize < 200.to_i.kilobytes if @attachment.container @attachment.container.attachments.delete(@attachment) else @attachment.destroy end end
Hi, I turn back to this problem. I applied your solution and on the first test looks good, but. If I send with company logo another attachment this script delete it also.
So I think about solution and here is my idea.
- find how many attachments are in container
- if there are more then one, check filesize one by one (for each?)
- if filesize = xyz kilobytes, then delete, else do nothing
The point of this is delete after save company logo which is always the same, ale slowly take some disc space...
What do you think about it?
Thanks.
David
I cannot imagine how a logo < 200kB, although saved many time, can noticeably consume the disk space. I'd enlarge the disk space rather than implement such a hack.
I cannot imagine how a logo < 200kB, although saved many time, can noticeably consume the disk space. I'd enlarge the disk space rather than implement such a hack. or user can run script on host machine periodicaly, that will finge full file duples and change each duplicate to symlink )
And as not to make many issuses, it will be nice to have more examples for users like me, that not good in Ruby or so ) Thanks!