]> cat aescling's git repositories - mastodon.git/commitdiff
Set unknown attachment type when adding domain blocks (#2605)
authorPatrick Figel <patrick@figel.email>
Sat, 29 Apr 2017 00:44:03 +0000 (02:44 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 29 Apr 2017 00:44:03 +0000 (02:44 +0200)
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`.

app/services/block_domain_service.rb
lib/tasks/mastodon.rake

index 5d13cfc0e67d77a0a682ea3611c139f0b96f1b24..d15a1e83c6e693c20ffc1ebec0252ae1f714ae08 100644 (file)
@@ -39,12 +39,15 @@ class BlockDomainService < BaseService
     blocked_domain_accounts.find_each do |account|
       account.avatar.destroy
       account.header.destroy
+      account.save
     end
   end
 
   def clear_account_attachments
     media_from_blocked_domain.find_each do |attachment|
       attachment.file.destroy
+      attachment.type = :unknown
+      attachment.save
     end
   end
 
index 2f2d10a48430ff1ec55956c7c806f363a71607c4..985747936ac3c5a2cb80f85dbe75cfb7e83beb84 100644 (file)
@@ -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