forked from Alex/Pterodactyl-Panel
Merge branch 'develop' into v2
This commit is contained in:
commit
4b32828423
@ -13,6 +13,7 @@ use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Pterodactyl\Services\Backups\DeleteBackupService;
|
||||
use Pterodactyl\Services\Backups\DownloadLinkService;
|
||||
use Pterodactyl\Services\Backups\InitiateBackupService;
|
||||
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
|
||||
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
@ -24,16 +25,18 @@ class BackupController extends ClientApiController
|
||||
private InitiateBackupService $initiateBackupService;
|
||||
private DeleteBackupService $deleteBackupService;
|
||||
private DownloadLinkService $downloadLinkService;
|
||||
private DaemonBackupRepository $repository;
|
||||
private DaemonBackupRepository $daemonRepository;
|
||||
private BackupRepository $repository;
|
||||
|
||||
/**
|
||||
* BackupController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
DaemonBackupRepository $repository,
|
||||
DaemonBackupRepository $daemonRepository,
|
||||
DeleteBackupService $deleteBackupService,
|
||||
InitiateBackupService $initiateBackupService,
|
||||
DownloadLinkService $downloadLinkService
|
||||
DownloadLinkService $downloadLinkService,
|
||||
BackupRepository $repository
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
@ -41,6 +44,7 @@ class BackupController extends ClientApiController
|
||||
$this->initiateBackupService = $initiateBackupService;
|
||||
$this->deleteBackupService = $deleteBackupService;
|
||||
$this->downloadLinkService = $downloadLinkService;
|
||||
$this->daemonRepository = $daemonRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +65,7 @@ class BackupController extends ClientApiController
|
||||
return $this->fractal->collection($server->backups()->paginate($limit))
|
||||
->transformWith($this->getTransformer(BackupTransformer::class))
|
||||
->addMeta([
|
||||
'used_backup_count' => $this->initiateBackupService->getNonFailedBackups($server)->count(),
|
||||
'backup_count' => $this->repository->getNonFailedBackups($server)->count(),
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
@ -69,6 +73,8 @@ class BackupController extends ClientApiController
|
||||
/**
|
||||
* Starts the backup process for a server.
|
||||
*
|
||||
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
|
||||
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function store(StoreBackupRequest $request, Server $server): array
|
||||
@ -128,7 +134,6 @@ class BackupController extends ClientApiController
|
||||
* Returns information about a single backup.
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(Request $request, Server $server, Backup $backup): array
|
||||
{
|
||||
@ -231,7 +236,7 @@ class BackupController extends ClientApiController
|
||||
// actions against it via the Panel API.
|
||||
$server->update(['status' => Server::STATUS_RESTORING_BACKUP]);
|
||||
|
||||
$this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate'));
|
||||
$this->daemonRepository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate'));
|
||||
});
|
||||
|
||||
return $this->returnNoContent();
|
||||
|
@ -4,6 +4,8 @@ namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class BackupRepository extends EloquentRepository
|
||||
{
|
||||
@ -33,4 +35,17 @@ class BackupRepository extends EloquentRepository
|
||||
->get()
|
||||
->toBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a query filtering only non-failed backups for a specific server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function getNonFailedBackups(Server $server): HasMany
|
||||
{
|
||||
return $server->backups()->where(function ($query) {
|
||||
$query->whereNull('completed_at')
|
||||
->orWhere('is_successful', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class InitiateBackupService
|
||||
|
||||
// Check if the server has reached or exceeded its backup limit.
|
||||
// completed_at == null will cover any ongoing backups, while is_successful == true will cover any completed backups.
|
||||
$successful = $this->getNonFailedBackups($server);
|
||||
$successful = $this->repository->getNonFailedBackups($server);
|
||||
if (!$server->backup_limit || $successful->count() >= $server->backup_limit) {
|
||||
// Do not allow the user to continue if this server is already at its limit and can't override.
|
||||
if (!$override || $server->backup_limit <= 0) {
|
||||
|
@ -12,7 +12,7 @@ interface ctx {
|
||||
|
||||
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
||||
|
||||
type BackupResponse = PaginatedResult<ServerBackup> & { usedBackupCount: number };
|
||||
type BackupResponse = PaginatedResult<ServerBackup> & { backupCount: number };
|
||||
|
||||
export default () => {
|
||||
const { page } = useContext(Context);
|
||||
@ -24,7 +24,7 @@ export default () => {
|
||||
return ({
|
||||
items: (data.data || []).map(rawDataToServerBackup),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
usedBackupCount: data.meta.used_backup_count,
|
||||
backupCount: data.meta.backup_count,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -65,12 +65,12 @@ const BackupContainer = () => {
|
||||
}
|
||||
<Can action={'backup.create'}>
|
||||
<div css={tw`mt-6 sm:flex items-center justify-end`}>
|
||||
{(backupLimit > 0 && backups.usedBackupCount > 0) &&
|
||||
{(backupLimit > 0 && backups.backupCount > 0) &&
|
||||
<p css={tw`text-sm text-neutral-300 mb-4 sm:mr-6 sm:mb-0`}>
|
||||
{backups.usedBackupCount} of {backupLimit} backups have been created for this server.
|
||||
{backups.backupCount} of {backupLimit} backups have been created for this server.
|
||||
</p>
|
||||
}
|
||||
{backupLimit > 0 && backupLimit > backups.usedBackupCount &&
|
||||
{backupLimit > 0 && backupLimit > backups.backupCount &&
|
||||
<CreateBackupButton css={tw`w-full sm:w-auto`}/>
|
||||
}
|
||||
</div>
|
||||
|
@ -51,7 +51,7 @@ export default ({ backup }: Props) => {
|
||||
.then(() => mutate(data => ({
|
||||
...data!,
|
||||
items: data!.items.filter(b => b.uuid !== backup.uuid),
|
||||
usedBackupCount: data!.usedBackupCount - 1,
|
||||
backupCount: data!.backupCount - 1,
|
||||
}), false))
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
|
@ -81,7 +81,7 @@ export default () => {
|
||||
clearFlashes('backups:create');
|
||||
createServerBackup(uuid, values)
|
||||
.then(backup => {
|
||||
mutate(data => ({ ...data!, items: data!.items.concat(backup), usedBackupCount: data!.usedBackupCount + 1 }), false);
|
||||
mutate(data => ({ ...data!, items: data!.items.concat(backup), backupCount: data!.backupCount + 1 }), false);
|
||||
setVisible(false);
|
||||
})
|
||||
.catch(error => {
|
||||
|
Loading…
Reference in New Issue
Block a user