Skip to content

Commit

Permalink
Merge pull request #268 from nextcloud/bugfix/noid/storage-not-available
Browse files Browse the repository at this point in the history
Filter out entries that fail due to StorageNotAvailableException
  • Loading branch information
juliusknorr authored Aug 21, 2020
2 parents 8a86563 + e546cd9 commit 2048d76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 0 additions & 3 deletions lib/Dashboard/RecommendationWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class RecommendationWidget implements IWidget {
private $recommendationService;
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;

public function __construct(
IInitialStateService $initialStateService,
Expand All @@ -55,7 +53,6 @@ public function __construct(
$this->userSession = $userSession;
$this->recommendationService = $recommendationService;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
}

public function getId(): string {
Expand Down
23 changes: 15 additions & 8 deletions lib/Service/RecentlyEditedFilesSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
});
}

}

0 comments on commit 2048d76

Please sign in to comment.