# ServerFilesEvent events

> 7 FeatherPanel plugin events on ServerFilesEvent (6 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/server-files/

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. 1 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerFilesEvent::onServerFileSaved(), function ($userUuid, $serverUuid, $filePath): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:file:saved ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'file_path' => $filePath]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `ServerFilesEvent::onServerDirectoryCreated()`

- Name: `featherpanel:user:server:directory:created`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L36)

Docblock: string server uuid, string directory path. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerDirectoryCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `directory_path` | `$directoryPath` | not declared |

When it fires (2 sites)

-   [`ServerFilesController::createDirectory`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L1406)[`POST /api/user/servers/{uuidShort}/create-directory`](https://featherpanel.com/docs/api/reference/user/server/files/#post-user-servers-uuidShort-create-directory)
-   [`CreateDirectoryTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/CreateDirectoryTool.php#L157)

```php
$event->on(ServerFilesEvent::onServerDirectoryCreated(), function ($userUuid, $serverUuid, $directoryPath): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:directory:created');
});
```

## `ServerFilesEvent::onServerFileRenamed()`

- Name: `featherpanel:user:server:file:renamed`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L52)

Docblock: string server uuid, string file path. (the emitter passes 4 values, see the table)

Same event name as `ServerEvent::onServerFileRenamed()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `root` | `$root`not at every site | not declared |
| 4 | `files` | `$files`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `server_uuid`, `root`, `files` | 
`ServerFilesController::renameFileOrFolder`

 |
| `user_uuid`, `server_uuid`, `file_path`, `new_path` | 

`RenameFileTool::execute`

 |

When it fires (2 sites)

-   [`ServerFilesController::renameFileOrFolder`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L807)[`PUT /api/user/servers/{uuidShort}/rename`](https://featherpanel.com/docs/api/reference/user/server/files/#put-user-servers-uuidShort-rename)
-   [`RenameFileTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/RenameFileTool.php#L174)

```php
$event->on(ServerFilesEvent::onServerFileRenamed(), function ($userUuid, $serverUuid, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:file:renamed');
});
```

## `ServerFilesEvent::onServerFileSaved()`

- Name: `featherpanel:user:server:file:saved`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L44)

Docblock: string server uuid, string file path, int size.

Same event name as `ServerEvent::onServerFileWritten()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `string`from docblock |
| 3 | `file_path` | `$filePath` | `int`from docblock |

When it fires (2 sites)

-   [`ServerFilesController::writeFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L722)[`POST /api/user/servers/{uuidShort}/write-file`](https://featherpanel.com/docs/api/reference/user/server/files/#post-user-servers-uuidShort-write-file)
-   [`WriteFileTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/WriteFileTool.php#L173)

```php
$event->on(ServerFilesEvent::onServerFileSaved(), function ($userUuid, $serverUuid, $filePath): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:file:saved ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'file_path' => $filePath]));
});
```

## `ServerFilesEvent::onServerFileUploaded()`

- Name: `featherpanel:user:server:file:uploaded`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L60)

Docblock: string server uuid, array file data. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerFileUploaded()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `file_path` | `$filePath` | not declared |

When it fires (1 site)

-   [`ServerFilesController::uploadFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L2523)[`POST /api/user/servers/{uuidShort}/upload-file`](https://featherpanel.com/docs/api/reference/user/server/files/#post-user-servers-uuidShort-upload-file)

```php
$event->on(ServerFilesEvent::onServerFileUploaded(), function ($userUuid, $serverUuid, $filePath): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:file:uploaded');
});
```

## `ServerFilesEvent::onServerFilesDeleted()`

- Name: `featherpanel:user:server:files:deleted`
- emitted at 3 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L28)

Docblock: string server uuid, array files deleted.

Same event name as `ServerEvent::onServerFilesDeleted()`. A listener on either method receives the emits of both.

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

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `server_uuid` | 
`ServerFilesController::deleteFiles`

`ServerFilesController::wipeAllFiles`

 |
| `user_uuid`, `server_uuid`, `files` | 

`DeleteFilesTool::execute`

 |

When it fires (3 sites)

-   [`ServerFilesController::deleteFiles`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L902)[`DELETE /api/user/servers/{uuidShort}/delete-files`](https://featherpanel.com/docs/api/reference/user/server/files/#delete-user-servers-uuidShort-delete-files)
-   [`ServerFilesController::wipeAllFiles`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L1174)[`POST /api/user/servers/{uuidShort}/wipe-all-files`](https://featherpanel.com/docs/api/reference/user/server/files/#post-user-servers-uuidShort-wipe-all-files)
-   [`DeleteFilesTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/DeleteFilesTool.php#L174)

```php
$event->on(ServerFilesEvent::onServerFilesDeleted(), function ($userUuid, $serverUuid, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:files:deleted ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid]));
});
```

## `ServerFilesEvent::onServerFilesError()`

- Name: `featherpanel:user:server:files:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L77)

Docblock: string error message, array context.

```php
$event->on(ServerFilesEvent::onServerFilesError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:files:error ' . json_encode($args));
});
```

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

## `ServerFilesEvent::onServerPullProcessDeleted()`

- Name: `featherpanel:user:server:pull:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerFilesEvent.php#L68)

Docblock: string server uuid, string pull id. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerPullProcessDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `pull_id` | `$pullId` | `string` |

When it fires (1 site)

-   [`ServerFilesController::deletePullProcess`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/Files/ServerFilesController.php#L2127)[`DELETE /api/user/servers/{uuidShort}/delete-pull-process/{pullId}`](https://featherpanel.com/docs/api/reference/user/server/files/#delete-user-servers-uuidShort-delete-pull-process-pullId)

```php
$event->on(ServerFilesEvent::onServerPullProcessDeleted(), function ($userUuid, $serverUuid, $pullId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:pull:deleted ' . json_encode(['pull_id' => $pullId]));
});
```
