lasthourcloud/app/Actions/CoolifyTask/PrepareCoolifyTask.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2023-03-20 12:04:22 +00:00
<?php
2023-05-03 05:15:45 +00:00
namespace App\Actions\CoolifyTask;
2023-03-20 12:04:22 +00:00
2023-05-03 05:15:45 +00:00
use App\Data\CoolifyTaskArgs;
use App\Jobs\HandleCoolifyTaskInQueue;
use Spatie\Activitylog\Models\Activity;
2023-03-20 12:04:22 +00:00
2023-05-03 05:15:45 +00:00
class PrepareCoolifyTask
2023-03-20 12:04:22 +00:00
{
protected Activity $activity;
2023-05-03 05:15:45 +00:00
public function __construct(CoolifyTaskArgs $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-04-07 14:58:45 +00:00
->log("[]");
} else {
$this->activity = activity()
->withProperties($remoteProcessArgs->toArray())
2023-03-30 07:47:04 +00:00
->event($remoteProcessArgs->type)
2023-04-07 14:58:45 +00:00
->log("[]");
}
2023-03-20 12:04:22 +00:00
}
public function __invoke(): Activity
2023-03-20 12:04:22 +00:00
{
2023-05-03 05:15:45 +00:00
$job = new HandleCoolifyTaskInQueue($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;
}
}