Skip to content

Commit 952715f

Browse files
committed
Fix handling of upload IDs on backups
1 parent 8e06628 commit 952715f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Pterodactyl\Http\Controllers\Controller;
1111
use Pterodactyl\Extensions\Backups\BackupManager;
1212
use Pterodactyl\Repositories\Eloquent\BackupRepository;
13+
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
1314
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1415

1516
class BackupRemoteUploadController extends Controller
@@ -64,7 +65,7 @@ public function __invoke(Request $request, string $backup)
6465
// Prevent backups that have already been completed from trying to
6566
// be uploaded again.
6667
if (! is_null($backup->completed_at)) {
67-
return new JsonResponse([], JsonResponse::HTTP_CONFLICT);
68+
throw new ConflictHttpException('This backup is already in a completed state.');
6869
}
6970

7071
// Ensure we are using the S3 adapter.
@@ -103,9 +104,7 @@ public function __invoke(Request $request, string $backup)
103104
}
104105

105106
// Set the upload_id on the backup in the database.
106-
$backup->forceFill([
107-
'upload_id' => $params['UploadId'],
108-
])->saveOrFail();
107+
$backup->update(['upload_id' => $params['UploadId']]);
109108

110109
return new JsonResponse([
111110
'parts' => $parts,

app/Models/Backup.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class Backup extends Model
6868
'upload_id' => null,
6969
];
7070

71+
/**
72+
* @var string[]
73+
*/
74+
protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at'];
75+
7176
/**
7277
* @var array
7378
*/
@@ -80,7 +85,7 @@ class Backup extends Model
8085
'disk' => 'required|string',
8186
'checksum' => 'nullable|string',
8287
'bytes' => 'numeric',
83-
'upload_id' => 'nullable|uuid',
88+
'upload_id' => 'nullable|string',
8489
];
8590

8691
/**

database/migrations/2020_12_26_184914_add_upload_id_column_to_backups_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AddUploadIdColumnToBackupsTable extends Migration
1414
public function up()
1515
{
1616
Schema::table('backups', function (Blueprint $table) {
17-
$table->char('upload_id', 36)->nullable()->after('bytes');
17+
$table->text('upload_id')->nullable()->after('uuid');
1818
});
1919
}
2020

0 commit comments

Comments
 (0)