このコミットが含まれているのは:
@@ -27,13 +27,24 @@ class PostImportRunner
|
||||
return { source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: preview[:validation_errors] } if preview[:validation_errors].present?
|
||||
return row.slice('source_row').merge(status: 'skipped') if preview[:skip_reason] == 'existing'
|
||||
if preview[:skip_reason] == 'existing'
|
||||
return { source_row: row['source_row'],
|
||||
status: 'skipped',
|
||||
existing_post_id: preview[:existing_post_id] }
|
||||
end
|
||||
|
||||
attributes['tags'] = preview[:attributes]['tags']
|
||||
attributes['url'] = row['url']
|
||||
post = PostCreator.new(actor: @actor, attributes:).create!
|
||||
{ source_row: row['source_row'], status: 'created', post: PostRepr.base(post) }
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
existing_post = existing_post_for_race(row, e.record)
|
||||
if existing_post
|
||||
return { source_row: row['source_row'],
|
||||
status: 'skipped',
|
||||
existing_post_id: existing_post.id }
|
||||
end
|
||||
|
||||
{ source_row: row['source_row'], status: 'failed', errors: e.record.errors.to_hash }
|
||||
rescue Tag::NicoTagNormalisationError
|
||||
{ source_row: row['source_row'],
|
||||
@@ -54,4 +65,13 @@ class PostImportRunner
|
||||
status: 'failed',
|
||||
errors: { base: ['登録中にエラーが発生しました.'] } }
|
||||
end
|
||||
|
||||
def existing_post_for_race row, record
|
||||
return nil unless record.errors.of_kind?(:url, :taken)
|
||||
|
||||
normal_url = PostUrlNormaliser.normalise(row['url'])
|
||||
return nil if normal_url.blank?
|
||||
|
||||
Post.find_by(url: normal_url)
|
||||
end
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする