From 38055e92ac2b786cbb1649ed505e6ff3a999a9ba Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 16:39:59 -0400 Subject: [PATCH 1/9] add comment csv & migration config --- .../custom_migrate/artifacts/comments.csv | 6 ++ ...te_plus.migration.migrate_csv_comments.yml | 79 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 web/modules/custom/custom_migrate/artifacts/comments.csv create mode 100644 web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml diff --git a/web/modules/custom/custom_migrate/artifacts/comments.csv b/web/modules/custom/custom_migrate/artifacts/comments.csv new file mode 100644 index 0000000..e0af06d --- /dev/null +++ b/web/modules/custom/custom_migrate/artifacts/comments.csv @@ -0,0 +1,6 @@ +cid,pid,cid_parent,subject,body,name,mail,aid +1,2,,"foo","foo",,,1 +2,2,1,"bar","bar",,,1 +3,2,2,"baz","baz",,,1 +4,3,,"qux","qux",,,1 +5,3,4,"buzz","buzz",,,1 diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml new file mode 100644 index 0000000..facfa41 --- /dev/null +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -0,0 +1,79 @@ +langcode: en +status: true +dependencies: + enforced: + # List here the name of the module that provided this migration if you want + # this config to be removed when that module is uninstalled. + module: + - custom_migrate +migration_dependencies: + required: + - migrate_csv +# The source data is in CSV files, so we use the 'csv' source plugin. +id: migrate_csv_comments +label: CSV file migration of comments +migration_tags: + - CSV +source: + plugin: csv + # Full path to the file. + path: /artifacts/comments.csv + # The number of rows at the beginning which are not data. + header_row_count: 1 + # These are the field names from the source file representing the key + # uniquely identifying each game - they will be stored in the migration + # map table as columns sourceid1, sourceid2, and sourceid3. + keys: + - id + # Here we identify the columns of interest in the source file. Each numeric + # key is the 0-based index of the column. For each column, the key below + # (e.g., "start_date") is the field name assigned to the data on import, to + # be used in field mappings below. The value is a user-friendly string for + # display by the migration UI. + column_names: + # So, here we're saying that the first field (index 0) on each line will + # be stored in the start_date field in the Row object during migration, and + # that name can be used to map the value below. "Date of game" will appear + # in the UI to describe this field. + 0: + id: Identifier + 1: + first_name: First Name + 2: + last_name: Last Name + 3: + email: Email Address + 4: + country: Country + 5: + ip_address: IP Address + 6: + date_of_birth: Date of Birth +process: + pid: + plugin: migration + migration: migrate_csv_comments + source: cid_parent + entity_id: + plugin: migration + migration: migrate_csv + entity_type: + plugin: default_value + default_value: node + field_name: + plugin: default_value + default_value: field_comments + comment_type: + plugin: default_value + default_value: node_comments + subject: subject + uid: + plugin: default_value + default_value: 1 + name: name + mail: mail + status: + plugin: default_value + default_value: 1 + comment_body/value: body + From 0d67a42451cff8b83731a034961566c45ac56d06 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 16:41:12 -0400 Subject: [PATCH 2/9] fixup --- .../install/migrate_plus.migration.migrate_csv_comments.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index facfa41..5840104 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -75,5 +75,5 @@ process: status: plugin: default_value default_value: 1 - comment_body/value: body + "comment_body/value": body From 9c493ccc43141491bb021e67877875d383a2d62a Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 16:42:52 -0400 Subject: [PATCH 3/9] ignore vim .swp --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 647c524..edccdee 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ web/sites/default/settings.local.php .vagrant Vagrantfile.local local.config.yml + +# Ignore vim +*.swp From c0b5f480540dc959c905d156fb7b2d1e83eeafe4 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 16:49:09 -0400 Subject: [PATCH 4/9] fix column names --- ...ate_plus.migration.migrate_csv_comments.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index 5840104..e2adc84 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -24,7 +24,7 @@ source: # uniquely identifying each game - they will be stored in the migration # map table as columns sourceid1, sourceid2, and sourceid3. keys: - - id + - cid # Here we identify the columns of interest in the source file. Each numeric # key is the 0-based index of the column. For each column, the key below # (e.g., "start_date") is the field name assigned to the data on import, to @@ -36,19 +36,21 @@ source: # that name can be used to map the value below. "Date of game" will appear # in the UI to describe this field. 0: - id: Identifier + cid: Identifier 1: - first_name: First Name + pid: Person ID 2: - last_name: Last Name + cid_parent: Parent Comment ID 3: - email: Email Address + subject: Subject 4: - country: Country + body: Body 5: - ip_address: IP Address + name: Name 6: - date_of_birth: Date of Birth + mail: Mail + 7: + aid: Author ID process: pid: plugin: migration From dbb46063f14de490b41fbc2e8c99a0e10f027c49 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 16:53:30 -0400 Subject: [PATCH 5/9] destination --- .../migrate_plus.migration.migrate_csv_comments.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index e2adc84..557b6fe 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -77,5 +77,8 @@ process: status: plugin: default_value default_value: 1 - "comment_body/value": body - + 'comment_body/value': body +destination: + # Here we're saying that each row of data (line from the CSV file) will be + # used to create a comment entity. + plugin: entity:comment From 912e7f37e3f4415ff27ca120a4b921ff5bc2c1e7 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 17:36:33 -0400 Subject: [PATCH 6/9] entity_id source --- .../install/migrate_plus.migration.migrate_csv_comments.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index 557b6fe..b181a6e 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -59,6 +59,7 @@ process: entity_id: plugin: migration migration: migrate_csv + source: pid entity_type: plugin: default_value default_value: node From c94852089d1e6174ae067f53efb836dd9cd6ac35 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 17:49:38 -0400 Subject: [PATCH 7/9] rename fields for clarity --- web/modules/custom/custom_migrate/artifacts/comments.csv | 2 +- .../migrate_plus.migration.migrate_csv_comments.yml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/modules/custom/custom_migrate/artifacts/comments.csv b/web/modules/custom/custom_migrate/artifacts/comments.csv index e0af06d..2c07db0 100644 --- a/web/modules/custom/custom_migrate/artifacts/comments.csv +++ b/web/modules/custom/custom_migrate/artifacts/comments.csv @@ -1,4 +1,4 @@ -cid,pid,cid_parent,subject,body,name,mail,aid +id,person_id,cid_parent,subject,body,name,mail,aid 1,2,,"foo","foo",,,1 2,2,1,"bar","bar",,,1 3,2,2,"baz","baz",,,1 diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index b181a6e..d32d014 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -24,7 +24,7 @@ source: # uniquely identifying each game - they will be stored in the migration # map table as columns sourceid1, sourceid2, and sourceid3. keys: - - cid + - id # Here we identify the columns of interest in the source file. Each numeric # key is the 0-based index of the column. For each column, the key below # (e.g., "start_date") is the field name assigned to the data on import, to @@ -36,9 +36,9 @@ source: # that name can be used to map the value below. "Date of game" will appear # in the UI to describe this field. 0: - cid: Identifier + id: Comment ID 1: - pid: Person ID + person_id: Person ID 2: cid_parent: Parent Comment ID 3: @@ -59,7 +59,7 @@ process: entity_id: plugin: migration migration: migrate_csv - source: pid + source: person_id entity_type: plugin: default_value default_value: node From d9100feb9d8d7614eafae026dfdff3a59ddc6a52 Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 18:18:22 -0400 Subject: [PATCH 8/9] set field_name to 'comment' and remove comment_type --- .../install/migrate_plus.migration.migrate_csv_comments.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml index d32d014..f4dd48b 100644 --- a/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml +++ b/web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml @@ -65,10 +65,7 @@ process: default_value: node field_name: plugin: default_value - default_value: field_comments - comment_type: - plugin: default_value - default_value: node_comments + default_value: comment subject: subject uid: plugin: default_value From 814406a8824695b1aa558dbafa937a37e73ef50c Mon Sep 17 00:00:00 2001 From: Mike Chelen Date: Thu, 16 Mar 2017 21:50:09 -0400 Subject: [PATCH 9/9] update config files and module hooks --- ...ntity_form_display.node.people.default.yml | 7 ++++ ...ntity_view_display.node.people.default.yml | 11 +++++++ .../sync/field.field.node.people.comment.yml | 33 +++++++++++++++++++ ...te_plus.migration.migrate_csv_comments.yml | 1 + .../custom_migrate/custom_migrate.module | 1 + 5 files changed, 53 insertions(+) create mode 100644 config/sync/field.field.node.people.comment.yml create mode 120000 config/sync/migrate_plus.migration.migrate_csv_comments.yml diff --git a/config/sync/core.entity_form_display.node.people.default.yml b/config/sync/core.entity_form_display.node.people.default.yml index 64f5578..5f54cd8 100644 --- a/config/sync/core.entity_form_display.node.people.default.yml +++ b/config/sync/core.entity_form_display.node.people.default.yml @@ -3,6 +3,7 @@ langcode: en status: true dependencies: config: + - field.field.node.people.comment - field.field.node.people.field_country - field.field.node.people.field_dob - field.field.node.people.field_email @@ -11,6 +12,7 @@ dependencies: - field.field.node.people.field_last_name - node.type.people module: + - comment - datetime - path id: node.people.default @@ -18,6 +20,11 @@ targetEntityType: node bundle: people mode: default content: + comment: + weight: 37 + settings: { } + third_party_settings: { } + type: comment_default created: type: datetime_timestamp weight: 10 diff --git a/config/sync/core.entity_view_display.node.people.default.yml b/config/sync/core.entity_view_display.node.people.default.yml index 1b2bab6..d08fe68 100644 --- a/config/sync/core.entity_view_display.node.people.default.yml +++ b/config/sync/core.entity_view_display.node.people.default.yml @@ -3,6 +3,8 @@ langcode: en status: true dependencies: config: + - core.entity_view_display.comment.comment.default + - field.field.node.people.comment - field.field.node.people.field_country - field.field.node.people.field_dob - field.field.node.people.field_email @@ -11,6 +13,7 @@ dependencies: - field.field.node.people.field_last_name - node.type.people module: + - comment - datetime - user id: node.people.default @@ -18,6 +21,14 @@ targetEntityType: node bundle: people mode: default content: + comment: + weight: 107 + label: above + settings: + view_mode: default + pager_id: 0 + third_party_settings: { } + type: comment_default field_country: weight: 104 label: above diff --git a/config/sync/field.field.node.people.comment.yml b/config/sync/field.field.node.people.comment.yml new file mode 100644 index 0000000..f01b876 --- /dev/null +++ b/config/sync/field.field.node.people.comment.yml @@ -0,0 +1,33 @@ +uuid: 387af81b-94ba-4f20-a7ca-4053b6e7746a +langcode: en +status: true +dependencies: + config: + - field.storage.node.comment + - node.type.people + module: + - comment +id: node.people.comment +field_name: comment +entity_type: node +bundle: people +label: Comments +description: '' +required: false +translatable: true +default_value: + - + status: 2 + cid: 0 + last_comment_timestamp: 0 + last_comment_name: null + last_comment_uid: 0 + comment_count: 0 +default_value_callback: '' +settings: + default_mode: 1 + per_page: 50 + anonymous: 0 + form_location: true + preview: 1 +field_type: comment diff --git a/config/sync/migrate_plus.migration.migrate_csv_comments.yml b/config/sync/migrate_plus.migration.migrate_csv_comments.yml new file mode 120000 index 0000000..a1e57e5 --- /dev/null +++ b/config/sync/migrate_plus.migration.migrate_csv_comments.yml @@ -0,0 +1 @@ +../../web/modules/custom/custom_migrate/config/install/migrate_plus.migration.migrate_csv_comments.yml \ No newline at end of file diff --git a/web/modules/custom/custom_migrate/custom_migrate.module b/web/modules/custom/custom_migrate/custom_migrate.module index 06498f3..8fef870 100644 --- a/web/modules/custom/custom_migrate/custom_migrate.module +++ b/web/modules/custom/custom_migrate/custom_migrate.module @@ -28,4 +28,5 @@ function custom_migrate_help($route_name, RouteMatchInterface $route_match) { */ function custom_migrate_migration_plugins_alter(&$definitions) { $definitions['migrate_csv']['source']['path'] = drupal_get_path('module', 'custom_migrate') . $definitions['migrate_csv']['source']['path']; + $definitions['migrate_csv_comments']['source']['path'] = drupal_get_path('module', 'custom_migrate') . $definitions['migrate_csv_comments']['source']['path']; }