0

我需要在服务中运行命令

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.  
4

2 回答 2

0

我解决了

        $options = array('command' => 'fos:elastica:populate', "--no-reset" => true, "--index" => 'profile', "--type" => 'team');
        $upload = $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
于 2015-12-24T14:02:42.773 回答
0

另一种选择可能是使用ProcessComponent 来启动特定命令:

// .../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();
    }

    /.../
}
于 2015-12-24T13:48:42.157 回答