diff --git a/app/Addons/AdvancedAdmin/Models/CommandDefinition.php b/app/Addons/AdvancedAdmin/Models/CommandDefinition.php new file mode 100644 index 0000000..d75713b --- /dev/null +++ b/app/Addons/AdvancedAdmin/Models/CommandDefinition.php @@ -0,0 +1,130 @@ + '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; + } +} diff --git a/app/Addons/AdvancedAdmin/Models/ConsolePlayerCache.php b/app/Addons/AdvancedAdmin/Models/ConsolePlayerCache.php new file mode 100644 index 0000000..ba080e6 --- /dev/null +++ b/app/Addons/AdvancedAdmin/Models/ConsolePlayerCache.php @@ -0,0 +1,25 @@ + 'integer', + 'last_seen_at' => 'datetime', + ]; +}