#!/bin/bash migrate_loop() { # Better readability with separation. echo "========================"; # Get the output of the drush status. drush_output=$(drush ms "$1" --format string); # Split output string into an array. output=( $drush_output ) # Output the status items. for index in "${!output[@]}" do if [ "$index" == "3" ] then echo "Migration: ${output[index]}"; fi if [ "$index" == "4" ] then echo "Status: ${output[index]}"; fi if [ "$index" == "5" ] then echo "Total: ${output[index]}"; fi if [ "$index" == "6" ] then echo "Imported: ${output[index]}"; fi if [ "$index" == "7" ] then echo "Remaining: ${output[index]}"; fi done # Check if all items were imported. if [ "${output[7]}" == "0" ] || [ "${output[7]}" -lt "0" ] then echo "No items left to import."; else echo "There are ${output[7]} remaining ${output[3]} items to be imported."; echo "Running command: drush migrate:import $1"; echo "..."; # Run the migration until it stops. drush migrate:reset "$1"; drush migrate:import "$1" --feedback 1000 --limit 10000; # Run the check on this migration again. migrate_loop "$1"; fi } if [ "$1" == "reset" ]; then printf "\\nResetting migration status...\\n\\n" drush cr >/dev/null 2>&1 drush migrate:status --format=var_export | grep -o "\\w*example_\\w*" | grep -v "example_migration" | xargs -n1 drush migrate:stop drush migrate:status --format=var_export | grep -o "\\w*example_\\w*" | grep -v "example_migration" | xargs -n1 drush migrate:reset-status printf "\\n\\nMigration status reset. Run ./scripts/migrate.sh to start migrating data or ./scripts/migrate.sh rollback to rollback data as well.\\n\\n" elif [ "$1" == "rollback" ]; then drush migrate:status --format=var_export | grep -o "\\w*example_\\w*" | grep -v "example_migration" | xargs -n1 drush migrate:stop drush migrate:status --format=var_export | grep -o "\\w*example_\\w*" | grep -v "example_migration" | xargs -n1 drush migrate:reset-status drush migrate:status --format=var_export | grep -o "\\w*example_\\w*" | grep -v "example_migration" | xargs -n1 drush migrate:rollback printf "\\n\\nMigration rolled back. Run ./scripts/migrate.sh to start migrating data.\\n\\n" else printf "Updating database and entity definitions...\\n" drush updb -y >/dev/null 2>&1 drush entup -y >/dev/null 2>&1 migrate_loop example_migration migrate_loop another_example_migration migrate_loop my_example_migration fi