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:
71
app/Models/Command.php
Normal file
71
app/Models/Command.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $site_id
|
||||
* @property string $name
|
||||
* @property string $command
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property Collection<CommandExecution> $executions
|
||||
* @property ?CommandExecution $lastExecution
|
||||
* @property Site $site
|
||||
*/
|
||||
class Command extends AbstractModel
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'site_id',
|
||||
'name',
|
||||
'command',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'site_id' => 'integer',
|
||||
];
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function (Command $command) {
|
||||
$command->executions()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
public function getVariables(): array
|
||||
{
|
||||
$variables = [];
|
||||
preg_match_all('/\${(.*?)}/', $this->command, $matches);
|
||||
foreach ($matches[1] as $match) {
|
||||
$variables[] = $match;
|
||||
}
|
||||
|
||||
return array_unique($variables);
|
||||
}
|
||||
|
||||
public function executions(): HasMany
|
||||
{
|
||||
return $this->hasMany(CommandExecution::class);
|
||||
}
|
||||
|
||||
public function lastExecution(): HasOne
|
||||
{
|
||||
return $this->hasOne(CommandExecution::class)->latest();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user