Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge commit '436f1fbb648cf1e761e80481ae176afa095e6f54' into HEAD

  • Loading branch information...
commit ec3d386e92281fd82214b8f614e51d7bff867cd6 2 parents cb86897 + 436f1fb
Jenkins authored

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. +19 2 script/import.rb
21 script/import.rb
@@ -22,7 +22,11 @@ def build_params(hash, keys)
22 22 end
23 23
24 24 export["artefacts"].each do |a|
  25 + # Don't create contacts for artefacts that already exist
  26 + next if Artefact.where(slug: a["slug"]).any?
  27 +
25 28 next unless a["contact"]
  29 +
26 30 params = build_params(a["contact"], [
27 31 :contactotron_id, :email_address, :name, :opening_hours, :postal_address,
28 32 :website_url, :created_at, :updated_at
@@ -37,6 +41,12 @@ def build_params(hash, keys)
37 41 end
38 42
39 43 export["artefacts"].each do |a|
  44 + # Don't duplicate existing artefacts
  45 + if Artefact.where(slug: a["slug"]).any?
  46 + puts "exists: #{a["slug"]}"
  47 + next
  48 + end
  49 +
40 50 params = build_params(a, [
41 51 :section, :name, :slug, :kind, :owning_app, :active, :tags,
42 52 :need_id, :department, :fact_checkers, :relatedness_done,
@@ -48,12 +58,19 @@ def build_params(hash, keys)
48 58 end
49 59 artefact.save!
50 60 artefact_id_map[a["id"]] = artefact._id
  61 + puts "add: #{a["slug"]}; #{a["id"]} => #{artefact._id}"
51 62 end
52 63
53 64 export["artefacts"].each do |a|
  65 + # Skip anything we haven't created in this run
  66 + next unless artefact_id_map[a["id"]]
  67 +
54 68 artefact = Artefact.find(artefact_id_map[a["id"]])
55 69 a["related_items"].each do |r|
56   - related = Artefact.find(artefact_id_map[r["artefact"]["id"]])
57   - artefact.related_artefacts << related
  70 + related = Artefact.where(slug: artefact_id_map[r["artefact"]["slug"]]).first
  71 + if related
  72 + artefact.related_artefacts << related
  73 + puts "relate: #{artefact.slug} => #{related.slug}"
  74 + end
58 75 end
59 76 end

0 comments on commit ec3d386

Please sign in to comment.
Something went wrong with that request. Please try again.