ControllerTrait

Type
Trait
Namespace
craft\console
Implemented by
craft\console\Controller, craft\console\controllers\BackupController, craft\console\controllers\BaseSystemStatusController, craft\console\controllers\ClearCachesController, craft\console\controllers\ClearDeprecationsController, craft\console\controllers\DbController, craft\console\controllers\ElementsController, craft\console\controllers\EntrifyController, craft\console\controllers\ExecController, craft\console\controllers\FixtureController, craft\console\controllers\GcController, craft\console\controllers\GraphqlController, craft\console\controllers\IndexAssetsController, craft\console\controllers\InstallController, craft\console\controllers\InvalidateTagsController, craft\console\controllers\MailerController, craft\console\controllers\MigrateController, craft\console\controllers\OffController, craft\console\controllers\OnController, craft\console\controllers\PluginController, craft\console\controllers\ProjectConfigController, craft\console\controllers\ResaveController, craft\console\controllers\RestoreController, craft\console\controllers\SectionsController, craft\console\controllers\ServeController, craft\console\controllers\SetupController, craft\console\controllers\TestsController, craft\console\controllers\UpController, craft\console\controllers\UpdateController, craft\console\controllers\UsersController, craft\console\controllers\utils\AsciiFilenamesController, craft\console\controllers\utils\FixElementUidsController, craft\console\controllers\utils\FixFieldLayoutUidsController, craft\console\controllers\utils\PruneOrphanedMatrixBlocksController, craft\console\controllers\utils\PruneProvisionalDraftsController, craft\console\controllers\utils\PruneRevisionsController, craft\console\controllers\utils\RepairController, craft\console\controllers\utils\UpdateUsernamesController, craft\queue\Command
Since
3.2.0

ConsoleControllerTrait implements the common methods and properties for console controllers.

View source (opens new window)

# Public Properties

Property Description
isolated – Whether the command should ensure it is only being run once at a time.

# isolated

Default value
false
Since
4.4.0

If this is passed and the same command is already being run in a separate shell/environment, the command will abort with an exit code of 1.

View source (opens new window)

# Public Methods

Method Description
beforeAction() This method is invoked right before an action is executed.
failure() Outputs a failure message to the console.
init() Initializes the object.
markdownToAnsi() Converts Markdown to be better readable in console environments by applying some ANSI format.
note() Outputs a note to the console.
options() Returns the names of valid options for the action (id).
runAction() Runs an action within this controller with the specified action ID and parameters.
success() Outputs a success message to the console.
tip() Outputs a tip to the console.
warning() Outputs a warning to the console.

# beforeAction()

Since
4.4.0

This method is invoked right before an action is executed.

See also yii\base\Controller::beforeAction() (opens new window) View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the action should continue to run.

# failure()

Since
4.4.0

Outputs a failure message to the console.

View source (opens new window)

Arguments

# init()

Since
4.4.0

Initializes the object.

See also yii\base\BaseObject::init() (opens new window) View source (opens new window)

# markdownToAnsi()

Since
4.4.0

Converts Markdown to be better readable in console environments by applying some ANSI format.

View source (opens new window)

Arguments

Returns

string (opens new window)

# note()

Since
4.4.0

Outputs a note to the console.

View source (opens new window)

Arguments

# options()

Since
4.4.0

Returns the names of valid options for the action (id).

See also yii\console\Controller::options() (opens new window) View source (opens new window)

Arguments

Returns

string (opens new window)[] – The names of the options valid for the action.

# runAction()

Since
4.4.0

Runs an action within this controller with the specified action ID and parameters.

Runs an action with the specified action ID and parameters. If the action ID is empty, the method will use \craft\console\defaultAction.

See also yii\console\Controller::runAction() (opens new window) View source (opens new window)

Arguments

Returns

integer (opens new window) – The status of the action execution. 0 means normal, other values mean abnormal.

Throws

# success()

Since
4.4.0

Outputs a success message to the console.

View source (opens new window)

Arguments

# tip()

Since
4.4.0

Outputs a tip to the console.

View source (opens new window)

Arguments

# warning()

Since
4.4.0

Outputs a warning to the console.

View source (opens new window)

Arguments

# Protected Methods

Method Description
checkRootUser() Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.
checkTty() Sets yii\console\Controller::$interactive (opens new window) to false if this isn’t a TTY shell.
createAttributeValidator() Creates a function for the validator option of Controller::prompt.
outputCommand()

# checkRootUser()

Since
3.7.0

Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.

View source (opens new window)

Returns

boolean (opens new window)

# checkTty()

Since
3.6.1

Sets yii\console\Controller::$interactive (opens new window) to false if this isn’t a TTY shell.

View source (opens new window)

# createAttributeValidator()

Since
3.7.0

Creates a function for the validator option of Controller::prompt.

View source (opens new window)

Arguments

Returns

callable (opens new window)

# outputCommand()

View source (opens new window)

Arguments