php - 从 PHP 文件运行 CLI 命令
问题描述
我正在尝试解决以下问题
在我的网站上 - 托管在共享主机帐户 (PHP 7.0) 上 - 我安装了一个名为 MAUTIC 的电子邮件自动化软件
此应用程序需要 CLI 命令才能正常运行/纠正系统故障
有时可能需要在 Mautic 中使用命令行。可以使用以下 CLI 命令。
该应用程序的路径是:https ://www.mywebsite.com/contacts/ 在该目录中需要执行以下命令
缓存:清除缓存:热身--env=prod mautic:段:更新学说:模式:更新--dump-sql 学说:模式:更新--force
我想使用 URL https://www.mywebsite.com/repair-correct.php运行代码
我希望有经验的 PHP 编码器可以帮助我处理以下不起作用的代码,不幸的是 - 我不知道代码有什么问题?
非常感谢你的帮助!
最好的,托尼
<?php
if (!isset($_GET['ILoveMauticReallyIDo'])) {
echo 'The secret phrase is wrong.';
die;
}
$link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$allowedTasks = array(
'cache:clear',
'cache:clear --no-warmup',
'mautic:install:data',
'mautic:campaigns:trigger',
'mautic:campaigns:rebuild',
'mautic:social:monitoring',
'mautic:iplookup:download',
'mautic:emails:send',
'mautic:email:fetch',
'mautic:messages:send',
'mautic:integration:fetchleads -i Salesforce',
'mautic:integration:fetchleads --integration=Hubspot',
'mautic:segments:update',
'doctrine:migration:status',
'doctrine:migrations:migrate',
'doctrine:schema:update --dump-sql',
'doctrine:schema:update --force',
'mautic:maintenance:cleanup --days-old=365 --dry-run',
'mautic:update:find',
'mautic:update:apply'
);
if (!isset($_GET['task'])) {
echo '<html><head></head><body style="font-family: Open Sans, Helvetica, Arial, sans-serif;">';
echo '<p>Specify what task to run. You can run these:';
echo '<ul>';
foreach ($allowedTasks as $task) {
$href = $link . '&task=' . urlencode($task);
echo '<li><a href="' . $href . '">' . $task . '</a></li>';
}
echo '</ul><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></p>';
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 '<html><head></head><body style="font-family: Open Sans, Helvetica, Arial, sans-serif;">';
echo '<h3>Executing ' . implode(' ', $args) . '</h3>';
require_once __DIR__.'/app/autoload.php';
// require_once __DIR__.'/app/bootstrap.php.cache';
require_once __DIR__.'/app/AppKernel.php';
require __DIR__.'/vendor/autoload.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>';
} catch (\Exception $exception) {
echo $exception->getMessage();
}
?>
解决方案
推荐阅读
- asp.net-mvc - EF Code First:在 Code First 生成后未在 NOT NULL int 列中添加“必需”
- regex - Find lines with numbers
- ironpython - 如何根据 Spotfire 中列的数据类型使用 IronPython 脚本设置过滤器类型/属性
- html - 我正在 div 元素上实现选择/取消选择。我可以一次单击选择 div,但无法在下次单击同一个 div 时取消选择它?
- amazon-s3 - AWS S3 上传在 nativescript 上失败
- angular - 如何使用href Angular 6将变量绑定到url参数?
- c# - 如何统一使用集合数据结构?
- sql - 如何编写查询以从一个表中选择最接近但小于另一个表中的日期的日期
- datepicker - 如何通过单击按钮打开引导日期选择器?
- c++ - vkCmdClearColorImage 无法清除布局为