lasthourcloud/app/Actions/RemoteProcess/DispatchRemoteProcess.php

39 lines
1010 B
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)
->log("");
} else {
$this->activity = activity()
->withProperties($remoteProcessArgs->toArray())
->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;
}
}