feat: implement missing CommandDefinition and ConsolePlayerCache Eloquent models

This commit is contained in:
2026-06-11 22:28:26 -05:00
parent 73a84d762f
commit acdb9fd9c2
2 changed files with 155 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
<?php
namespace Pterodactyl\Addons\AdvancedAdmin\Models;
use Illuminate\Database\Eloquent\Model;
class CommandDefinition extends Model
{
protected $table = 'addon_command_definitions';
protected $fillable = [
'server_id',
'node_id',
'egg_id',
'plugin_source',
'command_name',
'definition',
'is_active',
// Virtual/fillable fields for controller convenience
'command',
'description',
'syntax',
'dangerous',
'plugin',
];
protected $casts = [
'definition' => 'array',
'is_active' => 'boolean',
'dangerous' => 'boolean',
];
protected $appends = [
'command',
'description',
'syntax',
'dangerous',
'plugin',
];
protected static function booted()
{
// Add global scope to alias command_name as command for ordering
static::addGlobalScope('alias_command', function ($builder) {
$builder->select('addon_command_definitions.*')
->selectRaw('addon_command_definitions.command_name as command');
});
// Sync helper fields to database columns on saving
static::saving(function (CommandDefinition $model) {
if ($model->plugin) {
$model->plugin_source = $model->plugin;
}
if ($model->command) {
$model->command_name = $model->command;
}
$def = $model->definition ?? [];
$def['name'] = $model->command_name ?? $def['name'] ?? '';
$def['description'] = $model->description ?? $def['description'] ?? '';
$def['syntax'] = $model->syntax ?? $def['syntax'] ?? '';
$def['dangerous'] = (bool) ($model->dangerous ?? $def['dangerous'] ?? false);
$def['plugin'] = $model->plugin_source ?? $def['plugin'] ?? 'custom';
$def['args'] = $def['args'] ?? [];
$model->definition = $def;
});
}
// Accessors and Mutators for virtual fields
public function getCommandAttribute()
{
return $this->command_name;
}
public function setCommandAttribute($value)
{
$this->command_name = $value;
$this->attributes['command_name'] = $value;
}
public function getDescriptionAttribute()
{
return $this->definition['description'] ?? '';
}
public function setDescriptionAttribute($value)
{
$def = $this->definition ?? [];
$def['description'] = $value;
$this->definition = $def;
}
public function getSyntaxAttribute()
{
return $this->definition['syntax'] ?? '';
}
public function setSyntaxAttribute($value)
{
$def = $this->definition ?? [];
$def['syntax'] = $value;
$this->definition = $def;
}
public function getDangerousAttribute()
{
return (bool) ($this->definition['dangerous'] ?? false);
}
public function setDangerousAttribute($value)
{
$def = $this->definition ?? [];
$def['dangerous'] = (bool) $value;
$this->definition = $def;
}
public function getPluginAttribute()
{
return $this->plugin_source;
}
public function setPluginAttribute($value)
{
$this->plugin_source = $value;
$this->attributes['plugin_source'] = $value;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Pterodactyl\Addons\AdvancedAdmin\Models;
use Illuminate\Database\Eloquent\Model;
class ConsolePlayerCache extends Model
{
protected $table = 'addon_console_player_cache';
protected $primaryKey = null;
public $incrementing = false;
public $timestamps = false;
protected $fillable = [
'server_id',
'player_name',
'last_seen_at',
];
protected $casts = [
'server_id' => 'integer',
'last_seen_at' => 'datetime',
];
}