Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/EggRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Egg;
6
use Webmozart\Assert\Assert;
7
use Illuminate\Database\Eloquent\Collection;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
10
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
11
12
class EggRepository extends EloquentRepository implements EggRepositoryInterface
13
{
14
/**
15
* Return the model backing this repository.
16
*/
17
public function model(): string
18
{
19
return Egg::class;
20
}
21
22
/**
23
* Return an egg with the variables relation attached.
24
*
25
* @throws RecordNotFoundException
26
*/
27
public function getWithVariables(int $id): Egg
28
{
29
try {
30
return $this->getBuilder()->with('variables')->findOrFail($id, $this->getColumns());
31
} catch (ModelNotFoundException) {
32
throw new RecordNotFoundException();
33
}
34
}
35
36
/**
37
* Return all eggs and their relations to be used in the daemon API.
38
*/
39
public function getAllWithCopyAttributes(): Collection
40
{
41
return $this->getBuilder()->with('scriptFrom', 'configFrom')->get($this->getColumns());
42
}
43
44
/**
45
* Return an egg with the scriptFrom and configFrom relations loaded onto the model.
46
*
47
* @param int|string $value
48
*
49
* @throws RecordNotFoundException
50
*/
51
public function getWithCopyAttributes($value, string $column = 'id'): Egg
52
{
53
Assert::true(is_digit($value) || is_string($value), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');
54
55
try {
56
return $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->firstOrFail($this->getColumns());
57
} catch (ModelNotFoundException) {
58
throw new RecordNotFoundException();
59
}
60
}
61
62
/**
63
* Return all the data needed to export a service.
64
*
65
* @throws RecordNotFoundException
66
*/
67
public function getWithExportAttributes(int $id): Egg
68
{
69
try {
70
return $this->getBuilder()->with('scriptFrom', 'configFrom', 'variables')->findOrFail($id, $this->getColumns());
71
} catch (ModelNotFoundException) {
72
throw new RecordNotFoundException();
73
}
74
}
75
76
/**
77
* Confirm a copy script belongs to the same nest as the item trying to use it.
78
*/
79
public function isCopyableScript(int $copyFromId, int $service): bool
80
{
81
return $this->getBuilder()->whereNull('copy_script_from')
82
->where('id', '=', $copyFromId)
83
->where('nest_id', '=', $service)
84
->exists();
85
}
86
}
87
88