Skip to content

virgilwashere/mautic-cron-commands

Repository files navigation

author date version copyright license link
Virgil <virgil@virgilwashere.co>
2019-10-20
0.1.6
2019 Virgil
All rights reserved
GPL3

Mautic

Mautic cron commands

commands.php can be used in environments where you do not have SSH access to run the Mautic command line tool: app/console.

Requirements β˜‘οΈ

  • a Mautic installation
    • works with Mautic 2.12+
  • a webserver with PHP support

Installation πŸš€

⚠️WARNING
DO NOT leave the $secretphrase as mautibot_happy

  1. πŸ”½οΈ Download [commands.php] (or clone the repo)

  2. ✏️Edit your local copy of [commands.php]

    1. πŸ” Change the $secretphrase parameter in the script to a new secret phrase so only you will be able to run the commands.
    2. 🎨 Optional: replace $logo with another <img src= link.
  3. 🐦Copy your modifed commands.php to the root folder of your Mautic installation via SSH terminal, (s)FTP upload or carrier pigeon.

    ℹ️ NOTE
    This is the same level as Mautic's LICENSE.txt file and the directory app/

nginx config for shared vhosts

Add this to the server block for the vhost.

server {
    #server_name      mautic.example.com;
    #...

    set $mautic_root /var/www/vhost1/mautic;
    include snippets/mautic_cron.conf;
}

snippets/mautic_cron.conf

    location /cron/ {
        # URL would be https://mautic.example.com/cron/commands.php
        root    $mautic_root;
        index   commands.php;

        location ~ /(commands|import)\.php(/|$) {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;

            #override SCRIPT_FILENAME
            fastcgi_param  SCRIPT_FILENAME $request_filename;
            fastcgi_param  HTTP_PROXY   "";
            fastcgi_read_timeout        600;
            fastcgi_buffers             16 16k;
            fastcgi_buffer_size         32k;
            fastcgi_intercept_errors    on;
            fastcgi_param  MAUTIC_ROOT  $mautic_root;
        }
    }

How to use 🚴

mautibot

When you open the URL, you are presented with a list of available commands. You can click on those to run the command, or use the Encoded URL link to a specific command in a cronjob/scheduler service, like Jenkins CI/CD.

πŸ‘ͺ Interactively

  1. 🌐 Open the commands.php URL with your browser

    https://mautic.example.com/commands.php?mautibot_happy
  2. ❔ Optional. Append &pretty to the URL to display a logo and basic navigation

     https://mautic.example.com/commands.php?mautibot_happy&pretty

pretty-list

command list
$allowedCmds = array(
    'list',
    'mautic:segments:update',
    'mautic:campaigns:update',
    'mautic:campaigns:trigger',
    'cache:clear',
    'mautic:emails:send',
    'mautic:emails:fetch',
    'mautic:emails:send --quiet',
    'mautic:emails:fetch --quiet',
    'mautic:broadcasts:send',
    'mautic:broadcasts:send --quiet',
    'mautic:broadcasts:send --channel=email',
    'mautic:broadcasts:send --channel=sms',
    'mautic:messages:send',
    'mautic:campaigns:messages',
    'mautic:campaigns:messages --channel=email',
    'mautic:campaigns:messages --channel=sms',
    'mautic:queue:process',
    'mautic:webhooks:process',
    'mautic:reports:scheduler',
    'mautic:plugins:update',
    'mautic:iplookup:download',
    'mautic:assets:generate',
    'mautic:segments:update --force',
    'mautic:campaigns:update --force',
    'mautic:campaigns:trigger --force',
    'mautic:segments:update --max-contacts=300 --batch-limit=300',
    'mautic:segments:update --max-contacts=300 --batch-limit=300 --quiet',
    'mautic:segments:update --max-contacts=300 --batch-limit=300 --force',
    'mautic:segments:update --max-contacts=1000 --batch-limit=1000',
    'mautic:segments:update --max-contacts=1000 --batch-limit=1000 --quiet',
    'mautic:campaigns:update --max-contacts=100 --quiet',
    'mautic:campaigns:update --max-contacts=300 --quiet',
    'mautic:campaigns:trigger --quiet',
    'cache:clear --no-interaction --no-warmup --no-optional-warmers',
    'cache:warmup --no-interaction --no-optional-warmers',
    'mautic:social:monitoring',
    'mautic:integration:pushleadactivity --integration=XXX',
    'mautic:integration:fetchleads --integration=XXX',
    'mautic:import --limit=600',
    'mautic:import --limit=600 --quiet',
    'mautic:dnc:import --limit=600',
    'mautic:dnc:import --limit=600 --quiet',
    'mautic:maintenance:cleanup --no-interaction --days-old=90 --dry-run',
    'mautic:maintenance:cleanup --no-interaction --days-old=365 --dry-run',
    'mautic:maintenance:cleanup --no-interaction --days-old=90',
    'mautic:maintenance:cleanup --no-interaction --days-old=365',
    'doctrine:migrations:status',
    'doctrine:migrations:status --show-versions',
    'doctrine:migrations:migrate --allow-no-migration --dry-run',
    'doctrine:migrations:migrate --allow-no-migration --no-interaction',
    'doctrine:migrations:migrate --allow-no-migration --query-time --dry-run',
    'doctrine:migrations:migrate --allow-no-migration --query-time --no-interaction',
    'doctrine:schema:update',
    'doctrine:schema:update --dump-sql',
    'doctrine:schema:validate',
    'doctrine:schema:update --no-interaction --dump-sql --force',
    'doctrine:schema:update --no-interaction --force',
    'debug:swiftmailer',
    'debug:router',
    'doctrine:mapping:info',
    'debug:event-dispatcher',
    'mautic:install:data --no-interaction --force',
    'mautic:contacts:deduplicate',
    'mautic:unusedip:delete',
    'mautic:dashboard:warm',
    'mautic:campaign:summarize',
    'mautic:update:find',
    'mautic:update:apply --no-interaction --force',
);

Cron jobs πŸ•–

  1. πŸ”Ž Find the URL encoded link to a command

    https://mautic.example.com/commands.php?mautibot_happy&task=mautic%3Acampaigns%3Atrigger
  2. 🌐 Request the URL

    # min hr dom mth dow  command
    */15  *  *   *   *    curl -L http://mautic.example.com/commands.php?mautibot_happy&task=mautic%3Acampaigns%3Atrigger

    πŸ’‘ ProTip
    curl can also use this syntax:
    curl -L 'http://mautic.example.com/commands.php?mautibot_happy&task=mautic:campaigns:trigger'

πŸ”° Basic output

The output from the script will be sent to the browser so you can see the results just as if you ran this console command from the shell.

Executing console mautic:campaigns:trigger
 Triggering events for campaign 1
 Triggering events for newly added contacts
 2 total events(s) to be processed in batches of 100 contacts
  0/2 [>---------------------------]   0%
  2/2 [============================] 100%
 2 total events were executed
 0 total events were scheduled

 Triggering scheduled events
 0 total events(s) to be processed in batches of 100 contacts

 0 total events were executed
 0 total events were scheduled

 Triggering events for inactive contacts

 0 total events were executed
 0 total events were scheduled

πŸ’ Pretty output

pretty format campaign trigger

pretty format migrations status

Mautic logo

Mautic documentation πŸ“œ

ℹ️ NOTE
Access the complete Mautic documentation here.

mautibot

Related projects ⛅️

Changelog πŸ“”

See CHANGELOG