Skip to content

Instantly share code, notes, and snippets.

@alanhartless

alanhartless/cron.php

Forked from escopecz/commands.php
Last active Jul 11, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@ninjoan 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
You can’t perform that action at this time.