2020-04-17 17:21:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
|
|
|
|
|
2020-08-21 04:07:53 +00:00
|
|
|
use Carbon\CarbonImmutable;
|
2020-04-17 17:21:51 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
2020-08-28 02:35:22 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
2020-04-17 17:21:51 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
|
|
|
|
|
|
|
|
class BackupStatusController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BackupStatusController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
|
|
|
|
*/
|
|
|
|
public function __construct(BackupRepository $repository)
|
|
|
|
{
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles updating the state of a backup.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request
|
|
|
|
* @param string $backup
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-08-28 02:35:22 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2020-04-17 17:21:51 +00:00
|
|
|
*/
|
|
|
|
public function __invoke(ReportBackupCompleteRequest $request, string $backup)
|
|
|
|
{
|
2020-08-28 02:35:22 +00:00
|
|
|
/** @var \Pterodactyl\Models\Backup $model */
|
|
|
|
$model = $this->repository->findFirstWhere([[ 'uuid', '=', $backup ]]);
|
|
|
|
|
2020-10-31 23:44:20 +00:00
|
|
|
if (! is_null($model->completed_at)) {
|
2020-08-28 02:35:22 +00:00
|
|
|
throw new BadRequestHttpException(
|
|
|
|
'Cannot update the status of a backup that is already marked as completed.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-28 02:59:01 +00:00
|
|
|
$successful = $request->input('successful') ? true : false;
|
|
|
|
$model->forceFill([
|
|
|
|
'is_successful' => $successful,
|
|
|
|
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
|
|
|
|
'bytes' => $successful ? $request->input('size') : 0,
|
2020-08-21 04:07:53 +00:00
|
|
|
'completed_at' => CarbonImmutable::now(),
|
2020-08-28 02:59:01 +00:00
|
|
|
])->save();
|
2020-04-17 17:21:51 +00:00
|
|
|
|
2020-08-21 04:07:53 +00:00
|
|
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
2020-04-17 17:21:51 +00:00
|
|
|
}
|
|
|
|
}
|