Script to run Mautic (Symfony) commands from a URL.

I follow the instruction provide by @escopecz but i get this error.

Code:
[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 48.

so i download the commands.php file from GitHub

and know i get this
Code:
[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 59.

I follow the instruction provide by @escopecz but i get this error.

[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 48.

so i download the commands.php file from GitHub

and know i get this

[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 59.

I think i fix it. Copy this Code and remember change ILoveMAUTIC

[quote]<?php

if (!isset($_GET['ILoveMAUTIC])) {
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 ‘
’ . $href . ‘’;
}
echo ‘
Read more’;
echo ‘
Please, backup your database before executing the doctrine commands!’;
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];
}
}

require_once DIR.’/app/bootstrap.php.cache’;
require_once DIR.’/app/AppKernel.php’;
use SymfonyBundleFrameworkBundleConsoleApplication;
use SymfonyComponentConsoleInputArgvInput;
use SymfonyComponentConsoleOutputBufferedOutput;

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 “

n”.$output->fetch().’
’;
} catch (Exception $exception) {
echo $exception->getMessage();
}
[/quote]

For the rest of the world, @ninjoan is talking about this script:

https://gist.github.com/escopecz/9a1a0b10861941a457f4

If I compared your version of the script correctly, you removed this row:

echo '<h3>Executing ' . implode(' ', $args) . '</h3>';

And it no longer throws this error:

[RuntimeException] Failed to start the session because headers have already been sent by "/home/MYDOMAIN/public_html/marketing/commands.php" at line 59.

If that’s correct, well great you’ve solved it. It doesn’t make much sense to me, but that’s not the first or the last wonder in PHP world for me :slight_smile:

1 Like

I hope this work for another user with problem like me.

Thanks @escopecz for be so patience.

Also there is any way to get in touch with David Hurley?