#! /bin/bash

export PATH=$Path:/bin:/usr/bin:/usr/local/bin
DATE=`date +%d-%m-%y/%H:%M:%S`

# https://www.mediacurrent.com/blog/memory-management-migrations-drupal-8/

echo -e "* * * * * * * * * * * * * * * *"
echo -e "*                             *"
echo -e "*         Migration           *"
echo -e "*                             *"
echo -e "* $DATE           *"
echo -e "*                             *"
echo -e "* * * * * * * * * * * * * * * *"

echo " "
echo "Reseting migrations states"
drush mrs d7_allpublicfiles
drush mrs d7_taxonomy_term_thesaurus
drush mrs d7_taxonomy_term_thesaurus_i18n
drush mrs d7_taxonomy_term_tags
drush mrs d7_taxonomy_term_tags_i18n
drush mrs d7_taxonomy_term_company
drush mrs d7_taxonomy_term_showroom
drush mrs d7_users
drush mrs d7_user_profile
drush mrs d7_uc_roles_license
drush mrs d7_node_materiau
drush mrs d7_node_materiau_i18n
drush mrs d7_node_article
drush mrs d7_node_article_i18n
drush mrs d7_simplenews_nodes
drush mrs d7_simplenews_subscribers
drush mrs d7_flaglists
drush mrs d7_flaglistitems
sleep 5



echo " "
echo "Migrating Files"
drush mim d7_allpublicfiles --feedback="1000"
sleep 5

echo " "
echo "Migrating Taxonomy"
echo "Migrating thesaurus"
drush mim d7_taxonomy_term_thesaurus --update --feedback="100"
echo " "
drush mim d7_taxonomy_term_thesaurus_i18n --update --feedback="100"
sleep 5

echo " "
echo "Migrating tags"
drush mim d7_taxonomy_term_tags --update --feedback="100"
echo " "
drush mim d7_taxonomy_term_tags_i18n --update --feedback="100"
sleep 5

echo " "
echo "Migrating companies"
drush mim d7_taxonomy_term_company --update --feedback="100"
sleep 5

echo " "
echo "Migrating showroom"
drush mim d7_taxonomy_term_showroom --update --feedback="100"
sleep 5

echo " "
echo "Migrating Users"
drush mim d7_users --update --feedback="1000"
echo " "
drush mim d7_user_profile --feedback="1000"
echo " "
drush mim d7_uc_roles_license --update --feedback="200"
sleep 5

echo " "
echo "Migrating Nodes"
echo "Migrating Materials"
drush mim d7_node_materiau --feedback="1000"
echo " "
drush mim d7_node_materiau_i18n --feedback="1000"
sleep 5

echo " "
echo "Migrating breves"
drush mim d7_node_article --feedback="100"
echo " "
drush mim d7_node_article_i18n --feedback="100"
sleep 5

echo " "
echo "Migrating simplenews"
drush mim d7_simplenews_nodes --feedback="200"
drush mim d7_simplenews_subscribers --update --feedback="1000"
sleep 5

echo " "
echo "Migrating flaglists"
drush mim d7_flaglists --feedback="200"
echo " "
drush mim d7_flaglistitems --feedback="200"
sleep 5

echo " "
echo "Regenerating url aliases for nodes and terms"
drush pag all canonical_entities:taxonomy_term
drush pag all canonical_entities:node
sleep 5
