Created
November 8, 2016 20:14
-
-
Save christopher-b/072369296c4a6ea78b6f73edad5d278b to your computer and use it in GitHub Desktop.
Canvas - Delete export files
This file contains 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 characters
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 |
Hi @mayng0702, for more information about the attachment class in Canvas LMS, check the main repo, specifically the Attachment model.
The concepts that are approached by this file (deleting unused files in Canvas LMS CV from disk) are elaborated in a module that can be found here.
Thanks for your reply. I will study it further.
在 2022年10月4日週二 01:44,christopher-b ***@***.***> 寫道:
… ***@***.**** commented on this gist.
------------------------------
Hi @mayng0702 <https://github.com/mayng0702>, for more information about
the attachment class in Canvas LMS, check the main repo
<https://github.com/instructure/canvas-lms>, specifically the Attachment
model
<https://github.com/instructure/canvas-lms/blob/master/app/models/attachment.rb>
.
The concepts that are approached by this file (deleting unused files in
Canvas LMS CV from disk) are elaborated in a module that can be found here
<https://github.com/christopher-b/canvas-file-zapper>.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/072369296c4a6ea78b6f73edad5d278b#gistcomment-4323203>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AONMLHCLDMNUX3LLOD3C52LWBMLQZANCNFSM6AAAAAAQ3NMEYU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We are doing open source projects about canvas, may I have more information about the main class of attachment?