mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
- 2.x - scripts
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@ -18,6 +19,9 @@
|
||||
* @property Carbon $updated_at
|
||||
* @property Collection<ScriptExecution> $executions
|
||||
* @property ?ScriptExecution $lastExecution
|
||||
* @property User $user
|
||||
* @property int $project_id
|
||||
* @property ?Project $project
|
||||
*/
|
||||
class Script extends AbstractModel
|
||||
{
|
||||
@ -27,6 +31,12 @@ class Script extends AbstractModel
|
||||
'user_id',
|
||||
'name',
|
||||
'content',
|
||||
'project_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'project_id' => 'int',
|
||||
];
|
||||
|
||||
public static function boot(): void
|
||||
@ -43,6 +53,11 @@ public function user(): BelongsTo
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function getVariables(): array
|
||||
{
|
||||
$variables = [];
|
||||
@ -63,4 +78,14 @@ public function lastExecution(): HasOne
|
||||
{
|
||||
return $this->hasOne(ScriptExecution::class)->latest();
|
||||
}
|
||||
|
||||
public static function getByProjectId(int $projectId, int $userId): Builder
|
||||
{
|
||||
return self::query()
|
||||
->where(function (Builder $query) use ($projectId, $userId) {
|
||||
$query->where('project_id', $projectId)
|
||||
->orWhere('user_id', $userId)
|
||||
->orWhereNull('project_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,16 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ScriptExecutionStatus;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $script_id
|
||||
* @property int $server_log_id
|
||||
* @property ?int $server_id
|
||||
* @property string $user
|
||||
* @property array $variables
|
||||
* @property string $status
|
||||
@ -18,13 +19,15 @@
|
||||
* @property Carbon $updated_at
|
||||
* @property Script $script
|
||||
* @property ?ServerLog $serverLog
|
||||
* @property ?Server $server
|
||||
*/
|
||||
class ScriptExecution extends Model
|
||||
class ScriptExecution extends AbstractModel
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'script_id',
|
||||
'server_id',
|
||||
'server_log_id',
|
||||
'user',
|
||||
'variables',
|
||||
@ -33,10 +36,17 @@ class ScriptExecution extends Model
|
||||
|
||||
protected $casts = [
|
||||
'script_id' => 'integer',
|
||||
'server_id' => 'integer',
|
||||
'server_log_id' => 'integer',
|
||||
'variables' => 'array',
|
||||
];
|
||||
|
||||
public static array $statusColors = [
|
||||
ScriptExecutionStatus::EXECUTING => 'warning',
|
||||
ScriptExecutionStatus::COMPLETED => 'success',
|
||||
ScriptExecutionStatus::FAILED => 'danger',
|
||||
];
|
||||
|
||||
public function script(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Script::class);
|
||||
@ -58,4 +68,22 @@ public function serverLog(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServerLog::class);
|
||||
}
|
||||
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function getServer(): ?Server
|
||||
{
|
||||
if ($this->server_id) {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
if ($this->server_log_id) {
|
||||
return $this->serverLog?->server;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* @property int $user_id
|
||||
@ -16,6 +17,7 @@
|
||||
class SshKey extends AbstractModel
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
|
Reference in New Issue
Block a user