2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-30 02:43:44 -04:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class FixInvalidGravatarUploads < ::Jobs::Onceoff
|
2018-07-30 03:07:03 -04:00
|
|
|
def execute_onceoff(args)
|
2018-07-30 02:43:44 -04:00
|
|
|
Upload
|
|
|
|
.where(original_filename: "gravatar.png")
|
|
|
|
.find_each do |upload|
|
2018-10-15 19:29:16 -04:00
|
|
|
# note, this still feels pretty expensive for a once off
|
|
|
|
# we may need to re-evaluate this
|
2021-02-03 11:45:12 -05:00
|
|
|
extension =
|
2023-01-09 07:20:10 -05:00
|
|
|
begin
|
2021-02-03 11:45:12 -05:00
|
|
|
FastImage.type(Discourse.store.path_for(upload))
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2018-07-30 02:43:44 -04:00
|
|
|
current_extension = upload.extension
|
|
|
|
|
|
|
|
if extension.to_s.downcase != current_extension.to_s.downcase
|
2018-10-15 19:29:16 -04:00
|
|
|
upload&.user&.user_avatar&.update_columns(last_gravatar_download_attempt: nil)
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2018-07-30 02:43:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|