forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEggRepository.php
More file actions
86 lines (77 loc) · 2.64 KB
/
EggRepository.php
File metadata and controls
86 lines (77 loc) · 2.64 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Egg;
use Webmozart\Assert\Assert;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class EggRepository extends EloquentRepository implements EggRepositoryInterface
{
/**
* Return the model backing this repository.
*/
public function model(): string
{
return Egg::class;
}
/**
* Return an egg with the variables relation attached.
*
* @throws RecordNotFoundException
*/
public function getWithVariables(int $id): Egg
{
try {
return $this->getBuilder()->with('variables')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException) {
throw new RecordNotFoundException();
}
}
/**
* Return all eggs and their relations to be used in the daemon API.
*/
public function getAllWithCopyAttributes(): Collection
{
return $this->getBuilder()->with('scriptFrom', 'configFrom')->get($this->getColumns());
}
/**
* Return an egg with the scriptFrom and configFrom relations loaded onto the model.
*
* @param int|string $value
*
* @throws RecordNotFoundException
*/
public function getWithCopyAttributes($value, string $column = 'id'): Egg
{
Assert::true(is_digit($value) || is_string($value), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');
try {
return $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->firstOrFail($this->getColumns());
} catch (ModelNotFoundException) {
throw new RecordNotFoundException();
}
}
/**
* Return all the data needed to export a service.
*
* @throws RecordNotFoundException
*/
public function getWithExportAttributes(int $id): Egg
{
try {
return $this->getBuilder()->with('scriptFrom', 'configFrom', 'variables')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException) {
throw new RecordNotFoundException();
}
}
/**
* Confirm a copy script belongs to the same nest as the item trying to use it.
*/
public function isCopyableScript(int $copyFromId, int $service): bool
{
return $this->getBuilder()->whereNull('copy_script_from')
->where('id', '=', $copyFromId)
->where('nest_id', '=', $service)
->exists();
}
}