2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
2023-03-21 09:56:49 +00:00
|
|
|
namespace App\Actions\RemoteProcess;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-03-21 10:02:16 +00:00
|
|
|
use App\Data\RemoteProcessArgs;
|
2023-03-29 13:47:56 +00:00
|
|
|
use App\Jobs\DeployRemoteProcess;
|
2023-03-21 10:39:44 +00:00
|
|
|
use App\Jobs\ExecuteRemoteProcess;
|
2023-03-21 10:32:38 +00:00
|
|
|
use Spatie\Activitylog\Models\Activity;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-03-21 09:56:49 +00:00
|
|
|
class DispatchRemoteProcess
|
2023-03-20 12:04:22 +00:00
|
|
|
{
|
|
|
|
protected Activity $activity;
|
|
|
|
|
2023-03-29 10:27:02 +00:00
|
|
|
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 07:47:04 +00:00
|
|
|
->event($remoteProcessArgs->type)
|
2023-03-29 10:27:02 +00:00
|
|
|
->log("");
|
|
|
|
} else {
|
|
|
|
$this->activity = activity()
|
|
|
|
->withProperties($remoteProcessArgs->toArray())
|
2023-03-30 07:47:04 +00:00
|
|
|
->event($remoteProcessArgs->type)
|
2023-03-29 10:27:02 +00:00
|
|
|
->log("");
|
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 09:08:36 +00:00
|
|
|
public function __invoke(): Activity
|
2023-03-20 12:04:22 +00:00
|
|
|
{
|
2023-03-21 10:39:44 +00:00
|
|
|
$job = new ExecuteRemoteProcess($this->activity);
|
2023-03-20 12:04:22 +00:00
|
|
|
dispatch($job);
|
2023-03-21 09:31:16 +00:00
|
|
|
$this->activity->refresh();
|
2023-03-20 12:04:22 +00:00
|
|
|
return $this->activity;
|
|
|
|
}
|
|
|
|
}
|