Skip to content

Instantly share code, notes, and snippets.

@greenstack
Created March 24, 2017 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenstack/4e25be42c022433c3c0ba4d9cf92bd7b to your computer and use it in GitHub Desktop.
Save greenstack/4e25be42c022433c3c0ba4d9cf92bd7b to your computer and use it in GitHub Desktop.
If, in Drupal 7, you need to change your files from Public to Private (or maybe even the other way around), using this script will help you with that process.
#!/bin/bash
# Make a back up of the file field data tables
drush sqlq "CREATE TABLE field_data_field_$1_bak AS SELECT * FROM field_data_field_$1;"
drush sqlq "CREATE TABLE field_revision_field_$1_bak AS SELECT * FROM field_revision_field_$1;"
#empty file field data tables
drush sqlq "TRUNCATE TABLE field_data_field_$1;"
drush sqlq "TRUNCATE TABLE field_revision_field_$1;"
echo "In the file field settings in Drupal, the option to change the field $1 to"
echo "private is now available. Do so and save the field."
read -p "Once finished, press Enter to continue."
#copy all data from the temp backup tables back in to the real tables
drush sqlq "INSERT INTO field_data_field_$1 SELECT * FROM field_data_field_$1_bak;"
drush sqlq "INSERT INTO field_revision_field_$1 SELECT * FROM field_revision_field_$1_bak;"
echo "In the FILE (FIELD) PATH SETTINGS are of the file field settinsg in Drupal, select the 'Retroactive Upgrade' option and save; it will move all the files to the right place in the file system and update the db to the new path (which may take a little while)."
read -p "Once you have completed this step, press Enter to continue."
#delete the temp storage tables
drush sqlq "DROP TABLE field_data_field_$1_bak;"
drush sqlq "DROP TABLE field_revision_field_$1_bak;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment