mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
42
app/Jobs/Redirect/AddToServer.php
Normal file
42
app/Jobs/Redirect/AddToServer.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Redirect;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Redirect;
|
||||
|
||||
class AddToServer extends Job
|
||||
{
|
||||
protected Redirect $redirect;
|
||||
|
||||
public function __construct(Redirect $redirect)
|
||||
{
|
||||
$this->redirect = $redirect;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
/** @var array $redirects */
|
||||
$redirects = Redirect::query()->where('site_id', $this->redirect->site_id)->get();
|
||||
$this->redirect->site->server->webserver()->handler()->updateRedirects($this->redirect->site, $redirects);
|
||||
$this->redirect->status = 'ready';
|
||||
$this->redirect->save();
|
||||
event(
|
||||
new Broadcast('create-redirect-finished', [
|
||||
'redirect' => $this->redirect,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->redirect->status = 'failed';
|
||||
$this->redirect->delete();
|
||||
event(
|
||||
new Broadcast('create-redirect-failed', [
|
||||
'redirect' => $this->redirect,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
44
app/Jobs/Redirect/DeleteFromServer.php
Normal file
44
app/Jobs/Redirect/DeleteFromServer.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Redirect;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Redirect;
|
||||
|
||||
class DeleteFromServer extends Job
|
||||
{
|
||||
protected Redirect $redirect;
|
||||
|
||||
public function __construct(Redirect $redirect)
|
||||
{
|
||||
$this->redirect = $redirect;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
/** @var array $redirects */
|
||||
$redirects = Redirect::query()
|
||||
->where('site_id', $this->redirect->site_id)
|
||||
->where('id', '!=', $this->redirect->id)
|
||||
->get();
|
||||
$this->redirect->site->server->webserver()->handler()->updateRedirects($this->redirect->site, $redirects);
|
||||
$this->redirect->delete();
|
||||
event(
|
||||
new Broadcast('delete-redirect-finished', [
|
||||
'id' => $this->redirect->id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->redirect->status = 'failed';
|
||||
$this->redirect->save();
|
||||
event(
|
||||
new Broadcast('delete-redirect-failed', [
|
||||
'redirect' => $this->redirect,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user