Commit d52e197b authored by Morris Jobke's avatar Morris Jobke
Browse files

Merge pull request #16965 from owncloud/getUserFolder-in-IRootFolder

Add getUserFolder to IRootFolder
parents 2b86ba43 3e97ca3b
......@@ -323,4 +323,33 @@ class Root extends Folder implements IRootFolder {
public function getName() {
return '';
}
/**
* Returns a view to user's files folder
*
* @param String $userId user ID
* @return \OCP\Files\Folder
*/
public function getUserFolder($userId) {
\OC\Files\Filesystem::initMountPoints($userId);
$dir = '/' . $userId;
$folder = null;
if (!$this->nodeExists($dir)) {
$folder = $this->newFolder($dir);
} else {
$folder = $this->get($dir);
}
$dir = '/files';
if (!$folder->nodeExists($dir)) {
$folder = $folder->newFolder($dir);
\OC_Util::copySkeleton($userId, $folder);
} else {
$folder = $folder->get($dir);
}
return $folder;
}
}
......@@ -535,29 +535,9 @@ class Server extends SimpleContainer implements IServerContainer {
return null;
}
$userId = $user->getUID();
} else {
$user = $this->getUserManager()->get($userId);
}
\OC\Files\Filesystem::initMountPoints($userId);
$dir = '/' . $userId;
$root = $this->getRootFolder();
$folder = null;
if (!$root->nodeExists($dir)) {
$folder = $root->newFolder($dir);
} else {
$folder = $root->get($dir);
}
$dir = '/files';
if (!$folder->nodeExists($dir)) {
$folder = $folder->newFolder($dir);
\OC_Util::copySkeleton($user, $folder);
} else {
$folder = $folder->get($dir);
}
return $folder;
return $root->getUserFolder($userId);
}
/**
......
......@@ -267,17 +267,17 @@ class OC_Util {
/**
* copies the skeleton to the users /files
*
* @param \OC\User\User $user
* @param String $userId
* @param \OCP\Files\Folder $userDirectory
*/
public static function copySkeleton(\OC\User\User $user, \OCP\Files\Folder $userDirectory) {
public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
$skeletonDirectory = \OCP\Config::getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
if (!empty($skeletonDirectory)) {
\OCP\Util::writeLog(
'files_skeleton',
'copying skeleton for '.$user->getUID().' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
\OCP\Util::DEBUG
);
self::copyr($skeletonDirectory, $userDirectory);
......
......@@ -33,5 +33,13 @@ use OC\Hooks\Emitter;
*/
interface IRootFolder extends Folder, Emitter {
/**
* Returns a view to user's files folder
*
* @param String $userId user ID
* @return \OCP\Files\Folder
* @since 8.2.0
*/
public function getUserFolder($userId);
}
......@@ -99,6 +99,7 @@ interface IServerContainer {
* @param string $userId user ID
* @return \OCP\Files\Folder
* @since 6.0.0 - parameter $userId was added in 8.0.0
* @see getUserFolder in \OCP\Files\IRootFolder
*/
public function getUserFolder($userId = null);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment