aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-11-18 11:28:52 +0100
committerGitHub <noreply@github.com>2020-11-18 11:28:52 +0100
commit884c80053aa693732bb685c717cdf133ed73f13d (patch)
treebe80f3afccd30511b022b3940ecd3b1b7a58de58 /apps
parent5eaeba49aa54d7be5c4746cd6823b747d51e34bc (diff)
parente904da9d7abbf67d41f36051511b8a7b67f5359b (diff)
downloadnextcloud-server-884c80053aa693732bb685c717cdf133ed73f13d.tar.gz
nextcloud-server-884c80053aa693732bb685c717cdf133ed73f13d.zip
Merge pull request #24198 from nextcloud/bugfix/noid/no-fs-setup-dashboard
Only setup filesystem if needed for dashboard background service
Diffstat (limited to 'apps')
-rw-r--r--apps/dashboard/lib/Service/BackgroundService.php58
1 files changed, 38 insertions, 20 deletions
diff --git a/apps/dashboard/lib/Service/BackgroundService.php b/apps/dashboard/lib/Service/BackgroundService.php
index 605f953d15b..69fd2c1301f 100644
--- a/apps/dashboard/lib/Service/BackgroundService.php
+++ b/apps/dashboard/lib/Service/BackgroundService.php
@@ -26,11 +26,18 @@ declare(strict_types=1);
namespace OCA\Dashboard\Service;
+use InvalidArgumentException;
+use OC\User\NoUserException;
+use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
+use OCP\Lock\LockedException;
+use OCP\PreConditionNotMetException;
class BackgroundService {
public const THEMING_MODE_DARK = 'dark';
@@ -102,13 +109,13 @@ class BackgroundService {
]
];
/**
- * @var \OCP\Files\Folder
+ * @var IRootFolder
*/
- private $userFolder;
+ private $rootFolder;
/**
- * @var \OCP\Files\SimpleFS\ISimpleFolder
+ * @var IAppData
*/
- private $dashboardUserFolder;
+ private $appData;
/**
* @var IConfig
*/
@@ -119,12 +126,8 @@ class BackgroundService {
if ($userId === null) {
return;
}
- $this->userFolder = $rootFolder->getUserFolder($userId);
- try {
- $this->dashboardUserFolder = $appData->getFolder($userId);
- } catch (NotFoundException $e) {
- $this->dashboardUserFolder = $appData->newFolder($userId);
- }
+ $this->rootFolder = $rootFolder;
+ $this->appData = $appData;
$this->config = $config;
$this->userId = $userId;
}
@@ -136,26 +139,29 @@ class BackgroundService {
/**
* @param $path
* @throws NotFoundException
- * @throws \OCP\Files\NotPermittedException
- * @throws \OCP\PreConditionNotMetException
+ * @throws NotPermittedException
+ * @throws LockedException
+ * @throws PreConditionNotMetException
+ * @throws NoUserException
*/
public function setFileBackground($path): void {
$this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
- /** @var \OCP\Files\File $file */
- $file = $this->userFolder->get($path);
- $this->dashboardUserFolder->newFile('background.jpg', $file->fopen('r'));
+ $userFolder = $this->rootFolder->getUserFolder($this->userId);
+ /** @var File $file */
+ $file = $userFolder->get($path);
+ $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r'));
}
public function setShippedBackground($fileName): void {
if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) {
- throw new \InvalidArgumentException('The given file name is invalid');
+ throw new InvalidArgumentException('The given file name is invalid');
}
$this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName);
}
public function setColorBackground(string $color): void {
- if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
- throw new \InvalidArgumentException('The given color is invalid');
+ if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
+ throw new InvalidArgumentException('The given color is invalid');
}
$this->config->setUserValue($this->userId, 'dashboard', 'background', $color);
}
@@ -164,10 +170,22 @@ class BackgroundService {
$background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default');
if ($background === 'custom') {
try {
- return $this->dashboardUserFolder->getFile('background.jpg');
- } catch (NotFoundException $e) {
+ return $this->getAppDataFolder()->getFile('background.jpg');
+ } catch (NotFoundException | NotPermittedException $e) {
}
}
return null;
}
+
+ /**
+ * @return ISimpleFolder
+ * @throws NotPermittedException
+ */
+ private function getAppDataFolder(): ISimpleFolder {
+ try {
+ return $this->appData->getFolder($this->userId);
+ } catch (NotFoundException $e) {
+ return $this->appData->newFolder($this->userId);
+ }
+ }
}