0

CakePHP version 2.3.8

If I use public $tasks = array('Email'); and $this->Email->execute(); the output level i.e. Console/cake Test --verbose will use verbose output in the Email task. But if I load the task on the fly using TaskCollection object it will not. It only uses the default output level of NORMAL.

class TestShell extends AppShell {
    public function main() {
        $Email = $this->Tasks->load('Email');
        $Email->execute();
    }
}

class EmailTask extends Shell {
    public function execute() {
        $this->out('Some debugging output', 1, Shell::VERBOSE);
    }
}

How do I set up the TestShell to pass the output level to the EmailTask when it's loaded on the fly?


Update: I tried adding getOptionParser() to Shell and Task so I could use $this->params['verbose'] as per the Cookbook but I get error: Undefined index: verbose.

public function getOptionParser() {
    $parser = parent::getOptionParser();
    $parser->addOption('verbose', array(
        'help' => 'Enable verbose output.',
        'boolean' => true
    ));
    return $parser;
}

Update with sort of solution

I can pass the params manually to the Task like so:

public function main() {
    $Email = $this->Tasks->load('Email');
    $Email->params =& $this->params;
    $Email->execute();
}

But shouldn't TaskCollection do that for me?

Corie Slate
  • 616
  • 9
  • 19

1 Answers1

0

Did you register the verbose param in both the Shell and your Task? Using the consoleOptionParser? Then it should get passed down to it.

See https://github.com/cakephp/cakephp/blob/master/lib/Cake/Console/Command/Task/TestTask.php#L547

Also: Shouldn't your EmailTask extend the AppShell?

mark
  • 21,691
  • 3
  • 49
  • 71
  • I'm not using the consoleOptionParser. Could you provide an example? I implemented [addOption](http://book.cakephp.org/2.0/en/console-and-shells.html#using-boolean-options) from the Cookbook but that didn't work. Also, the Cookbook's Task example extends Shell. – Corie Slate Aug 09 '13 at 09:28
  • There are examples in the cake core - just check out the other shells and taks there. I guess the cookbook should be correcten then :) – mark Aug 09 '13 at 09:29