Advertisement
Guest User

Cron Mautic

a guest
Jul 24th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2. if (!isset($_GET['chavesecreta'])) {
  3. echo 'The secret phrase is wrong.';
  4. die;
  5. }
  6.  
  7.  
  8. $link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  9. $allowedTasks = array(
  10. 'cache:clear',
  11. 'mautic:leadlists:update',
  12. 'mautic:campaigns:update',
  13. 'mautic:campaigns:trigger',
  14. 'mautic:email:process',
  15. 'mautic:fetch:email',
  16. 'doctrine:migrations:migrate',
  17. 'doctrine:schema:update --dump-sql',
  18. 'doctrine:schema:update --force'
  19. );
  20.  
  21.  
  22. if (!isset($_GET['task'])) {
  23. echo 'Specify what task to run. You can run these:';
  24. foreach ($allowedTasks as $task) {
  25. $href = $link . '&task=' . urlencode($task);
  26. echo '<br><a href="' . $href . '">' . $href . '</a>';
  27. }
  28. echo '<br><a href="https://www.mautic.org/docs/setup/index.html">Read more</a>';
  29. echo '<br><b style="color:red">Please, backup your database before executing the doctrine commands!</b>';
  30. die;
  31. }
  32. $task = urldecode($_GET['task']);
  33. if (!in_array($task, $allowedTasks)) {
  34. echo 'Task ' . $task . ' is not allowed.';
  35. die;
  36. }
  37. $fullCommand = explode(' ', $task);
  38. $command = $fullCommand[0];
  39. $argsCount = count($fullCommand) - 1;
  40. $args = array('console', $command);
  41. if ($argsCount) {
  42. for ($i = 1; $i <= $argsCount; $i++) {
  43. $args[] = $fullCommand[$i];
  44. }
  45. }
  46. echo '<h3>Executing ' . implode(' ', $args) . '</h3>';
  47. require_once __DIR__.'/app/bootstrap.php.cache';
  48. require_once __DIR__.'/app/AppKernel.php';
  49. use Symfony\Bundle\FrameworkBundle\Console\Application;
  50. use Symfony\Component\Console\Input\ArgvInput;
  51. use Symfony\Component\Console\Output\BufferedOutput;
  52. defined('IN_MAUTIC_CONSOLE') or define('IN_MAUTIC_CONSOLE', 1);
  53. try {
  54. $input = new ArgvInput($args);
  55. $output = new BufferedOutput();
  56. $kernel = new AppKernel('prod', false);
  57. $app = new Application($kernel);
  58. $app->setAutoExit(false);
  59. $result = $app->run($input, $output);
  60. echo "<pre>\n".$output->fetch().'</pre>';
  61.  
  62. $crontext = "Cron Run at ".date("r")." Retorno ".$output->fetch()."\n" ;
  63. $folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1);
  64. $filename = $folder."cron-test.txt" ;
  65. $fp = fopen($filename,"a") or die("Open error!");
  66. fwrite($fp, $crontext) or die("Write error!");
  67. fclose($fp);
  68.  
  69. } catch (\Exception $exception) {
  70. echo $exception->getMessage();
  71. $crontext = "Cron Run at ".date("r")." Erro ".$exception->getMessage()."\n" ;
  72. $folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1);
  73. $filename = $folder."cron-test.txt" ;
  74. $fp = fopen($filename,"a") or die("Open error!");
  75. fwrite($fp, $crontext) or die("Write error!");
  76. fclose($fp);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement