1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
14
|
|
|
* copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Pterodactyl\Models; |
26
|
|
|
|
27
|
|
|
use File; |
28
|
|
|
use Storage; |
29
|
|
|
use Illuminate\Database\Eloquent\Model; |
30
|
|
|
use Nicolaslopezj\Searchable\SearchableTrait; |
31
|
|
|
|
32
|
|
|
class Pack extends Model |
33
|
|
|
{ |
34
|
|
|
use SearchableTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The table associated with the model. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $table = 'packs'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Fields that are mass assignable. |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $fillable = [ |
49
|
|
|
'option_id', 'name', 'version', 'description', 'selectable', 'visible', 'locked', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Cast values to correct type. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $casts = [ |
58
|
|
|
'option_id' => 'integer', |
59
|
|
|
'selectable' => 'boolean', |
60
|
|
|
'visible' => 'boolean', |
61
|
|
|
'locked' => 'boolean', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Parameters for search querying. |
66
|
|
|
* |
67
|
|
|
* @var array |
68
|
|
|
*/ |
69
|
|
|
protected $searchable = [ |
70
|
|
|
'columns' => [ |
71
|
|
|
'packs.name' => 10, |
72
|
|
|
'packs.uuid' => 8, |
73
|
|
|
'service_options.name' => 6, |
74
|
|
|
'service_options.tag' => 5, |
75
|
|
|
'service_options.docker_image' => 5, |
76
|
|
|
'packs.version' => 2, |
77
|
|
|
], |
78
|
|
|
'joins' => [ |
79
|
|
|
'service_options' => ['packs.option_id', 'service_options.id'], |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns all of the archived files for a given pack. |
85
|
|
|
* |
86
|
|
|
* @param bool $collection |
87
|
|
|
* @return \Illuminate\Support\Collection|object |
88
|
|
|
*/ |
89
|
|
|
public function files($collection = false) |
90
|
|
|
{ |
91
|
|
|
$files = collect(Storage::files('packs/' . $this->uuid)); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$files = $files->map(function ($item) { |
94
|
|
|
$path = storage_path('app/' . $item); |
95
|
|
|
|
96
|
|
|
return (object) [ |
97
|
|
|
'name' => basename($item), |
98
|
|
|
'hash' => sha1_file($path), |
99
|
|
|
'size' => File::humanReadableSize($path), |
100
|
|
|
]; |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
return ($collection) ? $files : (object) $files->all(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Gets option associated with a service pack. |
108
|
|
|
* |
109
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
110
|
|
|
*/ |
111
|
|
|
public function option() |
112
|
|
|
{ |
113
|
|
|
return $this->belongsTo(ServiceOption::class); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Gets servers associated with a pack. |
118
|
|
|
* |
119
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
120
|
|
|
*/ |
121
|
|
|
public function servers() |
122
|
|
|
{ |
123
|
|
|
return $this->hasMany(Server::class); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.