Skip to content

Commit

Permalink
Don't fail move avatar step if user has no home at all
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Sep 27, 2016
1 parent 9ce19e2 commit acfd7ef
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/private/Repair/MoveAvatarOutsideHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\IConfig;
use OCP\Files\Folder;
use OCP\IAvatarManager;
use OCP\Files\NotFoundException;

/**
* Move avatars outside of their homes to the new location
Expand Down Expand Up @@ -98,15 +99,19 @@ private function moveAvatars(IOutput $out, IUser $user, Folder $newAvatarsFolder
\OC\Files\Filesystem::initMountPoints($userId);

// call get instead of getUserFolder to avoid needless skeleton copy
$oldAvatarUserFolder = $this->rootFolder->get('/' . $userId);
$oldAvatar = new Avatar($oldAvatarUserFolder, $this->l, $user, $this->logger);
if ($oldAvatar->exists()) {
$newAvatarsUserFolder = $this->avatarManager->getAvatarFolder($userId);

// get original file
$oldAvatarFile = $oldAvatar->getFile(-1);
$oldAvatarFile->move($newAvatarsUserFolder->getPath() . '/' . $oldAvatarFile->getName());
$oldAvatar->remove();
try {
$oldAvatarUserFolder = $this->rootFolder->get('/' . $userId);
$oldAvatar = new Avatar($oldAvatarUserFolder, $this->l, $user, $this->logger);
if ($oldAvatar->exists()) {
$newAvatarsUserFolder = $this->avatarManager->getAvatarFolder($userId);

// get original file
$oldAvatarFile = $oldAvatar->getFile(-1);
$oldAvatarFile->move($newAvatarsUserFolder->getPath() . '/' . $oldAvatarFile->getName());
$oldAvatar->remove();
}
} catch (NotFoundException $e) {
// not all users have a home, ignore
}

\OC_Util::tearDownFS();
Expand Down

0 comments on commit acfd7ef

Please sign in to comment.