mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 14:35:17 +08:00
FEATURE: Add rake task to disable secure media (#8669)
* Add a rake task to disable secure media. This sets all uploads to `secure: false`, changes the upload ACL to public, and rebakes all the posts using the uploads to make sure they point to the correct URLs. This is in a transaction for each upload with the upload being updated the last step, so if the task fails it can be resumed. * Also allow viewing media via the secure url if secure media is disabled, redirecting to the normal CDN url, because otherwise media links will be broken while we go and rebake all the posts + update ACLs
This commit is contained in:
@ -909,6 +909,43 @@ task "uploads:recover" => :environment do
|
||||
end
|
||||
end
|
||||
|
||||
task "uploads:disable_secure_media" => :environment do
|
||||
RailsMultisite::ConnectionManagement.each_connection do |db|
|
||||
unless Discourse.store.external?
|
||||
puts "This task only works for external storage."
|
||||
exit 1
|
||||
end
|
||||
|
||||
puts "Disabling secure media and resetting uploads to not secure in #{db}...", ""
|
||||
|
||||
SiteSetting.secure_media = false
|
||||
|
||||
secure_uploads = Upload.includes(:posts).where(secure: true)
|
||||
secure_upload_count = secure_uploads.count
|
||||
|
||||
i = 0
|
||||
secure_uploads.find_each(batch_size: 20).each do |upload|
|
||||
Upload.transaction do
|
||||
upload.secure = false
|
||||
|
||||
RakeHelpers.print_status_with_label("Updating ACL for upload #{upload.id}.......", i, secure_upload_count)
|
||||
Discourse.store.update_upload_ACL(upload)
|
||||
|
||||
RakeHelpers.print_status_with_label("Rebaking posts for upload #{upload.id}.......", i, secure_upload_count)
|
||||
upload.posts.each(&:rebake!)
|
||||
upload.save
|
||||
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
RakeHelpers.print_status_with_label("Rebaking and updating complete! ", i, secure_upload_count)
|
||||
puts ""
|
||||
end
|
||||
|
||||
puts "Secure media is now disabled!", ""
|
||||
end
|
||||
|
||||
##
|
||||
# Run this task whenever the secure_media or login_required
|
||||
# settings are changed for a Discourse instance to update
|
||||
|
Reference in New Issue
Block a user