From e546cd9b7125badea9844eb4a5deac93d4f495aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 20 Aug 2020 13:30:39 +0200 Subject: [PATCH] Filter out entries that fail due to StorageNotAvailableException MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Dashboard/RecommendationWidget.php | 3 --- lib/Service/RecentlyEditedFilesSource.php | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Dashboard/RecommendationWidget.php b/lib/Dashboard/RecommendationWidget.php index 9f02af2b..9c3f6981 100644 --- a/lib/Dashboard/RecommendationWidget.php +++ b/lib/Dashboard/RecommendationWidget.php @@ -41,8 +41,6 @@ class RecommendationWidget implements IWidget { private $recommendationService; /** @var IL10N */ private $l10n; - /** @var IURLGenerator */ - private $urlGenerator; public function __construct( IInitialStateService $initialStateService, @@ -55,7 +53,6 @@ public function __construct( $this->userSession = $userSession; $this->recommendationService = $recommendationService; $this->l10n = $l10n; - $this->urlGenerator = $urlGenerator; } public function getId(): string { diff --git a/lib/Service/RecentlyEditedFilesSource.php b/lib/Service/RecentlyEditedFilesSource.php index df7d254b..3206dcec 100644 --- a/lib/Service/RecentlyEditedFilesSource.php +++ b/lib/Service/RecentlyEditedFilesSource.php @@ -26,6 +26,7 @@ namespace OCA\Recommendations\Service; use OCP\Files\Node; +use OCP\Files\StorageNotAvailableException; use OCP\IL10N; use OCP\IServerContainer; use OCP\IUser; @@ -50,14 +51,20 @@ public function __construct(IServerContainer $serverContainer, public function getMostRecentRecommendation(IUser $user, int $max): array { $userFolder = $this->serverContainer->getUserFolder($user->getUID()); - return array_map(function (Node $node) use ($userFolder) { - return new RecommendedFile( - $userFolder->getRelativePath($node->getParent()->getPath()), - $node, - $node->getMTime(), - $this->l10n->t("Recently edited") - ); - }, $userFolder->getRecent($max)); + return array_filter(array_map(function (Node $node) use ($userFolder) { + try { + return new RecommendedFile( + $userFolder->getRelativePath($node->getParent()->getPath()), + $node, + $node->getMTime(), + $this->l10n->t("Recently edited") + ); + } catch (StorageNotAvailableException $e) { + return null; + } + }, $userFolder->getRecent($max)), function ($entry) { + return $entry !== null; + }); } }