Created
November 8, 2016 20:14
-
-
Save christopher-b/072369296c4a6ea78b6f73edad5d278b to your computer and use it in GitHub Desktop.
Revisions
-
christopher-b created this gist
Nov 8, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ Attachment.where(workflow_state:'zipped').find_each do |attachment| delete_attachment attachment };nil def delete_attachment(attachment) # Don't delete parent Attachments return if attachment.children.present? # Delete associated ContentExports content_export_for(attachment).try(:delete) # Delete the db row. Trigger callbacks, then remove the row attachment.destroy attachment.delete # Delete file on disk and containing folder, unless there is a parent Attachment unless attachment.root_attachment_id path = File.dirname(attachment.full_filename) FileUtils.rm_rf(path) if File.directory? path end true end def content_export_for(attachment) ContentExport.where(attachment_id:attachment.id).first end