diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-09-07 16:09:22 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-05 11:00:16 +0200 |
commit | 6807cb684f64587f1747b5168eb42e5172c889eb (patch) | |
tree | 8cd20e87f28693c1c4d2dc44ea9c6c43f597ceeb /lib/private | |
parent | ac38a3a654df909d2c0c9d7c4d84e8e5ea2c587a (diff) | |
download | nextcloud-server-6807cb684f64587f1747b5168eb42e5172c889eb.tar.gz nextcloud-server-6807cb684f64587f1747b5168eb42e5172c889eb.zip |
avatar to appdata
* Fix AvatarTest
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Avatar.php | 16 | ||||
-rw-r--r-- | lib/private/AvatarManager.php | 29 | ||||
-rw-r--r-- | lib/private/Files/SimpleFS/SimpleFolder.php | 4 | ||||
-rw-r--r-- | lib/private/Server.php | 2 |
4 files changed, 23 insertions, 28 deletions
diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php index e7fd4da4615..c3a068701df 100644 --- a/lib/private/Avatar.php +++ b/lib/private/Avatar.php @@ -29,10 +29,9 @@ namespace OC; use OC\User\User; -use OCP\Files\Folder; -use OCP\Files\File; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IAvatar; use OCP\IConfig; @@ -99,7 +98,8 @@ class Avatar implements IAvatar { * @return bool */ public function exists() { - return $this->folder->nodeExists('avatar.jpg') || $this->folder->nodeExists('avatar.png'); + + return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png'); } /** @@ -171,15 +171,15 @@ class Avatar implements IAvatar { } try { - $file = $this->folder->get($path); + $file = $this->folder->getFile($path); } catch (NotFoundException $e) { if ($size <= 0) { throw new NotFoundException; } $avatar = new OC_Image(); - /** @var File $file */ - $file = $this->folder->get('avatar.' . $ext); + /** @var ISimpleFile $file */ + $file = $this->folder->getFile('avatar.' . $ext); $avatar->loadFromData($file->getContent()); if ($size !== -1) { $avatar->resize($size); @@ -202,9 +202,9 @@ class Avatar implements IAvatar { * @throws NotFoundException */ private function getExtension() { - if ($this->folder->nodeExists('avatar.jpg')) { + if ($this->folder->fileExists('avatar.jpg')) { return 'jpg'; - } elseif ($this->folder->nodeExists('avatar.png')) { + } elseif ($this->folder->fileExists('avatar.png')) { return 'png'; } throw new NotFoundException; diff --git a/lib/private/AvatarManager.php b/lib/private/AvatarManager.php index df3247b8f00..b8c6c2a1eb6 100644 --- a/lib/private/AvatarManager.php +++ b/lib/private/AvatarManager.php @@ -27,13 +27,12 @@ namespace OC; -use OCP\Files\Folder; +use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\IAvatarManager; use OCP\IConfig; use OCP\ILogger; use OCP\IUserManager; -use OCP\Files\IRootFolder; use OCP\IL10N; /** @@ -44,8 +43,8 @@ class AvatarManager implements IAvatarManager { /** @var IUserManager */ private $userManager; - /** @var IRootFolder */ - private $rootFolder; + /** @var IAppData */ + private $appData; /** @var IL10N */ private $l; @@ -60,19 +59,19 @@ class AvatarManager implements IAvatarManager { * AvatarManager constructor. * * @param IUserManager $userManager - * @param IRootFolder $rootFolder + * @param IAppData $appData * @param IL10N $l * @param ILogger $logger * @param IConfig $config */ public function __construct( IUserManager $userManager, - IRootFolder $rootFolder, + IAppData $appData, IL10N $l, ILogger $logger, IConfig $config) { $this->userManager = $userManager; - $this->rootFolder = $rootFolder; + $this->appData = $appData; $this->l = $l; $this->logger = $logger; $this->config = $config; @@ -95,20 +94,12 @@ class AvatarManager implements IAvatarManager { // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) $userId = $user->getUID(); - /* - * Fix for #22119 - * Basically we do not want to copy the skeleton folder. - * - * For unit test purposes this is ignored when run in PHPUnit. - */ - if(!defined('PHPUNIT_RUN')) { - \OC\Files\Filesystem::initMountPoints($userId); + try { + $folder = $this->appData->getFolder($userId); + } catch (NotFoundException $e) { + $folder = $this->appData->newFolder($userId); } - $dir = '/' . $userId; - /** @var Folder $folder */ - $folder = $this->rootFolder->get($dir); - return new Avatar($folder, $this->l, $user, $this->logger, $this->config); } } diff --git a/lib/private/Files/SimpleFS/SimpleFolder.php b/lib/private/Files/SimpleFS/SimpleFolder.php index 8ce6c013c1f..5b55fe0f157 100644 --- a/lib/private/Files/SimpleFS/SimpleFolder.php +++ b/lib/private/Files/SimpleFS/SimpleFolder.php @@ -65,6 +65,10 @@ class SimpleFolder implements ISimpleFolder { $this->folder->delete(); } + public function fileExists($name) { + return $this->folder->nodeExists($name); + } + public function getFile($name) { $file = $this->folder->get($name); diff --git a/lib/private/Server.php b/lib/private/Server.php index 838393b8507..cd2cce5cb0b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -359,7 +359,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('AvatarManager', function (Server $c) { return new AvatarManager( $c->getUserManager(), - $c->getRootFolder(), + $c->getAppDataDir('avatar'), $c->getL10N('lib'), $c->getLogger(), $c->getConfig() |