Your software
My Mautic version is: 4.X
My PHP version is: 7.4
My Database type and version is: N/A
We have been experiencing issues with segment filters losing values after minor point upgrades. This stops the cron job in its tracks and only some of our segments get updated.
What are you doing to proactively notify someone when this (or other Mautic errors) happen? Is there some magic you can add to a cron command to notify an admin when it errors?
I love that out of date segments get a red exclamation mark now, but I’d rather not have to wait until a member of our team logs in and happens to navigate to the segment tab to know that some of our segments aren’t updating.
#!/bin/bash
set -xu
MAUTIC_DOCROOT=$(realpath $(pwd)/../public_html/)
PHP_BIN="/usr/bin/php"
MAUTIC_CLI="$PHP_BIN $MAUTIC_DOCROOT/bin/console"
# change to mautic docroot
cd $MAUTIC_DOCROOT
# get db credentials
HOST=$(grep db_host app/config/local.php |cut -d"'" -f4)
DATABASE=$(grep db_name app/config/local.php |cut -d"'" -f4)
USER=$(grep db_user app/config/local.php |cut -d"'" -f4)
PASSWORD=$(grep db_password app/config/local.php |cut -d"'" -f4)
function trap_error {
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Error during segment command ... "
# HERE YOU CAN CALL A COMMAND TO NOTIFY YOU
# dshofdhf
fi
}
trap trap_error EXIT
while read -a row
do
# call the segment rebuild per id and timeout after 5,5 hours
/usr/bin/timeout --preserve-status 20000 $MAUTIC_CLI mautic:segments:update --batch-limit=200 --list-id=${row} -q -n
done < <(echo 'select id from lead_lists where is_published=1' | mysql --host=${HOST} --user=${USER} --password=${PASSWORD} --batch -s --database=$DATABASE)
(the script expects to be in a dir scripts and goes one level up and change into public_html. replace MAUTIC_DOCROOT with your mautic document root)
Script explanation:
We change into the mautic document root and get the db credentials from the mautic config
We then use the db credentials to get every published segment and rebuild it
We use the timeout command to prevent an endless running command. We preserve the status of the command to get the exit code.