Skip to content

Instantly share code, notes, and snippets.

@alanhartless
Forked from escopecz/commands.php
Last active July 11, 2016 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhartless/4b30ab2f2af847c3e7cd to your computer and use it in GitHub Desktop.
Save alanhartless/4b30ab2f2af847c3e7cd to your computer and use it in GitHub Desktop.
Script to run Symfony commands from web
<?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'
);
if (!isset($_GET['task'])) {
echo 'Specify what task to run. You can run these:';
foreach ($allowedTasks as $task) {
$href = $link . '&task=' . $task;
echo '<br><a href="' . $href . '">' . $href . '</a>';
}
echo '<br><a href="https://www.mautic.org/docs/setup/index.html">Read more</a>';
die;
}
if (!in_array($_GET['task'], $allowedTasks)) {
echo 'Task ' . $_GET['task'] . ' is not allowed.';
die;
}
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;
try {
$args = array('console', $_GET['task']);
$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();
}
@ninjoan
Copy link

ninjoan commented Jul 11, 2016

HI thanks for sharing im getting this error
Fatal error: Class 'Symfony\Component\Console\Input\ArgvInput' not found in /home/user/public_html/marketing/cron.php on line 37

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