mirror of
https://github.com/discourse/discourse.git
synced 2025-02-18 22:42:46 +08:00
FIX: Prevent cast error when import_id contains strings and numbers
Some importers insert numbers and strings as import_id into the same custom_fields table. This change prevents cast errors during imports.
This commit is contained in:
parent
0f7aaf5ab1
commit
29d27ec2ef
|
@ -198,12 +198,7 @@ class ImportScripts::Base
|
||||||
return false if import_ids.empty?
|
return false if import_ids.empty?
|
||||||
|
|
||||||
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
|
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
|
||||||
|
existing = existing.where('value in (?)', import_ids.map(&:to_s))
|
||||||
if Fixnum === import_ids.first
|
|
||||||
existing = existing.where('cast(value as int) in (?)', import_ids)
|
|
||||||
else
|
|
||||||
existing = existing.where('value in (?)', import_ids)
|
|
||||||
end
|
|
||||||
|
|
||||||
if existing.count == import_ids.length
|
if existing.count == import_ids.length
|
||||||
# puts "Skipping #{import_ids.length} already imported #{type}"
|
# puts "Skipping #{import_ids.length} already imported #{type}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user