public function runAction($route, $params = [])
{
// In addition to the default behavior of runAction, the console command
// will strip the first element of the route and threat it as a module
// changed the controller namespace to run the commands
if (!empty($route)) {
$partial = explode("/", $route);
// if there is a first key in the splitted array
if (isset($partial[0]) && count($partial) > 1 && ($module = Yii::$app->getModule($partial[0]))) {
try {
// change the controller namespace of this module to make usage of `commands`.
$module->controllerNamespace = $module->namespace . '\\commands';
unset($partial[0]);
// action response
return $module->runAction(implode("/", $partial), $params);
} catch (\Exception $e) {
throw new Exception("Exception in route \"{$route}\": \"{$e->getMessage()}\" in file \"{$e->getFile()}\" on line {$e->getLine()}.", 0, $e);
}
}
}
// call parent action
return parent::runAction($route, $params);
}