2

I need to migrate a CSV file of 3000 Taxonomy terms with depth of 5 levels deep. This is a small sample of the CSV comma-separated values file.

About Us
About Us, Our Programs
About Us, Our History, Timeline
Mission
Mission, Community

I want these values to be inserted into a Vocabulary, It should have the depth and it should ignore parent terms it has already created. It should look just like this in Drupal

About Us
-Our Programs
-Our History
--Timeline
Mission
-Community

I created a simple migrate yml file that can do this but I had to restructure the CSV file a lot and it is too much manual work. Can regex or something search for the comma delimiter and make the term after a comma a child of the term in front of it? And can it skip or ignore parent terms it already created? Here is my migration and csv file.

id: vocab
label: Migrate terms from the source CSV to taxonomy terms
migration_group: migrated_terms
source:
   plugin: csv
   path: 'public://csv/vocab.csv'
   header_row_count: 1
   keys:
      - uuid
   column_names:
     0:
       uuid: UUID
     1:
       vid: VID
     2:
       name: NAME
     3:
       parent: PARENT
destination:
   plugin: entity:taxonomy_term
process:
   vid: vid
   name: name
   parent:
      plugin: migration
      migration: vocab
      source: parent

csv file

"uuid","vid","name","parent"
"100","myvocab","About Us"  
"101","myvocab","Our Programs","100"
"102","myvocab","Our History","100"
"103","myvocab","Mission"
"104","myvocab","Community","103"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.