Skip to content

Commit 3c48947

Browse files
committed
Fix known issues from the upgrade guide
1 parent 0dcf2aa commit 3c48947

File tree

11 files changed

+71
-88
lines changed

11 files changed

+71
-88
lines changed

app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Console\Commands\Maintenance;
114

125
use Carbon\Carbon;
136
use Illuminate\Console\Command;
7+
use Symfony\Component\Finder\SplFileInfo;
148
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
159

1610
class CleanServiceBackupFilesCommand extends Command
1711
{
1812
const BACKUP_THRESHOLD_MINUTES = 5;
1913

20-
/**
21-
* @var \Carbon\Carbon
22-
*/
23-
protected $carbon;
24-
2514
/**
2615
* @var string
2716
*/
@@ -40,14 +29,12 @@ class CleanServiceBackupFilesCommand extends Command
4029
/**
4130
* CleanServiceBackupFilesCommand constructor.
4231
*
43-
* @param \Carbon\Carbon $carbon
4432
* @param \Illuminate\Contracts\Filesystem\Factory $filesystem
4533
*/
46-
public function __construct(Carbon $carbon, FilesystemFactory $filesystem)
34+
public function __construct(FilesystemFactory $filesystem)
4735
{
4836
parent::__construct();
4937

50-
$this->carbon = $carbon;
5138
$this->disk = $filesystem->disk();
5239
}
5340

@@ -58,11 +45,11 @@ public function handle()
5845
{
5946
$files = $this->disk->files('services/.bak');
6047

61-
collect($files)->each(function ($file) {
62-
$lastModified = $this->carbon->timestamp($this->disk->lastModified($file));
63-
if ($lastModified->diffInMinutes($this->carbon->now()) > self::BACKUP_THRESHOLD_MINUTES) {
64-
$this->disk->delete($file);
65-
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file]));
48+
collect($files)->each(function (SplFileInfo $file) {
49+
$lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath()));
50+
if ($lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) {
51+
$this->disk->delete($file->getPath());
52+
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()]));
6653
}
6754
});
6855
}

app/Http/Controllers/Admin/PackController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function newTemplate()
163163
*/
164164
public function store(PackFormRequest $request)
165165
{
166-
if ($request->has('from_template')) {
166+
if ($request->filled('from_template')) {
167167
$pack = $this->templateUploadService->handle($request->input('egg_id'), $request->file('file_upload'));
168168
} else {
169169
$pack = $this->creationService->handle($request->normalize(), $request->file('file_upload'));

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public function updateBuild(Request $request, Server $server)
524524
*/
525525
public function delete(Request $request, Server $server)
526526
{
527-
$this->deletionService->withForce($request->has('force_delete'))->handle($server);
527+
$this->deletionService->withForce($request->filled('force_delete'))->handle($server);
528528
$this->alert->success(trans('admin/server.alerts.server_deleted'))->flash();
529529

530530
return redirect()->route('admin.servers');

app/Http/Controllers/Auth/LoginController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function __construct(
107107
*
108108
* @param \Illuminate\Http\Request $request
109109
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
110+
*
111+
* @throws \Illuminate\Validation\ValidationException
110112
*/
111113
public function login(Request $request)
112114
{
@@ -115,8 +117,7 @@ public function login(Request $request)
115117

116118
if ($this->hasTooManyLoginAttempts($request)) {
117119
$this->fireLockoutEvent($request);
118-
119-
return $this->sendLockoutResponse($request);
120+
$this->sendLockoutResponse($request);
120121
}
121122

122123
try {

app/Http/Middleware/VerifyReCaptcha.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle($request, Closure $next)
3939
return $next($request);
4040
}
4141

42-
if ($request->has('g-recaptcha-response')) {
42+
if ($request->filled('g-recaptcha-response')) {
4343
$client = new Client();
4444
$res = $client->post($this->config->get('recaptcha.domain'), [
4545
'form_params' => [

app/Http/Requests/Admin/DatabaseHostFormRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DatabaseHostFormRequest extends AdminFormRequest
1818
*/
1919
public function rules()
2020
{
21-
if (! $this->has('node_id')) {
21+
if (! $this->filled('node_id')) {
2222
$this->merge(['node_id' => null]);
2323
}
2424

app/Models/Pack.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
namespace Pterodactyl\Models;
1111

12-
use File;
13-
use Storage;
1412
use Sofa\Eloquence\Eloquence;
1513
use Sofa\Eloquence\Validable;
1614
use Illuminate\Database\Eloquent\Model;
@@ -88,30 +86,6 @@ class Pack extends Model implements CleansAttributes, ValidableContract
8886
'version' => 2,
8987
];
9088

91-
/**
92-
* Returns all of the archived files for a given pack.
93-
*
94-
* @param bool $collection
95-
* @return \Illuminate\Support\Collection|object
96-
* @deprecated
97-
*/
98-
public function files($collection = false)
99-
{
100-
$files = collect(Storage::files('packs/' . $this->uuid));
101-
102-
$files = $files->map(function ($item) {
103-
$path = storage_path('app/' . $item);
104-
105-
return (object) [
106-
'name' => basename($item),
107-
'hash' => sha1_file($path),
108-
'size' => File::humanReadableSize($path),
109-
];
110-
});
111-
112-
return ($collection) ? $files : (object) $files->all();
113-
}
114-
11589
/**
11690
* Gets egg associated with a service pack.
11791
*

app/Policies/ServerPolicy.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ public function before(User $user, $ability, Server $server)
5151

5252
return $this->checkPermission($user, $server, $ability);
5353
}
54+
55+
/**
56+
* This is a horrendous hack to avoid Laravel's "smart" behavior that does
57+
* not call the before() function if there isn't a function matching the
58+
* policy permission.
59+
*
60+
* @param string $name
61+
* @param mixed $arguments
62+
*/
63+
public function __call($name, $arguments)
64+
{
65+
// do nothing
66+
}
5467
}

app/Providers/SettingsServiceProvider.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ public function boot(ConfigRepository $config, Encrypter $encrypter, SettingsRep
8787
}
8888
}
8989

90+
switch (strtolower($value)) {
91+
case 'true':
92+
case '(true)':
93+
$value = true;
94+
break;
95+
case 'false':
96+
case '(false)':
97+
$value = false;
98+
break;
99+
case 'empty':
100+
case '(empty)':
101+
$value = '';
102+
break;
103+
case 'null':
104+
case '(null)':
105+
$value = null;
106+
}
107+
90108
$config->set(str_replace(':', '.', $key), $value);
91109
}
92110
}

resources/themes/pterodactyl/admin/packs/view.blade.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@
113113
<th>SHA1 Hash</th>
114114
<th>File Size</th>
115115
</tr>
116-
@foreach($pack->files() as $file)
117-
<tr>
118-
<td>{{ $file->name }}</td>
119-
<td><code>{{ $file->hash }}</code></td>
120-
<td>{{ $file->size }}</td>
121-
</tr>
122-
@endforeach
123116
</table>
124117
</div>
125118
<div class="box-footer">

0 commit comments

Comments
 (0)