Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Keys/ID #36

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions config/install/migrate_plus.migration.example_collections_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Uninstall this config when the feature is uninstalled
dependencies:
enforced:
module:
- migrate_islandora_csv

id: example_collections_file
label: Step 2 - Import Example Collection Thumbnail image Files
migration_group: example_collections_migrate_islandora_csv

source:
plugin: csv
path: modules/contrib/migrate_islandora_csv/data/example_collections.csv
delimiter: ','
enclosure: '"'
header_row_count: 1

keys:
- ID

constants:
destination_dir: 'fedora://csv_migration'
filemime: image/jpeg
uid: 1

process:
filemime: constants/mimetype
uid: constants/uid

filename:
-
plugin: callback
callable: pathinfo
source: TN
-
plugin: extract
index:
- basename

destination:
-
plugin: concat
delimiter: /
source:
- constants/destination_dir
- '@filename'

uri:
plugin: file_copy
source:
- TN
- '@destination'

destination:
plugin: 'entity:file'
type: file
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Uninstall this config when the feature is uninstalled
dependencies:
enforced:
module:
- migrate_islandora_csv

id: example_collections_media
label: Step 4 - Generate Example Collection Media
migration_group: example_collections_migrate_islandora_csv

source:
plugin: csv
path: modules/contrib/migrate_islandora_csv/data/example_collections.csv
delimiter: ','
enclosure: '"'

# 1 means you have a header row, 0 means you don't
header_row_count: 1

# Each migration needs a unique key per row in the csv. Here we're using the file path.
keys:
- ID

# You can't enter string literals into a process plugin, but you can give it a constant as a 'source'.
constants:
# We're tagging our media as Thumbnail Image
use: Thumbnail Image

# Everything gets created as admin
uid: 1

process:

name: title
uid: constants/uid

# Make the media an 'Original File'
field_media_use:
plugin: entity_lookup
source: constants/use
entity_type: taxonomy_term
value_key: name
bundle_key: vid
bundle: islandora_media_use

# Lookup the migrated file in the file migration.
field_media_image:
alt: title
plugin: migration_lookup
source: ID
migration: example_collections_file
no_stub: true

# Lookup the migrated node in the node migration
field_media_of:
plugin: migration_lookup
source: ID
migration: example_collections_node
no_stub: true

destination:
# These are 'image' media we're making.
plugin: 'entity:media'
default_bundle: image

migration_dependencies:
required:
- migrate_plus.migration.example_collections_file
- migrate_plus.migration.example_collections_subjects
- migrate_plus.migration.example_collections_node
optional: { }
117 changes: 117 additions & 0 deletions config/install/migrate_plus.migration.example_collections_node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Uninstall this config when the feature is uninstalled
dependencies:
enforced:
module:
- migrate_islandora_csv

id: example_collections_node
label: Step 3 - Import Example Collection Nodes
migration_group: example_collections_migrate_islandora_csv

source:
plugin: csv
path: modules/contrib/migrate_islandora_csv/data/example_collections.csv
delimiter: ','
enclosure: '"'

# 1 means you have a header row, 0 means you don't
header_row_count: 1

# Each migration needs a unique key per row in the csv. Here we're using the file path.
keys:
- ID

# You can't enter string literals into a process plugin, but you can give it a constant as a 'source'.
constants:
# Everything gets created as admin
uid: 1

# Set fields using values from the CSV
process:
title: title
uid: constants/uid

promote: promote

field_description:
plugin: skip_on_empty
source: description
method: process

field_model:
plugin: entity_lookup
source: model
entity_type: taxonomy_term
value_key: name
bundle_key: vid
bundle: islandora_models

# Split up our pipe-delimited string of
# subjects, and generate terms for each.
field_subject:
-
plugin: skip_on_empty
source: subject
method: process
-
plugin: explode
delimiter: '|'
-
plugin: entity_generate
entity_type: taxonomy_term
value_key: name
bundle_key: vid
bundle: subject

field_member_of:
-
plugin: skip_on_empty
source: parent_id
method: process
-
plugin: migration_lookup
source: parent_id
migration: example_collections_node
no_stub: true

languages:
-
source: languages
plugin: skip_on_empty
method: process
-
plugin: explode
delimiter: '|'
-
plugin: str_to_assoc
key: 'name'

languages_creator:
plugin: sub_process
source: '@languages'
process:
target_id:
plugin: entity_generate
source: name
entity_type: taxonomy_term
value_key: name
bundle_key: vid
bundle: 'language'

field_language: '@languages'

# This is to keep track of the old PIDs
field_pid:
plugin: skip_on_empty
source: PID
method: process

# We're making nodes
destination:
plugin: 'entity:node'
default_bundle: islandora_object

migration_dependencies:
required:
- migrate_plus.migration.example_collections_subjects
optional: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Uninstall this config when the feature is uninstalled
dependencies:
enforced:
module:
- migrate_islandora_csv

id: example_collections_subjects
label: Step 1 - Import Example Collection Subjects
migration_group: example_collections_migrate_islandora_csv

source:
plugin: csv
path: modules/contrib/migrate_islandora_csv/data/collection_subjects.csv
delimiter: ','
enclosure: '"'

# 1 means you have a header row, 0 means you don't
header_row_count: 1

# You can't enter string literals into a process plugin, but you can give it a constant as a 'source'.
constants:
# Everything gets created as admin
uid: 1

keys:
- subject

# Set fields using values from the CSV
process:
# uid: constants/uid
uid:
plugin: default_value
default_value: 1

name: subject
field_authority_link/title: subject
field_authority_link/source: subject_authority
field_authority_link/uri: subject_uri

destination:
plugin: entity:taxonomy_term
default_bundle: subject
38 changes: 21 additions & 17 deletions config/install/migrate_plus.migration.example_migration_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,75 @@
dependencies:
enforced:
module:
- migrate_islandora_csv
- migrate_islandora_csv

id: example_migration_file
label: Import Image Files
migration_group: migrate_islandora_csv
migration_group: example_migrate_islandora_csv

source:
plugin: csv
path: 'modules/contrib/migrate_islandora_csv/data/migration.csv'
delimiter: ','
enclosure: '"'

# 1 means you have a header row, 0 means you don't
header_row_count: 1
header_row_count: 1

# Each migration needs a unique key per row in the csv. Here we're using the file path.
# Each migration needs a unique key per row in the csv. Here we're using the ID, it was an arbitrary selection but one that is unique to each CSV row.
keys:
- file
- ID

# You can't enter string literals into a process plugin, but you can give it a constant as a 'source'.
constants:
# Islandora uses flysystem and stream wrappers to work with files. What we're really saying here is
# to put these files in Fedora in a 'csv_migration' folder. It doesn't matter if the directory
# doesn't exist yet, it will get created for you automatically.
destination_dir: 'fedora://csv_migration'
destination_dir: 'fedora://csv_migration'

# Hard-code mime type to jpeg. This could easily come from a column in the CSV if you have
# different mimetypes.
mimetype: image/jpeg
# mimetype: image/jpeg

# Everything gets created as admin
uid: 1

process:

# Set these properties from constants.
filemime: constants/mimetype
filemime: mimetype
uid: constants/uid

# Hack the file name out of the full path provided in the 'file' column.
filename:
filepath:
-
plugin: callback
callable: pathinfo
source: file
source: filename
-
plugin: extract
index:
- basename

# Construct the destination URI using the file name.
destination:
plugin: concat
delimiter: /
source:
- constants/destination_dir
- '@filename'
-
plugin: concat
delimiter: /
source:
- constants/destination_dir
- '@filepath'
-
plugin: urlencode

##
# Here's where we copy the file over and set the uri of the file entity.
##
uri:
plugin: file_copy
source:
- file # The source column in the CSV
- '@destination' # The destination entry from above
- filename # The source column in the CSV
- '@destination' # The destination entry from above


destination:
Expand Down
Loading