# BackupPolicyEvent events

> 5 FeatherPanel plugin events on BackupPolicyEvent (5 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/backup-policy/

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(BackupPolicyEvent::onBackupPolicyCreated(), function ($policy, $createdBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:created');
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `BackupPolicyEvent::onBackupPolicyCreated()`

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `policy` | `$policy` | not declared |
| 2 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

-   [`BackupSchedulesController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/BackupSchedulesController.php#L192)[`PUT /api/admin/backup-schedules`](https://featherpanel.com/docs/api/reference/admin/backup-schedules/#put-admin-backup-schedules)

```php
$event->on(BackupPolicyEvent::onBackupPolicyCreated(), function ($policy, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:created');
});
```

## `BackupPolicyEvent::onBackupPolicyDeleted()`

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `policy` | `$policy` | not declared |
| 2 | `deleted_by` | `$deletedBy` | not declared |

When it fires (1 site)

-   [`BackupSchedulesController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/BackupSchedulesController.php#L288)[`DELETE /api/admin/backup-schedules/{id}`](https://featherpanel.com/docs/api/reference/admin/backup-schedules/#delete-admin-backup-schedules-id)

```php
$event->on(BackupPolicyEvent::onBackupPolicyDeleted(), function ($policy, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:deleted');
});
```

## `BackupPolicyEvent::onBackupPolicyRunCompleted()`

- Name: `featherpanel:admin:backup_policy:run:completed`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/BackupPolicyEvent.php#L44)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `policy` | `$policy` | `array` |
| 2 | `result` | `$result` | not declared |
| 3 | `manual` | `$manual`not at every site | `bool` |

| Arguments passed | Emitted from |
| --- | --- |
| `policy`, `result`, `manual` | 
`BackupSchedulesController::runNow`

 |
| `policy`, `result` | 

`AAdminBackupPolicyProcessor::processPolicy`

 |

When it fires (2 sites)

-   [`BackupSchedulesController::runNow`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/BackupSchedulesController.php#L331)[`POST /api/admin/backup-schedules/{id}/run`](https://featherpanel.com/docs/api/reference/admin/backup-schedules/#post-admin-backup-schedules-id-run)
-   [`AAdminBackupPolicyProcessor::processPolicy`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/storage/cron/php/AAdminBackupPolicyProcessor.php#L103)

```php
$event->on(BackupPolicyEvent::onBackupPolicyRunCompleted(), function ($policy, $result, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:run:completed ' . json_encode(['policy' => $policy]));
});
```

## `BackupPolicyEvent::onBackupPolicyRunStarted()`

- Name: `featherpanel:admin:backup_policy:run:started`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/BackupPolicyEvent.php#L39)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `policy` | `$policy` | `array` |
| 2 | `manual` | `$manual`not at every site | `bool` |
| 3 | `triggered_by` | `$triggeredBy`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `policy`, `manual`, `triggered_by` | 
`BackupSchedulesController::runNow`

 |
| `policy` | 

`AAdminBackupPolicyProcessor::processPolicy`

 |

When it fires (2 sites)

-   [`BackupSchedulesController::runNow`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/BackupSchedulesController.php#L321)[`POST /api/admin/backup-schedules/{id}/run`](https://featherpanel.com/docs/api/reference/admin/backup-schedules/#post-admin-backup-schedules-id-run)
-   [`AAdminBackupPolicyProcessor::processPolicy`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/storage/cron/php/AAdminBackupPolicyProcessor.php#L95)

```php
$event->on(BackupPolicyEvent::onBackupPolicyRunStarted(), function ($policy, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:run:started ' . json_encode(['policy' => $policy]));
});
```

## `BackupPolicyEvent::onBackupPolicyUpdated()`

- Name: `featherpanel:admin:backup_policy:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/BackupPolicyEvent.php#L29)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `policy` | `$policy` | not declared |
| 2 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

-   [`BackupSchedulesController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/BackupSchedulesController.php#L251)[`PATCH /api/admin/backup-schedules/{id}`](https://featherpanel.com/docs/api/reference/admin/backup-schedules/#patch-admin-backup-schedules-id)

```php
$event->on(BackupPolicyEvent::onBackupPolicyUpdated(), function ($policy, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:backup_policy:updated');
});
```
