forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteBackupService.php
More file actions
70 lines (62 loc) · 2.26 KB
/
DeleteBackupService.php
File metadata and controls
70 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Pterodactyl\Services\Backups;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DeleteBackupService
{
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
*/
private $daemonBackupRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* DeleteBackupService constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $daemonBackupRepository
*/
public function __construct(
ConnectionInterface $connection,
BackupRepository $repository,
DaemonBackupRepository $daemonBackupRepository
) {
$this->repository = $repository;
$this->daemonBackupRepository = $daemonBackupRepository;
$this->connection = $connection;
}
/**
* Deletes a backup from the system.
*
* @param \Pterodactyl\Models\Backup $backup
* @throws \Throwable
*/
public function handle(Backup $backup)
{
$this->connection->transaction(function () use ($backup) {
try {
$this->daemonBackupRepository->setServer($backup->server)->delete($backup);
} catch (DaemonConnectionException $exception) {
$previous = $exception->getPrevious();
// Don't fail the request if the Daemon responds with a 404, just assume the backup
// doesn't actually exist and remove it's reference from the Panel as well.
if (! $previous instanceof ClientException || $previous->getResponse()->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exception;
}
}
$this->repository->delete($backup->id);
});
}
}