From 952715faccc004a2b5ab2382a0726d9540be4920 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 27 Dec 2020 11:34:55 -0800 Subject: [PATCH] Fix handling of upload IDs on backups --- .../Api/Remote/Backups/BackupRemoteUploadController.php | 7 +++---- app/Models/Backup.php | 7 ++++++- ..._12_26_184914_add_upload_id_column_to_backups_table.php | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php b/app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php index f8a758c1e..e89783b76 100644 --- a/app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php +++ b/app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php @@ -10,6 +10,7 @@ use League\Flysystem\AwsS3v3\AwsS3Adapter; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Extensions\Backups\BackupManager; use Pterodactyl\Repositories\Eloquent\BackupRepository; +use Symfony\Component\HttpKernel\Exception\ConflictHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; class BackupRemoteUploadController extends Controller @@ -64,7 +65,7 @@ class BackupRemoteUploadController extends Controller // Prevent backups that have already been completed from trying to // be uploaded again. if (! is_null($backup->completed_at)) { - return new JsonResponse([], JsonResponse::HTTP_CONFLICT); + throw new ConflictHttpException('This backup is already in a completed state.'); } // Ensure we are using the S3 adapter. @@ -103,9 +104,7 @@ class BackupRemoteUploadController extends Controller } // Set the upload_id on the backup in the database. - $backup->forceFill([ - 'upload_id' => $params['UploadId'], - ])->saveOrFail(); + $backup->update(['upload_id' => $params['UploadId']]); return new JsonResponse([ 'parts' => $parts, diff --git a/app/Models/Backup.php b/app/Models/Backup.php index 5f784ba64..6569d9f30 100644 --- a/app/Models/Backup.php +++ b/app/Models/Backup.php @@ -68,6 +68,11 @@ class Backup extends Model 'upload_id' => null, ]; + /** + * @var string[] + */ + protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at']; + /** * @var array */ @@ -80,7 +85,7 @@ class Backup extends Model 'disk' => 'required|string', 'checksum' => 'nullable|string', 'bytes' => 'numeric', - 'upload_id' => 'nullable|uuid', + 'upload_id' => 'nullable|string', ]; /** diff --git a/database/migrations/2020_12_26_184914_add_upload_id_column_to_backups_table.php b/database/migrations/2020_12_26_184914_add_upload_id_column_to_backups_table.php index 989670f50..2e1c50556 100644 --- a/database/migrations/2020_12_26_184914_add_upload_id_column_to_backups_table.php +++ b/database/migrations/2020_12_26_184914_add_upload_id_column_to_backups_table.php @@ -14,7 +14,7 @@ class AddUploadIdColumnToBackupsTable extends Migration public function up() { Schema::table('backups', function (Blueprint $table) { - $table->char('upload_id', 36)->nullable()->after('bytes'); + $table->text('upload_id')->nullable()->after('uuid'); }); }