After you stage your production websites to a non-production environment, you must run commands on your newly staged websites to synchronize them with your source environment’s data structure.
You can synchronize data with the post-staging-update
hook for your environment. If you don’t create a
post-staging-update
hook script, Site Factory will instead
execute the default drush updatedb
command.
Note
The post-staging-update
hook executes only if the non-production and
production environments aren’t running the same code.
For information on hook arguments, see Hook arguments.
Using the post-staging-update hook
Like several of the other hooks in use by Site Factory, you will create a script file following best practices for hook scripts. Place the script in a particular directory. Scripts in that directory are run in alphabetical order after the data copying process for each website being staged.
To use the post-staging-update
hook:
Create a script file including the commands to run after a staging deployment. You can create more than one script file for use with this hook, but the scripts will run in alphabetical order.
Create a directory called
factory-hooks
in the root of your code repository, if it doesn’t already exist.Note
The
factory-hooks
and docroot directories are separate directories at the same level in your code repository.Create a
post-staging-update
directory in thefactory-hooks
directory, if it doesn’t already exist.In the
/factory-hooks/post-staging-update
directory, add the script file or files you created for this procedure.Examine the files you created to ensure they have the executable flag. Failing to set the executable flag for scripts can prevent Site Factory from executing the files.
After executing a staging deployment, review the newly staged website, as well as any logging output created by your hook script, to check if your hook script executed successfully.
Troubleshooting database update hooks
If a script in the post-staging-update
directory ends with an error (a
non-zero exit code), no additional scripts will run in the directory, and the
task logs will display error messages in
SynchronizeSingleSite
tasks.
Example scripts
Change the following script to meet your needs:
#!/usr/bin/env bash
SITEGROUP="$1"
ENVIRONMENT="$2"
DB_ROLE="$3"
DOMAIN="$4"
echo "sitegroup: $SITEGROUP"
echo "env: $ENVIRONMENT"
echo "db role: $DB_ROLE"
echo "domain: $DOMAIN"
\drush8 -r /var/www/html/$SITEGROUP.$ENVIRONMENT/docroot -l $DOMAIN ev 'echo "Hello world";'