このコミットが含まれているのは:
@@ -22,6 +22,8 @@ class PostImportPreviewer
|
||||
tag_sources = row[:tag_sources]&.stringify_keys || initial_tag_sources(attributes, provenance)
|
||||
tag_sources['manual'] = attributes['tags'].to_s if provenance['tags'] == 'manual'
|
||||
url = row[:url].presence || values[@url_column].to_s.strip
|
||||
url_changed = row[:metadata_url].present? && row[:metadata_url] != url
|
||||
clear_automatic_values!(attributes, provenance, tag_sources) if url_changed
|
||||
provenance['url'] ||= row[:url].present? ? 'manual' : 'mapped'
|
||||
attributes['url'] = url
|
||||
fetch_warnings = Array(row[:fetch_warnings]).dup
|
||||
@@ -49,11 +51,12 @@ class PostImportPreviewer
|
||||
@existing == 'error' ? errors[:url] = ['既存投稿です.'] : validation_warnings << '既存投稿のためスキップします.'
|
||||
end
|
||||
validate_basic_data(attributes, errors)
|
||||
validate_preview_tags(merged_tags(tag_sources), errors, validation_warnings)
|
||||
validate_preview_tags(merged_tags(tag_sources, provenance['tags']), errors, validation_warnings)
|
||||
validate_parents(attributes['parent_post_ids'], errors)
|
||||
attributes.delete('url')
|
||||
attributes['tags'] = merged_tags(tag_sources)
|
||||
attributes['tags'] = merged_tags(tag_sources, provenance['tags'])
|
||||
{ source_row: row[:source_row], url: normal_url || url, attributes:, provenance:, tag_sources:,
|
||||
metadata_url: url,
|
||||
fetch_warnings:, validation_warnings:, warnings: fetch_warnings + validation_warnings, errors:,
|
||||
status: errors.present? ? 'error' : ((fetch_warnings + validation_warnings).present? ? 'warning' : 'ready'),
|
||||
existing: normal_url.present? && Post.exists?(url: normal_url) }
|
||||
@@ -97,10 +100,19 @@ class PostImportPreviewer
|
||||
'fixed' => origin == 'fixed' ? attributes['tags'].to_s : '', 'manual' => '' }
|
||||
end
|
||||
|
||||
def merged_tags sources
|
||||
def merged_tags sources, origin = nil
|
||||
return sources['manual'].to_s if origin == 'manual'
|
||||
|
||||
%w[automatic mapped fixed manual].flat_map { sources[_1].to_s.split }.uniq.join(' ')
|
||||
end
|
||||
|
||||
def clear_automatic_values! attributes, provenance, tag_sources
|
||||
%w[title thumbnail_base original_created_from original_created_before duration].each do |field|
|
||||
attributes[field] = '' if provenance[field] == 'automatic'
|
||||
end
|
||||
tag_sources['automatic'] = ''
|
||||
end
|
||||
|
||||
def fetch_metadata url
|
||||
return [{ }, ['URL が空です.']] if url.blank?
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする