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

DDST-366 and DDST-345: Update migration with missing bits and add support for multiple dates #137

Merged
merged 4 commits into from
Aug 27, 2024
Merged
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
119 changes: 108 additions & 11 deletions modules/dgi_migrate_foxml_standard_mods/migrations/dgis_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ destination:
#translations: true
validate: &validate true
process:
_unspecified_term:
- plugin: default_value
default_value: 'Unspecified'
_node_foxml_parsed:
- plugin: dgi_migrate.load_entity
source: fid
Expand Down Expand Up @@ -236,6 +239,9 @@ process:
- '@_sequence_number'
- '@_constituent_sequence'
- plugin: null_coalesce
# Prevent leading zeroes from crashing the migration.
- plugin: callback
callable: intval
- plugin: skip_on_empty
method: process
_mods_xpath:
Expand Down Expand Up @@ -1724,11 +1730,14 @@ process:
default_value: genre
<<: *generic_term_after
- <<: *generic_term_extract
_resource_type:
_resource_type_query:
- << : *base_mods_node
query: 'mods:typeOfResource'
- plugin: callback
callable: iterator_to_array
_resource_type:
- plugin: get
source: '@_resource_type_query'
- plugin: skip_on_empty
method: process
- plugin: multiple_values
Expand All @@ -1741,8 +1750,12 @@ process:
<<: *generic_term_after
- <<: *generic_term_extract
_unspecified_resource_type:
- plugin: default_value
default_value: Unspecified
- plugin: get
source: '@_resource_type_query'
- plugin: skip_on_empty
method: process
- plugin: get
source: '@_unspecified_term'
- plugin: gate
use_as_key: '@_resource_type'
valid_keys:
Expand Down Expand Up @@ -1998,7 +2011,7 @@ process:
validate: *validate
field_use_and_reproduction:
- << : *base_mods_node
query: 'mods:accessCondition[@type="use and reproduction"]'
query: 'mods:accessCondition[@type="use and reproduction" or @type="Use and Reproduction"]'
- plugin: callback
callable: iterator_to_array
- plugin: multiple_values
Expand Down Expand Up @@ -2036,11 +2049,14 @@ process:
default_value: degree_names
<<: *generic_term_after
- <<: *generic_term_extract
_degree_level:
_degree_level_query:
- <<: *base_mods_node
query: 'mods:extension/etd:degree/etd:level'
- plugin: callback
callable: iterator_to_array
_degree_level:
- plugin: get
source: '@_degree_level_query'
- plugin: skip_on_empty
method: process
- plugin: multiple_values
Expand All @@ -2053,8 +2069,12 @@ process:
<<: *generic_term_after
- <<: *generic_term_extract
_unspecified_degree_level:
- plugin: default_value
default_value: Unspecified
- plugin: get
source: '@_degree_level_query'
- plugin: skip_on_empty
method: process
- plugin: get
source: '@_unspecified_term'
- plugin: gate
use_as_key: '@_degree_level'
valid_keys:
Expand Down Expand Up @@ -2533,11 +2553,14 @@ process:
- plugin: single_value
- plugin: callback
callable: array_filter
_use_license:
_use_license_query:
- <<: *base_mods_node
query: 'mods:accessCondition[@type="use and reproduction"][@displayLabel="Creative Commons" or @displayLabe="Creative Commons"]'
query: 'mods:accessCondition[@type="use and reproduction" or @type="Use and Reproduction"][@displayLabel="Creative Commons" or @displayLabe="Creative Commons"]'
- plugin: callback
callable: iterator_to_array
_use_license:
- plugin: get
source: '@_use_license_query'
- plugin: skip_on_empty
method: process
- plugin: multiple_values
Expand All @@ -2550,8 +2573,12 @@ process:
<<: *generic_term_after
- <<: *generic_term_extract
_unspecified_use_license:
- plugin: default_value
default_value: Unspecified
- plugin: get
source: '@_use_license_query'
- plugin: skip_on_empty
method: process
- plugin: get
source: '@_unspecified_term'
- plugin: gate
use_as_key: '@_use_license'
valid_keys:
Expand Down Expand Up @@ -2592,6 +2619,76 @@ process:
- '@_use_license'
- '@_unspecified_use_license'
- plugin: flatten
_rights_statement_query:
- <<: *base_mods_node
query: 'mods:accessCondition[@type="rights statement"]'
- plugin: callback
callable: iterator_to_array
_rights_statement:
- plugin: get
source: '@_rights_statement_query'
- plugin: skip_on_empty
method: process
- plugin: multiple_values
- plugin: dgi_migrate.sub_process
process_values: true
values:
_vid:
- plugin: default_value
default_value: rights_statements
<<: *generic_term_after
- <<: *generic_term_extract
- plugin: single_value
- plugin: callback
callable: array_filter
- plugin: null_coalesce
_unspecified_rights_statement:
- plugin: get
source: '@_rights_statement_query'
- plugin: skip_on_empty
method: process
- plugin: get
source: '@_unspecified_term'
- plugin: gate
use_as_key: '@_rights_statement'
valid_keys:
- null
key_direction: unlock
- plugin: dgi_migrate.sub_process
process_values: true
values:
_vid:
- plugin: default_value
default_value: rights_statements
_auth_value_uri:
- plugin: default_value
default_value: ''
_auth_source:
- plugin: default_value
default_value: ''
_value:
- plugin: get
source: parent_value
actual:
- plugin: get
source:
- '@_auth_source'
- '@_auth_value_uri'
- '@_value'
# XXX: Needs to be provided wherever this is used, corresponding
# to the vocab in which to do the things.
- '@_vid'
- plugin: flatten
- plugin: migration_lookup
migration: dgis_stub_terms_generic
stub_id: dgis_stub_terms_generic
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
- <<: *generic_term_extract
field_rights_statement:
- plugin: get
source:
- '@_rights_statement'
- '@_unspecified_rights_statement'
- plugin: null_coalesce
nid:
- plugin: migration_lookup
source: '@field_pid'
Expand Down
29 changes: 23 additions & 6 deletions src/Plugin/migrate/process/AssembleDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* The output is handled thus:
* - If a range_start, or a range_end, or both, are provided and not empty, an
* EDTF-style date range will be assembled, and any results from single_date
* will be ignored.
* will be combined.
* - If neither a range_start nor a range_end are provided or are empty, but the
* single_date is provided and has a value, it is returned.
* - If no provided property has a value, null will be returned.
Expand All @@ -37,7 +37,8 @@
* @code
* process:
* - plugin: dgi_migrate.process.assemble_date
* single_date: 2001-01-01
* single_date:
* - 2001-01-01
* range_start: 2002-02-02
* range_end: 2003-03-03
* indicate_open: false
Expand Down Expand Up @@ -108,11 +109,27 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$return_value = $this->getDateRange($value, $migrate_executable, $row);
if (!$return_value) {
$return_value = $this->getValues ? $row->get($this->dates['single_date']) : $this->dates['single_date'];
$return_dates = [];

$date_range = $this->getDateRange($value, $migrate_executable, $row);
if ($date_range !== NULL) {
$return_dates[] = $date_range;
}

// Get single dates and add them to return_dates.
$single_dates = $this->getValues ? $row->get($this->dates['single_date']) : $this->dates['single_date'];
if (is_array($single_dates)) {
$return_dates = array_merge($return_dates, $single_dates);
}
elseif ($single_dates !== NULL) {
$return_dates[] = $single_dates;
}
return $return_value;

if (count($return_dates) === 1) {
return reset($return_dates);
}

return $return_dates;
}

/**
Expand Down
Loading