このコミットが含まれているのは:
@@ -6,40 +6,29 @@ class PostImportRunner
|
||||
|
||||
def run
|
||||
normalised_rows = PostImportRowNormaliser.normalise!(@rows)
|
||||
previews = PostImportPreviewer.new.preview_rows(rows: normalised_rows,
|
||||
fetch_metadata: false)
|
||||
preview_map = previews.index_by { _1[:source_row] }
|
||||
|
||||
results = normalised_rows.map { |row| run_row(row) }
|
||||
{
|
||||
created: results.count { _1[:status] == 'created' },
|
||||
results = normalised_rows.map do |row|
|
||||
run_row(row, preview_map.fetch(row['source_row']))
|
||||
end
|
||||
|
||||
{ created: results.count { _1[:status] == 'created' },
|
||||
skipped: results.count { _1[:status] == 'skipped' },
|
||||
failed: results.count { _1[:status] == 'failed' },
|
||||
rows: results,
|
||||
}
|
||||
rows: results }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_row row
|
||||
def run_row row, preview
|
||||
attributes = row.fetch('attributes', { }).transform_keys { _1.to_s.underscore }
|
||||
preview = PostImportPreviewer.new.preview_rows(
|
||||
rows: [{
|
||||
source_row: row['source_row'],
|
||||
url: row['url'],
|
||||
attributes:,
|
||||
provenance: row['provenance'],
|
||||
tag_sources: row['tag_sources'],
|
||||
}],
|
||||
fetch_metadata: false).first
|
||||
if Array(preview.dig(:field_warnings, 'url')).include?(PostImportPreviewer::EXISTING_SKIP_WARNING)
|
||||
return row.slice('source_row').merge(status: 'skipped')
|
||||
end
|
||||
return row.slice('source_row').merge(status: 'skipped') if preview[:skip_reason] == 'existing'
|
||||
|
||||
if preview[:validation_errors].present?
|
||||
return {
|
||||
source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: preview[:validation_errors],
|
||||
}
|
||||
end
|
||||
return { source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: preview[:validation_errors] } if preview[:validation_errors].present?
|
||||
|
||||
attributes['tags'] = preview[:attributes]['tags']
|
||||
attributes['url'] = row['url']
|
||||
@@ -48,15 +37,22 @@ class PostImportRunner
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
{ source_row: row['source_row'], status: 'failed', errors: e.record.errors.to_hash }
|
||||
rescue Tag::NicoTagNormalisationError
|
||||
{ source_row: row['source_row'], status: 'failed', errors: { tags: ['ニコニコ・タグは直接指定できません.'] } }
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { tags: ['ニコニコ・タグは直接指定できません.'] } }
|
||||
rescue Tag::DeprecatedTagNormalisationError
|
||||
{ source_row: row['source_row'], status: 'failed', errors: { tags: ['廃止済みタグは付与できません.'] } }
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { tags: ['廃止済みタグは付与できません.'] } }
|
||||
rescue ArgumentError, PostCreator::VideoMsParseError
|
||||
{ source_row: row['source_row'], status: 'failed', errors: { base: ['入力値が不正です.'] } }
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { base: ['入力値が不正です.'] } }
|
||||
rescue StandardError => e
|
||||
Rails.logger.error(
|
||||
"post_import_runner_failure #{ { error: e.class.name, message: e.message }.to_json }",
|
||||
)
|
||||
{ source_row: row['source_row'], status: 'failed', errors: { base: ['登録中にエラーが発生しました.'] } }
|
||||
Rails.logger.error("post_import_runner_failure #{ { error: e.class.name,
|
||||
message: e.message }.to_json }")
|
||||
{ source_row: row['source_row'],
|
||||
status: 'failed',
|
||||
errors: { base: ['登録中にエラーが発生しました.'] } }
|
||||
end
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする