Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!isset($_GET['chavesecreta'])) {
- 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>';
- $crontext = "Cron Run at ".date("r")." Retorno ".$output->fetch()."\n" ;
- $folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1);
- $filename = $folder."cron-test.txt" ;
- $fp = fopen($filename,"a") or die("Open error!");
- fwrite($fp, $crontext) or die("Write error!");
- fclose($fp);
- } catch (\Exception $exception) {
- echo $exception->getMessage();
- $crontext = "Cron Run at ".date("r")." Erro ".$exception->getMessage()."\n" ;
- $folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1);
- $filename = $folder."cron-test.txt" ;
- $fp = fopen($filename,"a") or die("Open error!");
- fwrite($fp, $crontext) or die("Write error!");
- fclose($fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement