-
-
Save ChgoChad/fe9950c628ad8169cd27a58ee64106e8 to your computer and use it in GitHub Desktop.
| <?php | |
| if (!isset($_GET['ILoveMautic'])) { | |
| echo 'The secret phrase is wrong.'; | |
| die; | |
| } | |
| $link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | |
| $allowedTasks = array( | |
| 'cache:clear', | |
| 'cache:clear --no-warmup', | |
| 'mautic:install:data', | |
| 'mautic:campaigns:trigger', | |
| 'mautic:campaigns:rebuild', | |
| 'mautic:social:monitoring', | |
| 'mautic:iplookup:download', | |
| 'mautic:emails:send', | |
| 'mautic:email:fetch', | |
| 'mautic:messages:send', | |
| 'mautic:integration:fetchleads -i Salesforce', | |
| 'mautic:integration:fetchleads --integration=Hubspot', | |
| 'mautic:segments:update', | |
| 'doctrine:migration:status', | |
| 'doctrine:migrations:migrate', | |
| 'doctrine:schema:update --dump-sql', | |
| 'doctrine:schema:update --force', | |
| 'mautic:maintenance:cleanup --days-old=365 --dry-run' | |
| ); | |
| if (!isset($_GET['task'])) { | |
| echo '<html><head></head><body style="font-family: Open Sans, Helvetica, Arial, sans-serif;">'; | |
| echo '<p>Specify what task to run. You can run these:'; | |
| echo '<ul>'; | |
| foreach ($allowedTasks as $task) { | |
| $href = $link . '&task=' . urlencode($task); | |
| echo '<li><a href="' . $href . '">' . $task . '</a></li>'; | |
| } | |
| echo '</ul><br/><a href="https://www.mautic.org/docs/setup/index.html">Read more</a>'; | |
| echo '<br/><b style="color:red">Please, backup your database before executing the doctrine commands!</b></p>'; | |
| die; | |
| } | |
| $task = urldecode($_GET['task']); | |
| if (!in_array($task, $allowedTasks)) { | |
| echo 'Task ' . $task . ' is not allowed.'; | |
| die; | |
| } | |
| $fullCommand = explode(' ', $task); | |
| $command = $fullCommand[0]; | |
| $argsCount = count($fullCommand) - 1; | |
| $args = array('console', $command); | |
| if ($argsCount) { | |
| for ($i = 1; $i <= $argsCount; $i++) { | |
| $args[] = $fullCommand[$i]; | |
| } | |
| } | |
| echo '<html><head></head><body style="font-family: Open Sans, Helvetica, Arial, sans-serif;">'; | |
| echo '<h3>Executing ' . implode(' ', $args) . '</h3>'; | |
| require_once __DIR__.'/app/autoload.php'; | |
| // require_once __DIR__.'/app/bootstrap.php.cache'; | |
| require_once __DIR__.'/app/AppKernel.php'; | |
| require __DIR__.'/vendor/autoload.php'; | |
| use Symfony\Bundle\FrameworkBundle\Console\Application; | |
| use Symfony\Component\Console\Input\ArgvInput; | |
| use Symfony\Component\Console\Output\BufferedOutput; | |
| defined('IN_MAUTIC_CONSOLE') or define('IN_MAUTIC_CONSOLE', 1); | |
| try { | |
| $input = new ArgvInput($args); | |
| $output = new BufferedOutput(); | |
| $kernel = new AppKernel('prod', false); | |
| $app = new Application($kernel); | |
| $app->setAutoExit(false); | |
| $result = $app->run($input, $output); | |
| echo "<pre>\n".$output->fetch().'</pre>'; | |
| } catch (\Exception $exception) { | |
| echo $exception->getMessage(); | |
| } |
Hi guys! I've just installed and tested here.... Working fine!
Installed in a shared Cpanel hosting.
Some tips:
- When you execute the script and it gives the commands list, after clicking on any command, youΒ΄ll get a urlencoded formatted link.
- Here, I gotta change to the original command on cron in some cases. Maybe thats because IΒ΄m using curl to call the command as example above:
*/5 * * * * * curl --request GET 'https://www.mymauticsite.com.br/crongen.php?mypassword&task=mautic:emails:send'
instead of
*/5 * * * * * curl --request GET 'https://www.mymauticsite.com.br/crongen.php?mypassword&task=mautic%3Aemails%3Asend'
as suggested originally.
Did this trick to all commands and works fine!
- Here, I gotta change to the original command on cron in some cases. Maybe thats because IΒ΄m using curl to call the command as example above:
- Remember to change the line 3 ILoveMautic GET password!
@ChgoChad, do You know how to execute webhooks? (mautic:webhooks:process)
I've tryed some changes on your script to execute it but it returns on cronjob email log:
Webhook Bundle is in immediate process mode. To use the command function change to command mode.
Hello guys,
I am new to Mautic. Can anyone help me please on how to use this code? I want to run Mautic on https. Please help.
mautic-cron-commands
I have an updated version of the script (https://github.com/virgilwashere/mautic-cron-commands) that supports Mautic 2.15.x
changes
- π¨
&prettyoutput mode - π add screenshots of
&prettyoutput - π document parameters
- β¨ add email and sms channels to
mautic:campaigns:messages - π add
--no-interactionto commands that need it - β¨ add commands from some popular plugins
- βοΈ fix
mautic:emais:fetch - π₯ removed duplicate commands
- πΈ moved the dangerous commands to the end of the list
- π οΈ HTML5 standards compliance
- π update documentation references
@ChgoChad not work in last version of mautic
page not found
page not found
@fredroo This is a .htaccess issue. You should add your commands.php file to the whitelist in the .htaccess file, line 113, like that:
Before:
# Except those whitelisted bellow.
<FilesMatch "^(index|index_dev|filemanager|upgrade)\.php$">
Require all granted
</FilesMatch>
After:
# Except those whitelisted bellow.
<FilesMatch "^(index|index_dev|filemanager|upgrade|commands)\.php$">
Require all granted
</FilesMatch>
Hello, is this still working in 4.4.x? I followed the steps and it shows me the command list. When I select clearing cache, it just stops there.
The browser just shows this.
"Executing console cache:clear"
Hello, is this still working in 4.4.x? I followed the steps and it shows me the command list. When I select clearing cache, it just stops there.
The browser just shows this. "Executing console cache:clear"
Yes working in 4.4.5
Hello, is this still working in 4.4.x? I followed the steps and it shows me the command list. When I select clearing cache, it just stops there.
The browser just shows this. "Executing console cache:clear"
I have the exact same issue. I have updated ownership, privileges, and htaccess for commands.php. i cannot execute commands like saidhasyim, no action

Hi,
I get some errors when running these
"Executing console mautic:campaigns:rebuild
Fatal error: Maximum execution time of 30 seconds exceeded in /home3/[accountname]/[mauticurl].com/m/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 104
Also cahe:clear similar errror,
Executing console cache:clear
Fatal error: Maximum execution time of 30 seconds exceeded in /home3/[accountname]/[mauticurl].com/m/vendor/symfony/translation/MessageCatalogue.php on line 136
but "cache:clear -- no warmup" works
Any ideas?
The following also seem to run without generating any errors.
campaigns:trigger
segments:update