diff options
Diffstat (limited to 'apps/user_ldap/lib/User/User.php')
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 53444990b26..e51b0abc80d 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -552,35 +552,37 @@ class User { /** * @brief attempts to get an image from LDAP and sets it as Nextcloud avatar - * @return null + * @return bool */ - public function updateAvatar() { - if($this->wasRefreshed('avatar')) { - return; + public function updateAvatar($force = false) { + if(!$force && $this->wasRefreshed('avatar')) { + return false; } $avatarImage = $this->getAvatarImage(); if($avatarImage === false) { //not set, nothing left to do; - return; + return false; + } + if(!$this->image->loadFromBase64(base64_encode($avatarImage))) { + return false; } - $this->image->loadFromBase64(base64_encode($avatarImage)); - $this->setOwnCloudAvatar(); + return $this->setOwnCloudAvatar(); } /** * @brief sets an image as Nextcloud avatar - * @return null + * @return bool */ private function setOwnCloudAvatar() { if(!$this->image->valid()) { $this->log->log('jpegPhoto data invalid for '.$this->dn, Util::ERROR); - return; + return false; } //make sure it is a square and not bigger than 128x128 $size = min(array($this->image->width(), $this->image->height(), 128)); if(!$this->image->centerCrop($size)) { $this->log->log('croping image for avatar failed for '.$this->dn, Util::ERROR); - return; + return false; } if(!$this->fs->isLoaded()) { @@ -590,11 +592,13 @@ class User { try { $avatar = $this->avatarManager->getAvatar($this->uid); $avatar->set($this->image); + return true; } catch (\Exception $e) { \OC::$server->getLogger()->notice( 'Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), ['app' => 'user_ldap']); } + return false; } /** |