2015-12-24 42 views
0

我需要終端的所有服務Symfony的終端FOS彈性填入

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. 

回答

0

另一個選項可以使用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(); 
    } 

    /.../ 
} 
0

我解決

 $options = array('command' => 'fos:elastica:populate', "--no-reset" => true, "--index" => 'profile', "--type" => 'team'); 
     $upload = $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));