From 035ff8f01429d4113ac5a06ff9939396cce75e5b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 24 Apr 2019 11:05:29 +0200 Subject: [PATCH] Catch and filter share that can't be found Signed-off-by: Christoph Wurst --- lib/Service/RecentlySharedFilesSource.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Service/RecentlySharedFilesSource.php b/lib/Service/RecentlySharedFilesSource.php index c9c1fa82..70dc76f7 100644 --- a/lib/Service/RecentlySharedFilesSource.php +++ b/lib/Service/RecentlySharedFilesSource.php @@ -25,10 +25,12 @@ namespace OCA\Recommendations\Service; +use function array_filter; use function array_map; use function array_merge; use function array_slice; use function iterator_to_array; +use OCP\Files\NotFoundException; use function usort; use Generator; use OC\Share\Constants; @@ -117,14 +119,18 @@ public function getMostRecentRecommendation(IUser $user, int $max): array { $shares = $this->getMostRecentShares($user, $max); $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - return array_map(function (IShare $share) use ($userFolder) { - return new RecommendedFile( - $userFolder->getRelativePath($userFolder->get($share->getTarget())->getParent()->getPath()), - $share->getNode(), - $share->getShareTime()->getTimestamp(), - $this->l10n->t("Recently shared") - ); - }, $shares); + return array_filter(array_map(function (IShare $share) use ($userFolder) { + try { + return new RecommendedFile( + $userFolder->getRelativePath($userFolder->get($share->getTarget())->getParent()->getPath()), + $share->getNode(), + $share->getShareTime()->getTimestamp(), + $this->l10n->t("Recently shared") + ); + } catch (NotFoundException $ex) { + return null; + } + }, $shares)); } }