👌 IMPROVE: make it possible to add the user to an array of groups (for later extendability e.g. #69)

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
Signed-off-by: none <vlad@teksperts.nyc>
This commit is contained in:
Jonas Sulzer
2019-05-24 13:36:21 +02:00
committed by none
parent f99c4daa71
commit 8c38759958
2 changed files with 17 additions and 20 deletions

View File

@@ -170,10 +170,11 @@ abstract class Base extends \OC\User\Backend{
* Create user record in database
*
* @param string $uid The username
* @param array $groups Groups to add the user to on creation
*
* @return void
*/
protected function storeUser($uid) {
protected function storeUser($uid, $groups) {
if (!$this->userExists($uid)) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->insert('users_external')
@@ -182,6 +183,13 @@ abstract class Base extends \OC\User\Backend{
'backend' => $query->createNamedParameter($this->backend),
]);
$query->execute();
if ($groups) {
$createduser = \OC::$server->getUserManager()->get($uid);
foreach ($groups as $group) {
\OC::$server->getGroupManager()->createGroup($group)->addUser($createduser);
}
}
}
}