coolify/app/Actions/RemoteProcess/DispatchRemoteProcess.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2023-03-20 13:04:22 +01:00
<?php
namespace App\Actions\RemoteProcess;
2023-03-20 13:04:22 +01:00
use App\Data\RemoteProcessArgs;
use App\Jobs\ExecuteRemoteProcess;
use Spatie\Activitylog\Models\Activity;
2023-03-20 13:04:22 +01:00
class DispatchRemoteProcess
2023-03-20 13:04:22 +01:00
{
protected Activity $activity;
public function __construct(RemoteProcessArgs $remoteProcessArgs)
{
if ($remoteProcessArgs->model) {
$properties = $remoteProcessArgs->toArray();
unset($properties['model']);
$this->activity = activity()
->withProperties($properties)
->performedOn($remoteProcessArgs->model)
2023-03-30 09:47:04 +02:00
->event($remoteProcessArgs->type)
->log("");
} else {
$this->activity = activity()
->withProperties($remoteProcessArgs->toArray())
2023-03-30 09:47:04 +02:00
->event($remoteProcessArgs->type)
->log("");
}
2023-03-20 13:04:22 +01:00
}
public function __invoke(): Activity
2023-03-20 13:04:22 +01:00
{
$job = new ExecuteRemoteProcess($this->activity);
2023-03-20 13:04:22 +01:00
dispatch($job);
$this->activity->refresh();
2023-03-20 13:04:22 +01:00
return $this->activity;
}
}