Fix handling of upload IDs on backups

This commit is contained in:
Dane Everitt 2020-12-27 11:34:55 -08:00
parent 8e06628409
commit 952715facc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 10 additions and 6 deletions

View file

@ -10,6 +10,7 @@ use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Backups\BackupManager; use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Repositories\Eloquent\BackupRepository; use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class BackupRemoteUploadController extends Controller class BackupRemoteUploadController extends Controller
@ -64,7 +65,7 @@ class BackupRemoteUploadController extends Controller
// Prevent backups that have already been completed from trying to // Prevent backups that have already been completed from trying to
// be uploaded again. // be uploaded again.
if (! is_null($backup->completed_at)) { 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. // 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. // Set the upload_id on the backup in the database.
$backup->forceFill([ $backup->update(['upload_id' => $params['UploadId']]);
'upload_id' => $params['UploadId'],
])->saveOrFail();
return new JsonResponse([ return new JsonResponse([
'parts' => $parts, 'parts' => $parts,

View file

@ -68,6 +68,11 @@ class Backup extends Model
'upload_id' => null, 'upload_id' => null,
]; ];
/**
* @var string[]
*/
protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at'];
/** /**
* @var array * @var array
*/ */
@ -80,7 +85,7 @@ class Backup extends Model
'disk' => 'required|string', 'disk' => 'required|string',
'checksum' => 'nullable|string', 'checksum' => 'nullable|string',
'bytes' => 'numeric', 'bytes' => 'numeric',
'upload_id' => 'nullable|uuid', 'upload_id' => 'nullable|string',
]; ];
/** /**

View file

@ -14,7 +14,7 @@ class AddUploadIdColumnToBackupsTable extends Migration
public function up() public function up()
{ {
Schema::table('backups', function (Blueprint $table) { Schema::table('backups', function (Blueprint $table) {
$table->char('upload_id', 36)->nullable()->after('bytes'); $table->text('upload_id')->nullable()->after('uuid');
}); });
} }