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
refactor(ShareApiController): Streamline share providers & add error …
…logging

1. Consolidated the repetitive provider code into a clean loop

2. Added exception handling to log unexpected errors

Signed-off-by: nfebe <[email protected]>
  • Loading branch information
nfebe committed Nov 18, 2025
commit 03c4d74e4dd3e81e6d2dff46c10d5833663def21
80 changes: 25 additions & 55 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1689,66 +1689,36 @@ private function parseDate(string $expireDate): \DateTime {
* @throws ShareNotFound
*/
private function getShareById(string $id): IShare {
$share = null;

// First check if it is an internal share.
try {
$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
return $share;
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}


try {
if ($this->shareManager->shareProviderExists(IShare::TYPE_CIRCLE)) {
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
return $share;
}
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}

try {
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
return $share;
}
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}

try {
$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
return $share;
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}
$providers = [
'ocinternal' => null, // No type check needed
'ocCircleShare' => IShare::TYPE_CIRCLE,
'ocMailShare' => IShare::TYPE_EMAIL,
'ocRoomShare' => null,
'deck' => IShare::TYPE_DECK,
'sciencemesh' => IShare::TYPE_SCIENCEMESH,
];

try {
if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) {
$share = $this->shareManager->getShareById('deck:' . $id, $this->currentUser);
return $share;
}
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
// Add federated sharing as a provider only if it's allowed
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$providers['ocFederatedSharing'] = null; // No type check needed
}

try {
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
$share = $this->shareManager->getShareById('sciencemesh:' . $id, $this->currentUser);
return $share;
foreach ($providers as $prefix => $type) {
try {
if ($type === null || $this->shareManager->shareProviderExists($type)) {
return $this->shareManager->getShareById($prefix . ':' . $id, $this->currentUser);
}
} catch (ShareNotFound $e) {
// Do nothing, continue to next provider
} catch (\Exception $e) {
$this->logger->warning('Unexpected error in share provider', [
'shareId' => $id,
'provider' => $prefix,
'exception' => $e,
]);
}
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}

if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
throw new ShareNotFound();
}
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);

return $share;
throw new ShareNotFound();
}

/**
Expand Down
Loading