diff --git a/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit.yml b/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit.yml new file mode 100644 index 0000000..83a8d66 --- /dev/null +++ b/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit.yml @@ -0,0 +1,85 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - migrate_7x_claw + - migrate_plus + - islandora +id: islandora_basic_image_audit +class: null +field_plugin_method: null +cck_plugin_method: null +migration_tags: null +migration_group: islandora_7x +label: 'Basic Image Objects AUDIT File' +source: + plugin: islandora + solr_base_url: 'http://10.0.2.2:18080/solr' + fedora_base_url: 'http://10.0.2.2:18080/fedora' + data_fetcher_plugin: http + authentication: + plugin: basic + username: fedoraAdmin + password: fedoraAdmin + content_model_field: RELS_EXT_hasModel_uri_ms + content_model: 'islandora:sp_basic_image' + data_parser_plugin: authenticated_xml + item_selector: '/foxml:digitalObject' + constants: + destination_directory: 'fedora://masters' + mimetype: application/xml + extension: xml + dsid: AUDIT + fedora_base_url: 'http://10.0.2.2:18080/fedora' + creator_uid: 1 + fields: + - + name: PID + label: PID + selector: '@PID' + - + name: audit_ds + label: Audit Datastream + selector: 'foxml:datastream[@ID = "AUDIT"]/foxml:datastreamVersion/foxml:xmlContent[1]' + ids: + PID: + type: string +process: + digital_id: + - + plugin: concat + delimiter: _ + source: + - PID + - constants/dsid + - + plugin: str_replace + search: ':' + replace: _ + filemime: constants/mimetype + uid: constants/creator_uid + filename: + plugin: concat + delimiter: . + source: + - '@digital_id' + - constants/extension + destination: + plugin: concat + delimiter: / + source: + - constants/destination_directory + - '@filename' + uri: + - + plugin: flatten + source: + - '@destination' + - audit_ds + - + plugin: file_blob +destination: + plugin: 'entity:file' + default_bundle: file +migration_dependencies: null diff --git a/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit_media.yml b/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit_media.yml new file mode 100644 index 0000000..c0c666e --- /dev/null +++ b/modules/islandora_migrate_7x_claw_feature/config/install/migrate_plus.migration.islandora_basic_image_audit_media.yml @@ -0,0 +1,77 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - migrate_7x_claw + - migrate_plus + - islandora +id: islandora_basic_image_audit_media +class: null +field_plugin_method: null +cck_plugin_method: null +migration_tags: null +migration_group: islandora_7x +label: 'Basic Image Objects AUDIT Media' +source: + plugin: islandora + solr_base_url: 'http://10.0.2.2:18080/solr' + fedora_base_url: 'http://10.0.2.2:18080/fedora' + data_fetcher_plugin: http + authentication: + plugin: basic + username: fedoraAdmin + password: fedoraAdmin + content_model_field: RELS_EXT_hasModel_uri_ms + content_model: 'islandora:sp_basic_image' + data_parser_plugin: authenticated_xml + item_selector: '/foxml:digitalObject' + constants: + destination_directory: 'fedora://masters' + mimetype: application/xml + extension: xml + dsid: AUDIT + fedora_base_url: 'http://10.0.2.2:18080/fedora' + creator_uid: 1 + fields: + - + name: PID + label: PID + selector: '@PID' + ids: + PID: + type: string +process: + digital_id: + - + plugin: concat + delimiter: _ + source: + - PID + - constants/dsid + - + plugin: str_replace + search: ':' + replace: _ + name: + plugin: concat + delimiter: . + source: + - '@digital_id' + - constants/extension + field_media_file: + plugin: migration_lookup + migration: islandora_basic_image_audit + source: PID + no_stub: true + field_media_of: + plugin: migration_lookup + migration: islandora_basic_image + source: PID + no_stub: true + uid: constants/creator_uid +destination: + plugin: 'entity:media' + default_bundle: file +migration_dependencies: null + diff --git a/src/Plugin/migrate_plus/data_parser/AuthenticatedXml.php b/src/Plugin/migrate_plus/data_parser/AuthenticatedXml.php index 00f97e4..5ed2a86 100644 --- a/src/Plugin/migrate_plus/data_parser/AuthenticatedXml.php +++ b/src/Plugin/migrate_plus/data_parser/AuthenticatedXml.php @@ -2,7 +2,7 @@ namespace Drupal\migrate_7x_claw\Plugin\migrate_plus\data_parser; -use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml; +use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\SimpleXml; /** * Obtain XML data for migration using the XMLReader pull parser. @@ -12,7 +12,7 @@ * title = @Translation("Authenticated XML") * ) */ -class AuthenticatedXml extends Xml { +class AuthenticatedXml extends SimpleXml { /** * Update the configuration for the dataparserplugin. @@ -30,32 +30,32 @@ public function updateUrls($urls) { $this->urls = $urls; } - /** - * {@inheritdoc} - */ - protected function openSourceUrl($url) { - // (Re)open the provided URL. - $this->reader->close(); + protected function fetchNextRow() { + $target_element = array_shift($this->matches); - // Clear XML error buffer. Other Drupal code that executed during the - // migration may have polluted the error buffer and could create false - // positives in our error check below. We are only concerned with errors - // that occur from attempting to load the XML string into an object here. - libxml_clear_errors(); - - if (is_null($url)) { - // No URL means no source. - return FALSE; + // If we've found the desired element, populate the currentItem and + // currentId with its data. + if ($target_element !== FALSE && !is_null($target_element)) { + foreach ($this->fieldSelectors() as $field_name => $xpath) { + foreach ($target_element->xpath($xpath) as $value) { + if ($value->children() && !trim((string) $value)) { + $this->currentItem[$field_name] = $value; + } + elseif (!trim((string) $value)){ + $this->currentItem[$field_name][] = $value->asXML(); + } + else { + $this->currentItem[$field_name][] = (string) $value; + } + } + } + // Reduce single-value results to scalars. + foreach ($this->currentItem as $field_name => $values) { + if (count($values) == 1) { + $this->currentItem[$field_name] = reset($values); + } + } } - - // Get the XML using the data fetcher to allow us to access URLs requiring - // authentication. - $xml = $this->getDataFetcherPlugin() - ->getResponseContent($url) - ->getContents(); - - return $this->reader->XML($xml, NULL, \LIBXML_NOWARNING); - } /** @@ -72,3 +72,4 @@ protected function nextSource() { } } +