# DatabaseManagementEvent events

> 3 FeatherPanel plugin events on DatabaseManagementEvent (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/database-management/

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 `DatabaseManagementEvent` 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\DatabaseManagementEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(DatabaseManagementEvent::onMigrationsExecuted(), function ($executed, $skipped, $failed, $totalTime, $executedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:database_management:migrations:executed ' . json_encode(['executed' => $executed, 'skipped' => $skipped, 'failed' => $failed]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `DatabaseManagementEvent::onDatabaseManagementError()`

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

Docblock: string error message, array context.

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

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

## `DatabaseManagementEvent::onMigrationsExecuted()`

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

Docblock: array migration results. (the emitter passes 5 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `executed` | `$executed` | `int` |
| 2 | `skipped` | `$skipped` | `int` |
| 3 | `failed` | `$failed` | `int` |
| 4 | `total_time` | `$totalTime` | not declared |
| 5 | `executed_by` | `$executedBy` | not declared |

When it fires (1 site)

-   [`DatabaseManagmentController::migrate`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/DatabaseManagmentController.php#L241)[`POST /api/admin/databases/management/migrate`](https://featherpanel.com/docs/api/reference/admin/databases-management/#post-admin-databases-management-migrate)

```php
$event->on(DatabaseManagementEvent::onMigrationsExecuted(), function ($executed, $skipped, $failed, $totalTime, $executedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:database_management:migrations:executed ' . json_encode(['executed' => $executed, 'skipped' => $skipped, 'failed' => $failed]));
});
```

## `DatabaseManagementEvent::onStatusRetrieved()`

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

Docblock: array status data.

```php
$event->on(DatabaseManagementEvent::onStatusRetrieved(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:database_management:status:retrieved ' . json_encode($args));
});
```

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