mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
* feat: Implement Site Commands (#298) - Introduced a Commands widget/table for Site view, allowing users to create, edit, delete, and execute commands. - Each Site Type now has a predefined set of commands inserted upon site creation. - A migration script ensures commands are created for existing sites. - Implemented necessary policies for command management. - Added feature tests to validate functionality. * I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason. * I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason. * I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason. * I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason. * Remove feature tests for commands due to inconsistencies for now * fixes * add tests for commands * ui fix and add to wordpress --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
83
app/Models/CommandExecution.php
Normal file
83
app/Models/CommandExecution.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CommandExecutionStatus;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $command_id
|
||||
* @property int $server_id
|
||||
* @property int $user_id
|
||||
* @property ?int $server_log_id
|
||||
* @property array $variables
|
||||
* @property string $status
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property Command $command
|
||||
* @property ?ServerLog $serverLog
|
||||
* @property Server $server
|
||||
* @property ?User $user
|
||||
*/
|
||||
class CommandExecution extends AbstractModel
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'command_id',
|
||||
'server_id',
|
||||
'user_id',
|
||||
'server_log_id',
|
||||
'variables',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'command_id' => 'integer',
|
||||
'server_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'server_log_id' => 'integer',
|
||||
'variables' => 'array',
|
||||
];
|
||||
|
||||
public static array $statusColors = [
|
||||
CommandExecutionStatus::EXECUTING => 'warning',
|
||||
CommandExecutionStatus::COMPLETED => 'success',
|
||||
CommandExecutionStatus::FAILED => 'danger',
|
||||
];
|
||||
|
||||
public function command(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Command::class);
|
||||
}
|
||||
|
||||
public function getContent(): string
|
||||
{
|
||||
$content = $this->command->command;
|
||||
foreach ($this->variables as $variable => $value) {
|
||||
if (is_string($value) && ! empty($value)) {
|
||||
$content = str_replace('${'.$variable.'}', $value, $content);
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function serverLog(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServerLog::class);
|
||||
}
|
||||
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user