fix documentation, get and createGroup may return null
* also have stricter checks in place Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
7b1eedb11e
commit
7ff15c9756
|
@ -68,6 +68,10 @@ class Add extends Base {
|
|||
return 1;
|
||||
} else {
|
||||
$group = $this->groupManager->createGroup($gid);
|
||||
if($group === false) {
|
||||
$output->writeln('<error>Could not create group</error>');
|
||||
return 2;
|
||||
}
|
||||
$output->writeln('Created group "' . $group->getGID() . '"');
|
||||
|
||||
$displayName = trim((string) $input->getOption('display-name'));
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
namespace OC\Core\Command\User;
|
||||
|
||||
use OC\Files\Filesystem;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
@ -152,10 +153,14 @@ class Add extends Command {
|
|||
if (!$group) {
|
||||
$this->groupManager->createGroup($groupName);
|
||||
$group = $this->groupManager->get($groupName);
|
||||
if($group instanceof IGroup) {
|
||||
$output->writeln('Created group "' . $group->getGID() . '"');
|
||||
}
|
||||
}
|
||||
if($group instanceof IGroup) {
|
||||
$group->addUser($user);
|
||||
$output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ class Manager extends PublicEmitter implements IGroupManager {
|
|||
|
||||
/**
|
||||
* @param string $gid
|
||||
* @return \OC\Group\Group
|
||||
* @return IGroup|null
|
||||
*/
|
||||
public function get($gid) {
|
||||
if (isset($this->cachedGroups[$gid])) {
|
||||
|
@ -175,7 +175,7 @@ class Manager extends PublicEmitter implements IGroupManager {
|
|||
/**
|
||||
* @param string $gid
|
||||
* @param string $displayName
|
||||
* @return \OCP\IGroup
|
||||
* @return \OCP\IGroup|null
|
||||
*/
|
||||
protected function getGroupObject($gid, $displayName = null) {
|
||||
$backends = [];
|
||||
|
@ -210,11 +210,11 @@ class Manager extends PublicEmitter implements IGroupManager {
|
|||
|
||||
/**
|
||||
* @param string $gid
|
||||
* @return IGroup|bool|null
|
||||
* @return IGroup|null
|
||||
*/
|
||||
public function createGroup($gid) {
|
||||
if ($gid === '' || $gid === null) {
|
||||
return false;
|
||||
return null;
|
||||
} else if ($group = $this->get($gid)) {
|
||||
return $group;
|
||||
} else {
|
||||
|
|
|
@ -50,6 +50,7 @@ use OC\Authentication\Token\DefaultTokenProvider;
|
|||
use OC\Log\Rotate;
|
||||
use OC\Preview\BackgroundCleanupJob;
|
||||
use OCP\Defaults;
|
||||
use OCP\IGroup;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUser;
|
||||
|
@ -380,7 +381,9 @@ class Setup {
|
|||
$config->setAppValue('core', 'vendor', $this->getVendor());
|
||||
|
||||
$group =\OC::$server->getGroupManager()->createGroup('admin');
|
||||
if($group instanceof IGroup) {
|
||||
$group->addUser($user);
|
||||
}
|
||||
|
||||
// Install shipped apps and specified app bundles
|
||||
Installer::installShippedApps();
|
||||
|
|
|
@ -75,7 +75,7 @@ interface IGroupManager {
|
|||
|
||||
/**
|
||||
* @param string $gid
|
||||
* @return \OCP\IGroup
|
||||
* @return \OCP\IGroup|null
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function get($gid);
|
||||
|
@ -89,7 +89,7 @@ interface IGroupManager {
|
|||
|
||||
/**
|
||||
* @param string $gid
|
||||
* @return \OCP\IGroup
|
||||
* @return \OCP\IGroup|null
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function createGroup($gid);
|
||||
|
|
Loading…
Reference in New Issue