我需要在服务中运行命令
app/console fos:elastica:populate --no-reset --index=profile --type=team
通过终端所有工作正常,但我需要运行服务
$application = new 'Symfony'Bundle'FrameworkBundle'Console'Application($this->kernel);
$application->setAutoExit(false);
//Upload in Elastic
$options = array('command' => 'fos:elastica:populate', "--no-reset" => true, "--index=profile" => true, "--type=team" => true);
$upload = $application->run(new 'Symfony'Component'Console'Input'ArrayInput($options));
有错误:
[InvalidArgumentException]
The "--index=profile" option does not exist.
另一个选项可以是使用Process
组件来启动特定命令:
// .../Service/YourService.php
use Symfony'Component'Process'Process;
class YourService
{
/.../
public function launchPopulateCommand()
{
$process = new Process('php app/console fos:elastica:populate --no-reset --index=profile --type=team');
$process->run();
}
/.../
}
我解决了
$options = array('command' => 'fos:elastica:populate', "--no-reset" => true, "--index" => 'profile', "--type" => 'team');
$upload = $application->run(new 'Symfony'Component'Console'Input'ArrayInput($options));