mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 18:22:00 +08:00
REFACTOR: create custom field even when missing post uploads not found
This commit is contained in:
parent
44e87372da
commit
a385f6c48a
@ -14,7 +14,7 @@ module Jobs
|
||||
.destroy_all
|
||||
|
||||
Post
|
||||
.joins("LEFT JOIN post_custom_fields cf ON posts.id = cf.post_id AND cf.name = 'missing_uploads'")
|
||||
.joins("LEFT JOIN post_custom_fields cf ON posts.id = cf.post_id AND cf.name = '#{MISSING_UPLOADS}'")
|
||||
.where("(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND cf.id IS NULL")
|
||||
.find_in_batches(batch_size: 100) do |posts|
|
||||
|
||||
@ -34,11 +34,9 @@ module Jobs
|
||||
end
|
||||
|
||||
if missing.present?
|
||||
post.preloaded_custom_fields = nil
|
||||
post.custom_fields[MISSING_UPLOADS] = missing
|
||||
post.save_custom_fields
|
||||
elsif post.custom_fields[MISSING_UPLOADS].present?
|
||||
PostCustomField.find_by(post_id: post.id, name: MISSING_UPLOADS).destroy!
|
||||
missing.each { |src| PostCustomField.create!(post_id: post.id, name: MISSING_UPLOADS, value: src) }
|
||||
else
|
||||
PostCustomField.create!(post_id: post.id, name: MISSING_UPLOADS, value: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user