From 91c78b746d78e6e3ec2af67c6e917733dc27cb81 Mon Sep 17 00:00:00 2001 From: Don Richards Date: Tue, 24 Oct 2023 16:54:59 -0400 Subject: [PATCH] Add temp fix for node ids in migrate script --- custom.Makefile | 27 +++++++++++++++++---------- temp_migrate_fix.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) create mode 100755 temp_migrate_fix.sh diff --git a/custom.Makefile b/custom.Makefile index 7544081f8..c8b3d0420 100644 --- a/custom.Makefile +++ b/custom.Makefile @@ -189,19 +189,26 @@ jhu_demo_content: find islandora_workbench/islandora_workbench_demo_content/ -type f -name '*.yml' -exec $(SED_DASH_I) 's/^nopassword.*/password\: $(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)/g' {} + # Set the Domain within the YAML files. find islandora_workbench/islandora_workbench_demo_content/ -type f -name '*.yml' -exec $(SED_DASH_I) '/^host:/s/.*/host: "$(subst /,\/,$(subst .,\.,$(SITE)))\/"/' {} + - # Build the workbench docker image. + # Look up the Node ID of the collection you want to import into and replace the value with one live on the site. + # This is a hack to work around for workbench. There is a better method. + @echo "Starting hack for workbench." + bash temp_migrate_fix.sh + @echo "Build the workbench docker image." cd islandora_workbench && DOCKER_BUILDKIT=0 docker build -t workbench-docker . - # These Import taxonomy terms. - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_geo_location.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_copyright_and_use.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_family.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_person.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_corporate_body.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_genre.yml" - cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_subject.yml" - # These Import collections and objects. + @echo "Migrate/Import taxonomy terms." + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_geo_location.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_copyright_and_use.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_family.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_person.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_corporate_body.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_genre.yml" + # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_subject.yml" + @echo "Migrate/Import taxonomy terms complete." + @echo "Migrate/Import collections and objects." cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/jhu_root_collections.yml" + cd /home/don/github/idc-isle-dc/islandora_workbench/islandora_workbench_demo_content/migration_from_production/ ; head -n 101 islandora_objects.csv > islandora_objects_first_100.csv ; cd /home/don/github/idc-isle-dc cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/islandora_objects.yml" + @echo "Migrate/Import collections and objects complete." # Example of a rollback # cd islandora_workbench && docker run -it --rm --network="host" -v .:/workbench/ --name my-running-workbench workbench-docker bash -lc "./workbench --config /workbench/rollback.yml" diff --git a/temp_migrate_fix.sh b/temp_migrate_fix.sh new file mode 100755 index 000000000..bfe987f7d --- /dev/null +++ b/temp_migrate_fix.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# For each title find the Node ID and replace the "collection_object:$TITLE" with the Node ID in the CSV file. +# NODE_ID=$(docker-compose exec -T drupal with-contenv bash -lc 'drush ev '\''$nodes = \Drupal::entityTypeManager()->getStorage("node")->loadByProperties(["title" => "$TITLE[0]"]); if (!empty($nodes)) { print reset($nodes)->id(); } else { print "No node found with the given title."; }'\''') +# sed -i 's/"collection_object:Johns Hopkins File 7 (Television program)"/$NODE_ID/g' islandora_workbench/islandora_workbench_demo_content/migration_from_production/islandora_objects.yml +echo -e "\n\n\nRunning Script to replace the collection_object:$TITLE with the Node ID in the CSV file" + +# Define the titles in an array +TITLES=( + "Johns Hopkins File 7 (Television program)" + "Johns Hopkins science review (Television program)" + "Johns Hopkins University graphic and pictorial collection" + "Johns Hopkins University maps and atlases" + "Johns Hopkins University News-Letter" + "Johns Hopkins University oral history collection" + "Johns Hopkins University television programs collection" + "Tomorrow (Television program)" + "Tomorrow's careers (Television program)" +) + +# Define the file path +FILE_PATH="islandora_workbench/islandora_workbench_demo_content/migration_from_production/islandora_objects.csv" + +# Loop through each title +for TITLE in "${TITLES[@]}"; do + echo "Fetch the Node ID for the current title in the CSV file" + ESCAPED_TITLE=$(echo "$TITLE" | sed "s/'/'\\\\''/g") # Escape single quotes in the title + NODE_ID=$(docker-compose exec -T drupal with-contenv bash -lc "drush ev '\$nodes = \Drupal::entityTypeManager()->getStorage(\"node\")->loadByProperties([\"title\" => \"$ESCAPED_TITLE\"]); if (!empty(\$nodes)) { print reset(\$nodes)->id(); } else { print \"No node found with the given title.\"; }'") + + # Check if NODE_ID is numeric (meaning we found a valid node ID) + if [[ $NODE_ID =~ ^[0-9]+$ ]]; then + echo "Replace the collection_object:$TITLE with the Node ID in the file" + sed -i "s/,\"collection_object:$TITLE\",/,$NODE_ID,/g" "$FILE_PATH" + else + echo "No Node ID found for title: $TITLE" + fi +done + +echo -e "\ndone.\n\n\n"