lcatlett
10/3/2017 - 7:01 PM

db-update factory hook

db-update factory hook

 #!/bin/sh
#
# Factory Hook: db-update
#
# The existence of one or more executable files in the
# /factory-hooks/db-update directory will prompt them to be run *instead of* the
# regular database update (drush updatedb) command. So that update command will
# normally be part of the commands executed below.
#
# Usage: post-code-deploy site env db-role domain custom-arg1 custom-arg2 ...
# Map the script inputs to convenient names.
# Acquia hosting site / environment names are site env db-role domain etc
site="$1"
env="$2"

# database role. This is needed to query the gardens data for the required information. 
db_role="$3"

# this is not used in this script to ensure the primary ACSF domain is used as the uri. 
domain="$4"

# The primary domain name of the website. Use this method to avoid committing rest api creds 
# and support automation for sites that do not have drush aliases committed to the repo.  
uri=`/usr/bin/env php /mnt/www/html/$site.$env/hooks/acquia/uri.php $site $env $db_role`

# The websites' document root can be derived from the site/env:
docroot="/var/www/html/$site.$env/docroot"

# When running drush, provide the docroot + url, rather than relying on
# aliases. This ensures that they do not need to be committed to the repo.  

DRUSH_CMD="drush --root=$docroot --uri=$uri"

# Run updb as required by ACSF
$DRUSH_CMD updatedb

  if [ $? -ne 0 ]; then
  	 # If updb fails, do not continue with deploy tasks for that site
  	 # because dependencies may not have been installed. 
      echo "Update errored for site $uri."
      exit 1
  fi

  # ensure cache tools drush commands are installed and executable

  $DRUSH_CMD en -y cache_tools

  $DRUSH_CMD cc drush

  # run purge 

  $DRUSH_CMD cache-tools-purge
  
  echo "Finished deployment updates for $uri."