Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,35 @@ public function isPageInPageFolder(int $collectiveId, int $parentId, int $pageId
* @throws NotFoundException
* @throws NotPermittedException
*/
private function getSubpagesFromFile(int $collectiveId, File $file, string $userId): array {
private function getChildPageIds(int $collectiveId, File $file, string $userId): array {
if (!NodeHelper::isIndexPage($file)) {
return [];
}

$parentId = $file->getId();
$folder = $this->getFolder($collectiveId, $parentId, $userId);
return array_filter($this->getPagesFromFolder($collectiveId, $folder, $userId), static fn (PageInfo $pageInfo) => $pageInfo->getParentId() === $parentId);
$folderNodes = $folder->getDirectoryListing();

$childIds = [];
foreach ($folderNodes as $node) {
if (str_starts_with($node->getName(), '.')) {
continue;
}

if ($node instanceof Folder) {
// Get index page ID from subfolder
try {
$childIds[] = self::getIndexPageFile($node)->getId();
} catch (NotFoundException) {
// Ignore subfolders without index page
}
} elseif ($node instanceof File && NodeHelper::isPage($node) && !NodeHelper::isIndexPage($node)) {
// Regular page file (not index page)
$childIds[] = $node->getId();
}
}

return $childIds;
}

/**
Expand Down Expand Up @@ -967,7 +988,7 @@ public function setSubpageOrder(int $collectiveId, int $id, ?string $subpageOrde
*/
private function cleanSubpageOrder(int $collectiveId, PageInfo $pageInfo, string $userId): string {
$pageFile = $this->getPageFile($collectiveId, $pageInfo->getId(), $userId);
$childIds = array_map(static fn (PageInfo $pageInfo) => $pageInfo->getId(), $this->getSubpagesFromFile($collectiveId, $pageFile, $userId));
$childIds = $this->getChildPageIds($collectiveId, $pageFile, $userId);
return SubpageOrderService::clean($pageInfo->getSubpageOrder(), $childIds);
}

Expand Down
Loading