From 197af5de70221498f44c60ebfbffd4d4c803dead Mon Sep 17 00:00:00 2001 From: Patrick Figel Date: Sat, 29 Apr 2017 02:44:03 +0200 Subject: Set unknown attachment type when adding domain blocks (#2605) Follow-up to #2599. When a domain block with `reject_media` is added or `rake mastodon:media:remove_remote` is invoked, mastodon deletes the locally cached attachments and avatars but does not reflect that change in the database, causing the `file` fields to still have values. This change persists the deletion in the database and sets the attachment type to unknown. This also introduces a one-off rake task that sets all attachments without a local file to the "unknown" type. The upgrade notes for the next release should contain a post-upgrade step with `rake mastodon:media:set_unknown`. --- lib/tasks/mastodon.rake | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 2f2d10a48..985747936 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -53,8 +53,18 @@ namespace :mastodon do task remove_remote: :environment do MediaAttachment.where.not(remote_url: '').where('created_at < ?', 1.week.ago).find_each do |media| media.file.destroy + media.type = :unknown + media.save end end + + desc 'Set unknown attachment type for remote-only attachments' + task set_unknown: :environment do + Rails.logger.debug 'Setting unknown attachment type for remote-only attachments...' + # rubocop:disable Rails/SkipsModelValidations + MediaAttachment.where(file_file_name: nil).where.not(type: :unknown).in_batches.update_all(type: :unknown) + Rails.logger.debug 'Done!' + end end namespace :push do -- cgit