From 3c004ef6b418e9d0b7102dc69b3b674abf940acd Mon Sep 17 00:00:00 2001 From: jonasdemoor <17252323+jonasdemoor@users.noreply.github.com> Date: Fri, 22 Mar 2019 14:34:07 +0100 Subject: [PATCH] check_drupal_cron: Add workaround for existing MySQL client config On older versions of Drush 8.x, `drush state-get system.cron_last` fails because the MySQL client config file takes precedence over Drupal's settings.php file. Related issue: https://github.com/drush-ops/drush/issues/2183 --- check_drupal-cron | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/check_drupal-cron b/check_drupal-cron index 09c8b9a..a986ded 100755 --- a/check_drupal-cron +++ b/check_drupal-cron @@ -15,6 +15,15 @@ else fi fi +# Workaround for https://github.com/drush-ops/drush/issues/2183. +# On older Drush 8.x versions, .my.cnf has preference over settings.php, +# which causes `drush state-get system.cron_last` to fail. +if [[ -f "${HOME}/.my.cnf" ]] +then + DRUSH_HOME="/tmp" +else + DRUSH_HOME="${HOME}" +fi while getopts u:r:c:w: o; do case "$o" in @@ -34,10 +43,10 @@ DRUPAL_VERSION=$(${DRUSH} --root=${root} --uri=${uri} status | grep 'Drupal vers if [[ "$DRUPAL_VERSION" =~ ^[6-7] ]] then # drupal 6/7 - LAST_CRON_RUN=$(${DRUSH} --root=${root} --uri=${uri} vget '^cron_last$'|cut -d: -f 2) + LAST_CRON_RUN=$(HOME=${DRUSH_HOME} ${DRUSH} --root=${root} --uri=${uri} vget '^cron_last$'|cut -d: -f 2) else # other drupal versions - LAST_CRON_RUN=$(${DRUSH} --root=${root} --uri=${uri} state-get system.cron_last) + LAST_CRON_RUN=$(HOME=${DRUSH_HOME} ${DRUSH} --root=${root} --uri=${uri} state-get system.cron_last) fi DELTA=$(($NOW - $LAST_CRON_RUN))