From fd5c5f6f136c0eb70a8506ff1c798f29281a85af Mon Sep 17 00:00:00 2001
From: David Valdez <david.valdez210@gmail.com>
Date: Fri, 30 Aug 2019 19:27:33 -0500
Subject: [PATCH] Add a migration to create some custom terms.

---
 composer.json                                 |  1 +
 .../default_data/default_terms.csv            |  4 +++
 .../custom/geo_upgrade/geo_upgrade.info.yml   |  2 ++
 .../upgrade_d7_node_story_author.yml          | 16 +++++++++-
 .../upgrade_d7_taxonomy_term_custom_terms.yml | 30 +++++++++++++++++++
 5 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 web/modules/custom/geo_upgrade/default_data/default_terms.csv
 create mode 100644 web/modules/custom/geo_upgrade/migrations/upgrade_d7_taxonomy_term_custom_terms.yml

diff --git a/composer.json b/composer.json
index e36e2e4..a4aad45 100644
--- a/composer.json
+++ b/composer.json
@@ -21,6 +21,7 @@
         "drupal/fixed_block_content": "^1.0",
         "drupal/link_attributes": "^1.9",
         "drupal/migrate_plus": "^4.2",
+        "drupal/migrate_source_csv": "3.1",
         "drupal/migrate_tools": "^4.1",
         "drupal/migrate_upgrade": "^3",
         "drush/drush": "^9.0",
diff --git a/web/modules/custom/geo_upgrade/default_data/default_terms.csv b/web/modules/custom/geo_upgrade/default_data/default_terms.csv
new file mode 100644
index 0000000..7e9ed4a
--- /dev/null
+++ b/web/modules/custom/geo_upgrade/default_data/default_terms.csv
@@ -0,0 +1,4 @@
+id,name,vocabulary
+1,Issue,collection_type
+2,Author,people_type
+3,Book,collection_type
diff --git a/web/modules/custom/geo_upgrade/geo_upgrade.info.yml b/web/modules/custom/geo_upgrade/geo_upgrade.info.yml
index e23b505..4e223aa 100644
--- a/web/modules/custom/geo_upgrade/geo_upgrade.info.yml
+++ b/web/modules/custom/geo_upgrade/geo_upgrade.info.yml
@@ -6,3 +6,5 @@ package: Migration
 dependencies:
   - migrate_drupal
   - migrate_plus
+  - migrate_source_csv
+  - migrate_tools
diff --git a/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml
index 4a0aad5..3b18232 100644
--- a/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml
+++ b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml
@@ -14,14 +14,28 @@ source:
   constants:
     user_id: 1
     author_status: 1
+    # The users that have an article in the old site will have the term
+    # "Author" on the new site, this term was migrated from a CSV and in that
+    # file the ID of that term is 2 (see default_terms.csv) so we are going to
+    # use that source ID to get the site term id.
+    author_type_source_id: 2
   plugin: geod7_author
 process:
   title: field_author_value
   uid: constants/user_id
   status: constants/author_status
+  field_people_type:
+    - plugin: migration_lookup
+      migration: upgrade_d7_taxonomy_term_custom_terms
+      source: constants/author_type_source_id
 destination:
   plugin: 'entity:node'
   default_bundle: people
 migration_dependencies:
-  required: {  }
+  required:
+    - upgrade_d7_taxonomy_term_custom_terms
+    - upgrade_d7_node_story
+    - upgrade_d7_node_page
+    - upgrade_d7_node_gleaning
+    - upgrade_d7_node_blog
   optional: {  }
diff --git a/web/modules/custom/geo_upgrade/migrations/upgrade_d7_taxonomy_term_custom_terms.yml b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_taxonomy_term_custom_terms.yml
new file mode 100644
index 0000000..f8c62bf
--- /dev/null
+++ b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_taxonomy_term_custom_terms.yml
@@ -0,0 +1,30 @@
+langcode: en
+status: true
+dependencies: {  }
+id: upgrade_d7_taxonomy_term_custom_terms
+migration_tags:
+  - 'Drupal 7'
+  - Content
+migration_group: migrate_drupal_7_geo
+label: 'Extra Taxonomy terms'
+source:
+  plugin: csv
+  path: modules/custom/geo_upgrade/default_data/default_terms.csv
+  ids: [id]
+process:
+  name: name
+  vid: vocabulary
+destination:
+  plugin: entity:taxonomy_term
+# Run first the other migration that create terms to avoid get a tid used by other term.
+migration_dependencies:
+  required:
+    - upgrade_d7_taxonomy_vocabulary
+    - upgrade_d7_taxonomy_term_vocabulary_1
+    - upgrade_d7_taxonomy_term_vocabulary_2
+    - upgrade_d7_taxonomy_term_vocabulary_3
+    - upgrade_d7_taxonomy_term_vocabulary_7
+    - upgrade_d7_taxonomy_term_vocabulary_10
+    - upgrade_d7_taxonomy_term_vocabulary_12
+    - upgrade_d7_taxonomy_term_vocabulary_13
+  optional: {  }