Add getUserFolder to IRootFolder
* untangle DI of user specific folders * allows to autodetect the dependency
This commit is contained in:
parent
f70791653c
commit
3e97ca3b96
|
@ -323,4 +323,33 @@ class Root extends Folder implements IRootFolder {
|
||||||
public function getName() {
|
public function getName() {
|
||||||
return '';
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
$userId = $user->getUID();
|
$userId = $user->getUID();
|
||||||
} else {
|
|
||||||
$user = $this->getUserManager()->get($userId);
|
|
||||||
}
|
}
|
||||||
\OC\Files\Filesystem::initMountPoints($userId);
|
|
||||||
$dir = '/' . $userId;
|
|
||||||
$root = $this->getRootFolder();
|
$root = $this->getRootFolder();
|
||||||
$folder = null;
|
return $root->getUserFolder($userId);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -267,17 +267,17 @@ class OC_Util {
|
||||||
/**
|
/**
|
||||||
* copies the skeleton to the users /files
|
* copies the skeleton to the users /files
|
||||||
*
|
*
|
||||||
* @param \OC\User\User $user
|
* @param String $userId
|
||||||
* @param \OCP\Files\Folder $userDirectory
|
* @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');
|
$skeletonDirectory = \OCP\Config::getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
|
||||||
|
|
||||||
if (!empty($skeletonDirectory)) {
|
if (!empty($skeletonDirectory)) {
|
||||||
\OCP\Util::writeLog(
|
\OCP\Util::writeLog(
|
||||||
'files_skeleton',
|
'files_skeleton',
|
||||||
'copying skeleton for '.$user->getUID().' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
|
'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
|
||||||
\OCP\Util::DEBUG
|
\OCP\Util::DEBUG
|
||||||
);
|
);
|
||||||
self::copyr($skeletonDirectory, $userDirectory);
|
self::copyr($skeletonDirectory, $userDirectory);
|
||||||
|
|
|
@ -33,5 +33,13 @@ use OC\Hooks\Emitter;
|
||||||
*/
|
*/
|
||||||
interface IRootFolder extends Folder, 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
|
* @param string $userId user ID
|
||||||
* @return \OCP\Files\Folder
|
* @return \OCP\Files\Folder
|
||||||
* @since 6.0.0 - parameter $userId was added in 8.0.0
|
* @since 6.0.0 - parameter $userId was added in 8.0.0
|
||||||
|
* @see getUserFolder in \OCP\Files\IRootFolder
|
||||||
*/
|
*/
|
||||||
public function getUserFolder($userId = null);
|
public function getUserFolder($userId = null);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue