# ConsoleEvent events

> 3 FeatherPanel plugin events on ConsoleEvent (1 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/console/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 2 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `ConsoleEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ConsoleEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ConsoleEvent::onCommandExecuted(), function ($command, $workingDirectory, $returnCode, $executionTime, $executedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:console:command:executed ' . json_encode(['command' => $command]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ConsoleEvent::onCommandExecuted()`

- Name: `featherpanel:admin:console:command:executed`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ConsoleEvent.php#L28)

Docblock: string command, array execution data. (the emitter passes 5 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `command` | `$command` | `string` |
| 2 | `working_directory` | `$workingDirectory` | not declared |
| 3 | `return_code` | `$returnCode` | not declared |
| 4 | `execution_time` | `$executionTime` | not declared |
| 5 | `executed_by` | `$executedBy` | not declared |

When it fires (1 site)

-   [`ConsoleController::executeCommand`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/ConsoleController.php#L167)[`POST /api/admin/console/execute`](https://featherpanel.com/docs/api/reference/admin/console/#post-admin-console-execute)

```php
$event->on(ConsoleEvent::onCommandExecuted(), function ($command, $workingDirectory, $returnCode, $executionTime, $executedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:console:command:executed ' . json_encode(['command' => $command]));
});
```

## `ConsoleEvent::onConsoleError()`

- Name: `featherpanel:admin:console:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ConsoleEvent.php#L45)

Docblock: string error message, array context.

```php
$event->on(ConsoleEvent::onConsoleError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:console:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ConsoleEvent::onSystemInfoRetrieved()`

- Name: `featherpanel:admin:console:system_info:retrieved`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ConsoleEvent.php#L36)

Docblock: array system info.

```php
$event->on(ConsoleEvent::onSystemInfoRetrieved(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:console:system_info:retrieved ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.
