Skip to content

Commit d922725

Browse files
committed
feat: add sentry error logging
Signed-off-by: ItsNeil17 <neil@hytalemodding.dev>
1 parent 6f7b80e commit d922725

6 files changed

Lines changed: 696 additions & 3 deletions

File tree

app/Http/Controllers/PageController.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ public function edit(Mod $mod, Page $page)
236236
$this->ensureManualPageEditingAllowed($mod);
237237

238238
$page->load(['parent']);
239+
$descendantIds = $this->getDescendantIds($page);
239240

240241
$potentialParents = $mod->pages()
241242
->where('id', '!=', $page->id)
243+
->when($descendantIds !== [], fn ($query) => $query->whereNotIn('id', $descendantIds))
242244
->orderBy('title')
243245
->get();
244246

@@ -282,6 +284,10 @@ public function update(Request $request, Mod $mod, Page $page)
282284
if ($parent->mod_id !== $mod->id || $parent->id === $page->id) {
283285
abort(422, 'Invalid parent page.');
284286
}
287+
288+
if (in_array($parent->id, $this->getDescendantIds($page), true)) {
289+
abort(422, 'Invalid parent page.');
290+
}
285291
}
286292

287293
if (($validated['kind'] ?? $page->kind) === Page::KIND_CATEGORY) {
@@ -406,6 +412,34 @@ private function ensureManualPageEditingAllowed(Mod $mod): void
406412
}
407413
}
408414

415+
/**
416+
* Get all descendant page IDs for a page in the same mod.
417+
*
418+
* @return array<int, string>
419+
*/
420+
private function getDescendantIds(Page $page): array
421+
{
422+
$descendantIds = [];
423+
$currentParentIds = [$page->id];
424+
425+
while ($currentParentIds !== []) {
426+
$childIds = Page::query()
427+
->where('mod_id', $page->mod_id)
428+
->whereIn('parent_id', $currentParentIds)
429+
->pluck('id')
430+
->all();
431+
432+
if ($childIds === []) {
433+
break;
434+
}
435+
436+
$descendantIds = array_merge($descendantIds, $childIds);
437+
$currentParentIds = $childIds;
438+
}
439+
440+
return $descendantIds;
441+
}
442+
409443
/**
410444
* Search pages within a mod.
411445
*/

bootstrap/app.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Foundation\Configuration\Exceptions;
1111
use Illuminate\Foundation\Configuration\Middleware;
1212
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
13+
use Sentry\Laravel\Integration;
1314

1415
return Application::configure(basePath: dirname(__DIR__))
1516
->withRouting(
@@ -44,5 +45,5 @@
4445
]);
4546
})
4647
->withExceptions(function (Exceptions $exceptions): void {
47-
//
48+
Integration::handles($exceptions);
4849
})->create();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"laravel/fortify": "^1.30",
1515
"laravel/framework": "^12.0",
1616
"laravel/tinker": "^2.10.1",
17-
"laravel/wayfinder": "^0.1.9"
17+
"laravel/wayfinder": "^0.1.9",
18+
"sentry/sentry-laravel": "^4.22"
1819
},
1920
"require-dev": {
2021
"fakerphp/faker": "^1.23",

0 commit comments

Comments
 (0)