dont die when we cant save the resized avatar, log instead
This commit is contained in:
parent
750ec93394
commit
54e750ba78
|
@ -312,7 +312,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
return new AvatarManager(
|
return new AvatarManager(
|
||||||
$c->getUserManager(),
|
$c->getUserManager(),
|
||||||
$c->getRootFolder(),
|
$c->getRootFolder(),
|
||||||
$c->getL10N('lib')
|
$c->getL10N('lib'),
|
||||||
|
$c->getLogger()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$this->registerService('Logger', function (Server $c) {
|
$this->registerService('Logger', function (Server $c) {
|
||||||
|
|
|
@ -31,10 +31,12 @@ use OC\User\User;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\Files\NotPermittedException;
|
||||||
use OCP\IAvatar;
|
use OCP\IAvatar;
|
||||||
use OCP\IImage;
|
use OCP\IImage;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OC_Image;
|
use OC_Image;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class gets and sets users avatars.
|
* This class gets and sets users avatars.
|
||||||
|
@ -47,6 +49,8 @@ class Avatar implements IAvatar {
|
||||||
private $l;
|
private $l;
|
||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
@ -54,11 +58,13 @@ class Avatar implements IAvatar {
|
||||||
* @param Folder $folder The folder where the avatars are
|
* @param Folder $folder The folder where the avatars are
|
||||||
* @param IL10N $l
|
* @param IL10N $l
|
||||||
* @param User $user
|
* @param User $user
|
||||||
|
* @param ILogger $logger
|
||||||
*/
|
*/
|
||||||
public function __construct (Folder $folder, IL10N $l, $user) {
|
public function __construct (Folder $folder, IL10N $l, $user, ILogger $logger) {
|
||||||
$this->folder = $folder;
|
$this->folder = $folder;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,8 +170,12 @@ class Avatar implements IAvatar {
|
||||||
if ($size !== -1) {
|
if ($size !== -1) {
|
||||||
$avatar->resize($size);
|
$avatar->resize($size);
|
||||||
}
|
}
|
||||||
$file = $this->folder->newFile($path);
|
try {
|
||||||
$file->putContent($avatar->data());
|
$file = $this->folder->newFile($path);
|
||||||
|
$file->putContent($avatar->data());
|
||||||
|
} catch (NotPermittedException $e) {
|
||||||
|
$this->logger->error('Failed to save avatar for ' . $this->user->getUID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace OC;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IAvatarManager;
|
use OCP\IAvatarManager;
|
||||||
|
use OCP\ILogger;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
@ -46,20 +47,26 @@ class AvatarManager implements IAvatarManager {
|
||||||
/** @var IL10N */
|
/** @var IL10N */
|
||||||
private $l;
|
private $l;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AvatarManager constructor.
|
* AvatarManager constructor.
|
||||||
*
|
*
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param IRootFolder $rootFolder
|
* @param IRootFolder $rootFolder
|
||||||
* @param IL10N $l
|
* @param IL10N $l
|
||||||
|
* @param ILogger $logger
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
IL10N $l) {
|
IL10N $l,
|
||||||
|
ILogger $logger) {
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +92,6 @@ class AvatarManager implements IAvatarManager {
|
||||||
/** @var Folder $folder */
|
/** @var Folder $folder */
|
||||||
$folder = $this->rootFolder->get($dir);
|
$folder = $this->rootFolder->get($dir);
|
||||||
|
|
||||||
return new Avatar($folder, $this->l, $user);
|
return new Avatar($folder, $this->l, $user, $this->logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class AvatarTest extends \Test\TestCase {
|
||||||
$l = $this->getMock('\OCP\IL10N');
|
$l = $this->getMock('\OCP\IL10N');
|
||||||
$l->method('t')->will($this->returnArgument(0));
|
$l->method('t')->will($this->returnArgument(0));
|
||||||
$this->user = $this->getMockBuilder('\OC\User\User')->disableOriginalConstructor()->getMock();
|
$this->user = $this->getMockBuilder('\OC\User\User')->disableOriginalConstructor()->getMock();
|
||||||
$this->avatar = new \OC\Avatar($this->folder, $l, $this->user);
|
$this->avatar = new \OC\Avatar($this->folder, $l, $this->user, $this->getMock('\OCP\ILogger'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetNoAvatar() {
|
public function testGetNoAvatar() {
|
||||||
|
|
Loading…
Reference in New Issue