Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit '436f1fbb648cf1e761e80481ae176afa095e6f54' into HEAD

  • Loading branch information...
commit ec3d386e92281fd82214b8f614e51d7bff867cd6 2 parents cb86897 + 436f1fb
Jenkins authored
Showing with 19 additions and 2 deletions.
  1. +19 −2 script/import.rb
View
21 script/import.rb
@@ -22,7 +22,11 @@ def build_params(hash, keys)
end
export["artefacts"].each do |a|
+ # Don't create contacts for artefacts that already exist
+ next if Artefact.where(slug: a["slug"]).any?
+
next unless a["contact"]
+
params = build_params(a["contact"], [
:contactotron_id, :email_address, :name, :opening_hours, :postal_address,
:website_url, :created_at, :updated_at
@@ -37,6 +41,12 @@ def build_params(hash, keys)
end
export["artefacts"].each do |a|
+ # Don't duplicate existing artefacts
+ if Artefact.where(slug: a["slug"]).any?
+ puts "exists: #{a["slug"]}"
+ next
+ end
+
params = build_params(a, [
:section, :name, :slug, :kind, :owning_app, :active, :tags,
:need_id, :department, :fact_checkers, :relatedness_done,
@@ -48,12 +58,19 @@ def build_params(hash, keys)
end
artefact.save!
artefact_id_map[a["id"]] = artefact._id
+ puts "add: #{a["slug"]}; #{a["id"]} => #{artefact._id}"
end
export["artefacts"].each do |a|
+ # Skip anything we haven't created in this run
+ next unless artefact_id_map[a["id"]]
+
artefact = Artefact.find(artefact_id_map[a["id"]])
a["related_items"].each do |r|
- related = Artefact.find(artefact_id_map[r["artefact"]["id"]])
- artefact.related_artefacts << related
+ related = Artefact.where(slug: artefact_id_map[r["artefact"]["slug"]]).first
+ if related
+ artefact.related_artefacts << related
+ puts "relate: #{artefact.slug} => #{related.slug}"
+ end
end
end

0 comments on commit ec3d386

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