# DatabaseSnapshotsEvent events

> 4 FeatherPanel plugin events on DatabaseSnapshotsEvent (4 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-snapshots/

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.

## Setup

Import `DatabaseSnapshotsEvent` 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\DatabaseSnapshotsEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(DatabaseSnapshotsEvent::onSnapshotCreated(), function ($filename, $size, $userUuid): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:database:snapshot:created ' . json_encode(['filename' => $filename, 'size' => $size, 'user_uuid' => $userUuid]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `DatabaseSnapshotsEvent::onSnapshotCreated()`

- Name: `featherpanel:database:snapshot:created`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/DatabaseSnapshotsEvent.php#L27)

Docblock: string filename, int size, string user uuid.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `filename` | `$filename` | `string` |
| 2 | `size` | `$size` | `int`from docblock |
| 3 | `user_uuid` | `$userUuid` | `string`from docblock |

When it fires (1 site)

-   [`DatabaseSnapshotsController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/DatabaseSnapshotsController.php#L242)[`POST /api/admin/database-snapshots`](https://featherpanel.com/docs/api/reference/admin/database-snapshots/#post-admin-database-snapshots)

```php
$event->on(DatabaseSnapshotsEvent::onSnapshotCreated(), function ($filename, $size, $userUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:database:snapshot:created ' . json_encode(['filename' => $filename, 'size' => $size, 'user_uuid' => $userUuid]));
});
```

## `DatabaseSnapshotsEvent::onSnapshotDeleted()`

- Name: `featherpanel:database:snapshot:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/DatabaseSnapshotsEvent.php#L43)

Docblock: string filename, string user uuid.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `filename` | `$filename` | `string` |
| 2 | `user_uuid` | `$userUuid` | `string`from docblock |

When it fires (1 site)

-   [`DatabaseSnapshotsController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/DatabaseSnapshotsController.php#L585)[`DELETE /api/admin/database-snapshots/{filename}`](https://featherpanel.com/docs/api/reference/admin/database-snapshots/#delete-admin-database-snapshots-filename)

```php
$event->on(DatabaseSnapshotsEvent::onSnapshotDeleted(), function ($filename, $userUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:database:snapshot:deleted ' . json_encode(['filename' => $filename, 'user_uuid' => $userUuid]));
});
```

## `DatabaseSnapshotsEvent::onSnapshotDownloaded()`

- Name: `featherpanel:database:snapshot:downloaded`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/DatabaseSnapshotsEvent.php#L51)

Docblock: string filename, string user uuid.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `filename` | `$filename` | `string` |
| 2 | `user_uuid` | `$userUuid` | `string`from docblock |

When it fires (1 site)

-   [`DatabaseSnapshotsController::download`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/DatabaseSnapshotsController.php#L339)[`GET /api/admin/database-snapshots/{filename}/download`](https://featherpanel.com/docs/api/reference/admin/database-snapshots/#get-admin-database-snapshots-filename-download)

```php
$event->on(DatabaseSnapshotsEvent::onSnapshotDownloaded(), function ($filename, $userUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:database:snapshot:downloaded ' . json_encode(['filename' => $filename, 'user_uuid' => $userUuid]));
});
```

## `DatabaseSnapshotsEvent::onSnapshotRestored()`

- Name: `featherpanel:database:snapshot:restored`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/DatabaseSnapshotsEvent.php#L35)

Docblock: string filename, string user uuid.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `filename` | `$filename` | `string` |
| 2 | `user_uuid` | `$userUuid` | `string`from docblock |

When it fires (1 site)

-   [`DatabaseSnapshotsController::restore`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/DatabaseSnapshotsController.php#L476)[`POST /api/admin/database-snapshots/{filename}/restore`](https://featherpanel.com/docs/api/reference/admin/database-snapshots/#post-admin-database-snapshots-filename-restore)

```php
$event->on(DatabaseSnapshotsEvent::onSnapshotRestored(), function ($filename, $userUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:database:snapshot:restored ' . json_encode(['filename' => $filename, 'user_uuid' => $userUuid]));
});
```
