Skip to content

Commit 56f8d63

Browse files
committed
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 <fenn25.fn@gmail.com>
1 parent c52e16d commit 56f8d63

File tree

1 file changed

+25
-55
lines changed

1 file changed

+25
-55
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,66 +1689,36 @@ private function parseDate(string $expireDate): \DateTime {
16891689
* @throws ShareNotFound
16901690
*/
16911691
private function getShareById(string $id): IShare {
1692-
$share = null;
1693-
1694-
// First check if it is an internal share.
1695-
try {
1696-
$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
1697-
return $share;
1698-
} catch (ShareNotFound $e) {
1699-
// Do nothing, just try the other share type
1700-
}
1701-
1702-
1703-
try {
1704-
if ($this->shareManager->shareProviderExists(IShare::TYPE_CIRCLE)) {
1705-
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
1706-
return $share;
1707-
}
1708-
} catch (ShareNotFound $e) {
1709-
// Do nothing, just try the other share type
1710-
}
1711-
1712-
try {
1713-
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
1714-
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
1715-
return $share;
1716-
}
1717-
} catch (ShareNotFound $e) {
1718-
// Do nothing, just try the other share type
1719-
}
1720-
1721-
try {
1722-
$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
1723-
return $share;
1724-
} catch (ShareNotFound $e) {
1725-
// Do nothing, just try the other share type
1726-
}
1692+
$providers = [
1693+
'ocinternal' => null, // No type check needed
1694+
'ocCircleShare' => IShare::TYPE_CIRCLE,
1695+
'ocMailShare' => IShare::TYPE_EMAIL,
1696+
'ocRoomShare' => null,
1697+
'deck' => IShare::TYPE_DECK,
1698+
'sciencemesh' => IShare::TYPE_SCIENCEMESH,
1699+
];
17271700

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

1737-
try {
1738-
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
1739-
$share = $this->shareManager->getShareById('sciencemesh:' . $id, $this->currentUser);
1740-
return $share;
1706+
foreach ($providers as $prefix => $type) {
1707+
try {
1708+
if ($type === null || $this->shareManager->shareProviderExists($type)) {
1709+
return $this->shareManager->getShareById($prefix . ':' . $id, $this->currentUser);
1710+
}
1711+
} catch (ShareNotFound $e) {
1712+
// Do nothing, continue to next provider
1713+
} catch (\Exception $e) {
1714+
$this->logger->warning('Unexpected error in share provider', [
1715+
'shareId' => $id,
1716+
'provider' => $prefix,
1717+
'exception' => $e,
1718+
]);
17411719
}
1742-
} catch (ShareNotFound $e) {
1743-
// Do nothing, just try the other share type
17441720
}
1745-
1746-
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
1747-
throw new ShareNotFound();
1748-
}
1749-
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
1750-
1751-
return $share;
1721+
throw new ShareNotFound();
17521722
}
17531723

17541724
/**

0 commit comments

Comments
 (0)