Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change output buffer for Artisan::call #16763

Closed
Muffinman opened this issue Dec 12, 2016 · 2 comments
Closed

Unable to change output buffer for Artisan::call #16763

Muffinman opened this issue Dec 12, 2016 · 2 comments

Comments

@Muffinman
Copy link
Contributor

Muffinman commented Dec 12, 2016

  • Laravel Version: 5.3.26
  • PHP Version: 5.6.27
  • Database Driver & Version: MariaDB 10.1.11

Description:

When using Artisan::call() it's not possible to capture the output of any sub-commands in the same output buffer. This has become a problem because we have a long-running index task and we'd like to know the progress as you would see by calling php artisan scout:index manually.

See the brief example below:

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Artisan;

class CreateScoutIndex extends Command
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'scoutindex:create';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Creates the scout ElasticSearch Index';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        /**
         * 1. Create the ElasticSearch index here with our own custom Analysers, field types etc.
         */

        /**
         * 2. Call the scout import command, we want to know the progress right?
         *     Except that isn't possible because the command has to completely finish before returning
         *     the output.
         */
        Artisan::call('scout:import', [ 'model' => 'App\\SomeModel' ]);
        $this->line(Artisan::output());

        /**
         * 3. Any other logic here; alias rotation, cleanup etc.
         */  
    }
}

A couple of things I've tried:

// call doesn't accept a third parameter even though this turns up in Google a lot - perhaps this used to work with an older version of Laravel.
Artisan::call('scout:import', [ 'model' => 'App\\SomeModel' ], $this->getOutput());
// This almost works, but it's dangerous to re-use the same instance and causes further issues if you call multiple at the same time:
$this->call('scout:import', [ 'model' => 'App\\SomeModel' ]);
$this->call('scout:import', [ 'model' => 'App\\SomeOtherModel' ]);  // This seems to mess up scout's progress counts

Are there any known work-arounds for this? Everything else I've seen suggests creating a new OutputBuffer instance, but this would have the same effect as my example class, where the output only shows after command completion.

Steps To Reproduce:

See above class.

@taylorotwell
Copy link
Member

I think we would just need to add a third parameter to pass an output buffer to the Foundation\Console\Kernel@call method, which would then pass it to the Console\Application@call method. /cc @themsaid

@themsaid
Copy link
Member

@Muffinman had to submit that to 5.4 since adding function arguments is considered a breaking change: #16930

Closing this issue and moving the discussion to the PR, however feel free to ping me if you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants