mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
@ -27,8 +27,7 @@ public function link(DatabaseUser $databaseUser, array $input): void
|
||||
->whereIn('name', $input['databases'])
|
||||
->count();
|
||||
if (count($input['databases']) !== $dbs) {
|
||||
throw ValidationException::withMessages(['databases' => __('Databases not found!')])
|
||||
->errorBag('linkUser');
|
||||
throw ValidationException::withMessages(['databases' => __('Databases not found!')]);
|
||||
}
|
||||
|
||||
$databaseUser->databases = $input['databases'];
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
class RunBackup
|
||||
{
|
||||
public function run(Backup $backup): void
|
||||
public function run(Backup $backup): BackupFile
|
||||
{
|
||||
$file = new BackupFile([
|
||||
'backup_id' => $backup->id,
|
||||
@ -26,5 +26,7 @@ public function run(Backup $backup): void
|
||||
$file->status = BackupFileStatus::FAILED;
|
||||
$file->save();
|
||||
})->onConnection('ssh');
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Actions\Queue;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Models\Queue;
|
||||
|
||||
class ManageQueue
|
||||
@ -14,10 +13,7 @@ public function start(Queue $queue): void
|
||||
$queue->save();
|
||||
dispatch(function () use ($queue) {
|
||||
$queue->server->processManager()->handler()->start($queue->id, $queue->site_id);
|
||||
$queue->status = ServiceStatus::READY;
|
||||
$queue->save();
|
||||
})->catch(function () use ($queue) {
|
||||
$queue->status = ServiceStatus::FAILED;
|
||||
$queue->status = QueueStatus::RUNNING;
|
||||
$queue->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
@ -28,10 +24,7 @@ public function stop(Queue $queue): void
|
||||
$queue->save();
|
||||
dispatch(function () use ($queue) {
|
||||
$queue->server->processManager()->handler()->stop($queue->id, $queue->site_id);
|
||||
$queue->status = ServiceStatus::STOPPED;
|
||||
$queue->save();
|
||||
})->catch(function () use ($queue) {
|
||||
$queue->status = ServiceStatus::FAILED;
|
||||
$queue->status = QueueStatus::STOPPED;
|
||||
$queue->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
@ -42,10 +35,7 @@ public function restart(Queue $queue): void
|
||||
$queue->save();
|
||||
dispatch(function () use ($queue) {
|
||||
$queue->server->processManager()->handler()->restart($queue->id, $queue->site_id);
|
||||
$queue->status = ServiceStatus::READY;
|
||||
$queue->save();
|
||||
})->catch(function () use ($queue) {
|
||||
$queue->status = ServiceStatus::FAILED;
|
||||
$queue->status = QueueStatus::RUNNING;
|
||||
$queue->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Script;
|
||||
|
||||
use App\Models\Script;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateScript
|
||||
{
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function handle(User $creator, array $input): Script
|
||||
{
|
||||
$this->validateInputs($input);
|
||||
|
||||
$script = new Script([
|
||||
'user_id' => $creator->id,
|
||||
'name' => $input['name'],
|
||||
'content' => $input['content'],
|
||||
]);
|
||||
$script->save();
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validateInputs(array $input): void
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'content' => 'required',
|
||||
];
|
||||
|
||||
Validator::make($input, $rules)->validateWithBag('createScript');
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Script;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class GetScripts
|
||||
{
|
||||
public function handle(User $user): LengthAwarePaginator
|
||||
{
|
||||
return $user->scripts()
|
||||
->orderBy('id', 'desc')
|
||||
->paginate(6)
|
||||
->onEachSide(1);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Script;
|
||||
|
||||
use App\Models\Script;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class UpdateScript
|
||||
{
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function handle(Script $script, array $input): Script
|
||||
{
|
||||
$this->validateInputs($input);
|
||||
|
||||
$script->name = $input['name'];
|
||||
$script->content = $input['content'];
|
||||
$script->save();
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validateInputs(array $input): void
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'content' => 'required',
|
||||
];
|
||||
|
||||
Validator::make($input, $rules)->validateWithBag('updateScript');
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class GetServers
|
||||
{
|
||||
public function handle(): Collection
|
||||
{
|
||||
return Server::query()->latest()->get();
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ public function create(User $user, array $input): ServerProvider
|
||||
} catch (Exception) {
|
||||
throw ValidationException::withMessages([
|
||||
'provider' => [
|
||||
__("Couldn't connect to provider. Please check your credentials and try again later."),
|
||||
sprintf("Couldn't connect to %s. Please check your credentials.", $input['provider']),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
21
app/Actions/ServerProvider/DeleteServerProvider.php
Normal file
21
app/Actions/ServerProvider/DeleteServerProvider.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\ServerProvider;
|
||||
|
||||
use App\Models\ServerProvider;
|
||||
use Exception;
|
||||
|
||||
class DeleteServerProvider
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete(ServerProvider $serverProvider): void
|
||||
{
|
||||
if ($serverProvider->servers()->exists()) {
|
||||
throw new Exception('This server provider is being used by a server.');
|
||||
}
|
||||
|
||||
$serverProvider->delete();
|
||||
}
|
||||
}
|
@ -19,9 +19,6 @@ public function start(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->catch(function () use ($service) {
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
|
||||
@ -37,9 +34,6 @@ public function stop(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->catch(function () use ($service) {
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
|
||||
@ -55,9 +49,6 @@ public function restart(Service $service): void
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
}
|
||||
$service->save();
|
||||
})->catch(function () use ($service) {
|
||||
$service->status = ServiceStatus::FAILED;
|
||||
$service->save();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
}
|
||||
|
17
app/Actions/SourceControl/DeleteSourceControl.php
Normal file
17
app/Actions/SourceControl/DeleteSourceControl.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\SourceControl;
|
||||
|
||||
use App\Models\SourceControl;
|
||||
|
||||
class DeleteSourceControl
|
||||
{
|
||||
public function delete(SourceControl $sourceControl): void
|
||||
{
|
||||
if ($sourceControl->sites()->exists()) {
|
||||
throw new \Exception('This source control is being used by a site.');
|
||||
}
|
||||
|
||||
$sourceControl->delete();
|
||||
}
|
||||
}
|
21
app/Actions/StorageProvider/DeleteStorageProvider.php
Normal file
21
app/Actions/StorageProvider/DeleteStorageProvider.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\StorageProvider;
|
||||
|
||||
use App\Models\StorageProvider;
|
||||
use Exception;
|
||||
|
||||
class DeleteStorageProvider
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete(StorageProvider $storageProvider): void
|
||||
{
|
||||
if ($storageProvider->backups()->exists()) {
|
||||
throw new Exception('This storage provider is being used by a backup.');
|
||||
}
|
||||
|
||||
$storageProvider->delete();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user