lasthourcloud/app/Actions/RemoteProcess/DispatchRemoteProcess.php

41 lines
1.1 KiB
PHP
Raw Normal View History

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