Skip to content

Commit

Permalink
Add temp fix for node ids in migrate script
Browse files Browse the repository at this point in the history
  • Loading branch information
DonRichards committed Oct 24, 2023
1 parent 7659303 commit 91c78b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
27 changes: 17 additions & 10 deletions custom.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
39 changes: 39 additions & 0 deletions temp_migrate_fix.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 91c78b7

Please sign in to comment.