Skip to content

Instantly share code, notes, and snippets.

@escopecz
Forked from alanhartless/cron.php
Last active April 18, 2023 22:43
Show Gist options
  • Star 42 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save escopecz/9a1a0b10861941a457f4 to your computer and use it in GitHub Desktop.
Save escopecz/9a1a0b10861941a457f4 to your computer and use it in GitHub Desktop.
Script to run Mautic (https://mautic.org) commands from a URL.
<?php
if (!isset($_GET['ILoveMauticReallyIDo'])) {
echo 'The secret phrase is wrong.';
die;
}
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$allowedTasks = array(
'cache:clear',
'mautic:leadlists:update',
'mautic:campaigns:update',
'mautic:campaigns:trigger',
'mautic:email:process',
'mautic:fetch:email',
'doctrine:migrations:migrate',
'doctrine:schema:update --dump-sql',
'doctrine:schema:update --force'
);
if (!isset($_GET['task'])) {
echo 'Specify what task to run. You can run these:';
foreach ($allowedTasks as $task) {
$href = $link . '&task=' . urlencode($task);
echo '<br><a href="' . $href . '">' . $href . '</a>';
}
echo '<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>';
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 '<h3>Executing ' . implode(' ', $args) . '</h3>';
require_once __DIR__.'/app/bootstrap.php.cache';
require_once __DIR__.'/app/AppKernel.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();
}
@Masho123
Copy link

Hello Brother and sisters

i am creating commands.php file but i access it thorogh my browser i receive this error
Untitled

Please help me to resolve this issue i have installed latest version of mautic and facing this error

Uh oh! I think I broke it. If I do it again, please report me to the system administrator!
500 Internal Server Error

mautic not give access to login to my administrator account and i receive this error

Let me know what to do to resolve this prompt

Best Regards
Muhammad Ashfaq

@dsp76
Copy link

dsp76 commented Apr 18, 2023

Hey Muhammad, please read the post above yours - but maybe you solved it meanwhile ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment