View .md

ServerAllocationEvent events

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

Last synced from FeatherPanel 15b94e9 on .

On this page

Part of the plugin events reference. 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 ServerAllocationEvent in your entry class and register listeners in processEvents():

<?php

namespace App\Addons\myplugin;

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerAllocationEvent::onServerAllocationDeleted(), function ($userUuid, $serverUuid, $allocationId): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:allocation:deleted ' . json_encode(['allocation_id' => $allocationId]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}

ServerAllocationEvent::onServerAllocationDeleted()

Name: featherpanel:user:server:allocation:deletedemitted at 2 sitesCancel or modify: nodefinition

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

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

#Payload keyListener parameterType
1user_uuid$userUuidnot declared
2server_uuid$serverUuidnot declared
3allocation_id$allocationIdint
When it fires (2 sites)
$event->on(ServerAllocationEvent::onServerAllocationDeleted(), function ($userUuid, $serverUuid, $allocationId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:allocation:deleted ' . json_encode(['allocation_id' => $allocationId]));
});

ServerAllocationEvent::onServerAllocationError()

Name: featherpanel:user:server:allocation:errornot emittedCancel or modify: nodefinition

Docblock: string error message, array context.

$event->on(ServerAllocationEvent::onServerAllocationError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:allocation:error ' . json_encode($args));
});

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

ServerAllocationEvent::onServerAllocationSetPrimary()

Name: featherpanel:user:server:allocation:set_primaryemitted at 2 sites2 payload shapesCancel or modify: nodefinition

Docblock: string server uuid, int allocation id, bool is_primary.

#Payload keyListener parameterType
1user_uuid$userUuidstringfrom docblock
2server_uuid$serverUuidintfrom docblock
3allocation_id$allocationIdint
Arguments passedEmitted from
user_uuid, server_uuid, allocation_id
ServerAllocationController::setPrimaryAllocation
user_uuid, server_uuid, allocation_id, is_primary
SetPrimaryAllocationTool::execute
When it fires (2 sites)
$event->on(ServerAllocationEvent::onServerAllocationSetPrimary(), function ($userUuid, $serverUuid, $allocationId, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:allocation:set_primary ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'allocation_id' => $allocationId]));
});