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

Proof of concept to migrate from Hugo JSON endpoints to Drupal using the migrate module #1

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"drupal/maillog": "dev-1.x",
"drupal/mailsystem": "^4.4",
"drupal/memcache": "^2.5",
"drupal/migrate_plus": "^6.0",
"drupal/require_revision_log_message": "^2.0",
"drupal/scheduler": "^2.0",
"drupal/scheduler_content_moderation_integration": "^2.0@beta",
Expand Down
67 changes: 66 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions composer.log
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ bd188b544a4fe1c3f347f6b125585b17|Matt Poole|develop|Wed Jun 12 19:49:23 EDT 2024
abe3fa91a2c15b6b571ea0c019e2daf7|Matt Poole|develop|Tue Jul 2 13:35:21 EDT 2024|./composer.sh require drupal/maillog
23ef02af0f842a216c54ec0bd469e3d1|Matt Poole|develop|Tue Jul 2 13:41:08 EDT 2024|./composer.sh require drupal/mailsystem
ae2759e9c45acbf0d8378d04e842d0a8|Matt Poole|develop|Tue Jul 2 13:45:43 EDT 2024|./composer.sh require drupal/maillog:dev-1.x
bee6963c114940945ea38110d5af9e93|Matt Poole|feature/migrate-image-example|Fri Aug 2 14:40:47 EDT 2024|./composer.sh require drupal/migrate_plus
2 changes: 1 addition & 1 deletion composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Disable drupal/core from scaffolding without being in composer.extra.drupal-scaffold.allowed-packages in that way one has more control of when new scaffolding is added.": "./patches/drupal.core-composer-scaffold.implicit-drupal-core-disable.patch"
},
"drupal/maillog": {
"/project/maillog/issues/3176023: Not configurable sender and other issues.": "https://www.drupal.org/files/issues/2024-01-17/maillog-n3176023-6.patch"
"/project/maillog/issues/3176023: Not configurable sender and other issues.": "https://www.drupal.org/files/issues/2024-07-24/maillog-n3176023-9.patch"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: 'Digital.gov Migration'
type: module
description: 'Migrations to Drupal from Hugo.'
package: Custom
core_version_requirement: ^10 || ^11
dependencies:
- migrate_plus:migrate_plus
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
id: json_images
label: 'Import images from Digital.gov Hugo'
source:
constants:
DRUPAL_FILE_DIRECTORY: 'public://m-images/'

plugin: url
data_fetcher_plugin: file
data_parser_plugin: json

urls:
# The host may have to change, depending on your local. For example, in
# WSL2, I had ot replace this with my WSL2 instances IP since Drupal is
# running inside a Docker Lando container, so localhost is the container
# not WSL2, where Hugo is. This shouldn't matter if this is a remote host.
# Another host to try is host.docker.internal or find your local machine's
# IP address.
#- http://172.31.222.216:1313/images/v1/json/
#- http://localhost:1313/images/v1/json/
- https://federalist-466b7d92-5da1-4208-974f-d61fd4348571.sites.pages.cloud.gov/preview/gsa/digitalgov.gov/1631-migrate-approaches/images/v1/json/


# XPath-like selector. The slash (/) at the beginning is optional.
# This is needed if the content is not at the root.
item_selector:
fields:
- name: src_image_id
label: 'Image ID'
selector: uid
- name: src_image_url
label: 'Image URL'
selector: source-url
ids:
src_image_id:
type: string
process:
psf_destination_filename:
plugin: callback
callable: basename
source: src_image_url
psf_destination_full_path:
- plugin: concat
source:
- constants/DRUPAL_FILE_DIRECTORY
- '@psf_destination_filename'
- plugin: urlencode
psf_source_image_path:
plugin: urlencode
source: src_image_url
# This is the field that actually gets saved to the file entity, the rest
# are just pseudo fields for populating it.
uri:
# https://api.drupal.org/api/drupal/core%21modules%21migrate%21src%21Plugin%21migrate%21process%21FileCopy.php/class/FileCopy/10
plugin: file_copy
source:
- '@psf_source_image_path'
- '@psf_destination_full_path'
file_exists: 'use existing'
move: FALSE
destination:
plugin: 'entity:file'