From 7b1eedb11e5f55d563831d8e58c44e615267669c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 8 Oct 2019 18:05:13 +0200 Subject: [PATCH 1/5] take group creation result into consideration Signed-off-by: Arthur Schiwon --- lib/private/Group/Manager.php | 19 ++++++++++--------- tests/lib/Group/ManagerTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 7567f719b0a..b372eb1786e 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -180,7 +180,7 @@ class Manager extends PublicEmitter implements IGroupManager { protected function getGroupObject($gid, $displayName = null) { $backends = []; foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::GROUP_DETAILS)) { + if ($backend->implementsActions(Backend::GROUP_DETAILS)) { $groupData = $backend->getGroupDetails($gid); if (is_array($groupData) && !empty($groupData)) { // take the display name from the first backend that has a non-null one @@ -210,7 +210,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * @param string $gid - * @return \OC\Group\Group + * @return IGroup|bool|null */ public function createGroup($gid) { if ($gid === '' || $gid === null) { @@ -218,13 +218,14 @@ class Manager extends PublicEmitter implements IGroupManager { } else if ($group = $this->get($gid)) { return $group; } else { - $this->emit('\OC\Group', 'preCreate', array($gid)); + $this->emit('\OC\Group', 'preCreate', [$gid]); foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::CREATE_GROUP)) { - $backend->createGroup($gid); - $group = $this->getGroupObject($gid); - $this->emit('\OC\Group', 'postCreate', array($group)); - return $group; + if ($backend->implementsActions(Backend::CREATE_GROUP)) { + if($backend->createGroup($gid)) { + $group = $this->getGroupObject($gid); + $this->emit('\OC\Group', 'postCreate', [$group]); + return $group; + } } } return null; @@ -300,7 +301,7 @@ class Manager extends PublicEmitter implements IGroupManager { */ public function isAdmin($userId) { foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC\Group\Backend::IS_ADMIN) && $backend->isAdmin($userId)) { + if ($backend->implementsActions(Backend::IS_ADMIN) && $backend->isAdmin($userId)) { return true; } } diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index 32e30217759..b8f798832d2 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -190,6 +190,7 @@ class ManagerTest extends TestCase { ->method('createGroup') ->will($this->returnCallback(function () use (&$backendGroupCreated) { $backendGroupCreated = true; + return true; })); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger); @@ -199,6 +200,35 @@ class ManagerTest extends TestCase { $this->assertEquals('group1', $group->getGID()); } + public function testCreateFailure() { + /**@var \PHPUnit_Framework_MockObject_MockObject|\OC\Group\Backend $backend */ + $backendGroupCreated = false; + $backend = $this->getTestBackend( + GroupInterface::ADD_TO_GROUP | + GroupInterface::REMOVE_FROM_GOUP | + GroupInterface::COUNT_USERS | + GroupInterface::CREATE_GROUP | + GroupInterface::DELETE_GROUP | + GroupInterface::GROUP_DETAILS + ); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->willReturn(false); + $backend->expects($this->once()) + ->method('createGroup') + ->willReturn(false); + $backend->expects($this->once()) + ->method('getGroupDetails') + ->willReturn([]); + + $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger); + $manager->addBackend($backend); + + $group = $manager->createGroup('group1'); + $this->assertEquals(null, $group); + } + public function testCreateExists() { /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Group\Backend $backend */ $backend = $this->getTestBackend(); From 7ff15c975694f838a21e8e40cc03e21da83fdf97 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 9 Oct 2019 19:13:27 +0200 Subject: [PATCH 2/5] fix documentation, get and createGroup may return null * also have stricter checks in place Signed-off-by: Arthur Schiwon --- core/Command/Group/Add.php | 4 ++++ core/Command/User/Add.php | 11 ++++++++--- lib/private/Group/Manager.php | 8 ++++---- lib/private/Setup.php | 5 ++++- lib/public/IGroupManager.php | 4 ++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php index f2ee6195a44..284cf7a3e9d 100644 --- a/core/Command/Group/Add.php +++ b/core/Command/Group/Add.php @@ -68,6 +68,10 @@ class Add extends Base { return 1; } else { $group = $this->groupManager->createGroup($gid); + if($group === false) { + $output->writeln('Could not create group'); + return 2; + } $output->writeln('Created group "' . $group->getGID() . '"'); $displayName = trim((string) $input->getOption('display-name')); diff --git a/core/Command/User/Add.php b/core/Command/User/Add.php index cc53f1c78c0..c66b5eb819c 100644 --- a/core/Command/User/Add.php +++ b/core/Command/User/Add.php @@ -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); - $output->writeln('Created group "' . $group->getGID() . '"'); + 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() . '"'); } - $group->addUser($user); - $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); } } } diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index b372eb1786e..9ae25be27f5 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -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 { diff --git a/lib/private/Setup.php b/lib/private/Setup.php index d7c6df3535a..a23ce2dbb0e 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -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'); - $group->addUser($user); + if($group instanceof IGroup) { + $group->addUser($user); + } // Install shipped apps and specified app bundles Installer::installShippedApps(); diff --git a/lib/public/IGroupManager.php b/lib/public/IGroupManager.php index f7a63dfefb7..d8a557777bc 100644 --- a/lib/public/IGroupManager.php +++ b/lib/public/IGroupManager.php @@ -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); From f0ff8b030761b5eab6c08b98692a010ab5d4361f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 9 Oct 2019 19:15:43 +0200 Subject: [PATCH 3/5] reformat code for @skjnldsv <3 Signed-off-by: Arthur Schiwon --- lib/private/Group/Manager.php | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 9ae25be27f5..0e51b4ec2cc 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -93,8 +93,8 @@ class Manager extends PublicEmitter implements IGroupManager { $this->dispatcher = $dispatcher; $this->logger = $logger; - $cachedGroups = & $this->cachedGroups; - $cachedUserGroups = & $this->cachedUserGroups; + $cachedGroups = &$this->cachedGroups; + $cachedUserGroups = &$this->cachedUserGroups; $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { /** * @var \OC\Group\Group $group @@ -149,6 +149,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Get the active backends + * * @return \OCP\GroupInterface[] */ public function getBackends() { @@ -221,7 +222,7 @@ class Manager extends PublicEmitter implements IGroupManager { $this->emit('\OC\Group', 'preCreate', [$gid]); foreach ($this->backends as $backend) { if ($backend->implementsActions(Backend::CREATE_GROUP)) { - if($backend->createGroup($gid)) { + if ($backend->createGroup($gid)) { $group = $this->getGroupObject($gid); $this->emit('\OC\Group', 'postCreate', [$group]); return $group; @@ -261,7 +262,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @param IUser|null $user * @return \OC\Group\Group[] */ - public function getUserGroups(IUser $user= null) { + public function getUserGroups(IUser $user = null) { if (!$user instanceof IUser) { return []; } @@ -296,6 +297,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Checks if a userId is in the admin group + * * @param string $userId * @return bool if admin */ @@ -310,6 +312,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** * Checks if a userId is in a group + * * @param string $userId * @param string $group * @return bool if in group @@ -320,28 +323,31 @@ class Manager extends PublicEmitter implements IGroupManager { /** * get a list of group ids for a user + * * @param IUser $user * @return array with group ids */ public function getUserGroupIds(IUser $user) { - return array_map(function($value) { - return (string) $value; + return array_map(function ($value) { + return (string)$value; }, array_keys($this->getUserGroups($user))); } /** * get an array of groupid and displayName for a user + * * @param IUser $user * @return array ['displayName' => displayname] */ public function getUserGroupNames(IUser $user) { - return array_map(function($group) { + return array_map(function ($group) { return array('displayName' => $group->getDisplayName()); }, $this->getUserGroups($user)); } /** * get a list of all display names in a group + * * @param string $gid * @param string $search * @param int $limit @@ -350,32 +356,32 @@ class Manager extends PublicEmitter implements IGroupManager { */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $group = $this->get($gid); - if(is_null($group)) { + if (is_null($group)) { return []; } $search = trim($search); $groupUsers = []; - if(!empty($search)) { + if (!empty($search)) { // only user backends have the capability to do a complex search for users $searchOffset = 0; $searchLimit = $limit * 100; - if($limit === -1) { + if ($limit === -1) { $searchLimit = 500; } do { $filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset); - foreach($filteredUsers as $filteredUser) { - if($group->inGroup($filteredUser)) { - $groupUsers[]= $filteredUser; + foreach ($filteredUsers as $filteredUser) { + if ($group->inGroup($filteredUser)) { + $groupUsers[] = $filteredUser; } } $searchOffset += $searchLimit; - } while(count($groupUsers) < $searchLimit+$offset && count($filteredUsers) >= $searchLimit); + } while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit); - if($limit === -1) { + if ($limit === -1) { $groupUsers = array_slice($groupUsers, $offset); } else { $groupUsers = array_slice($groupUsers, $offset, $limit); @@ -385,7 +391,7 @@ class Manager extends PublicEmitter implements IGroupManager { } $matchingUsers = []; - foreach($groupUsers as $groupUser) { + foreach ($groupUsers as $groupUser) { $matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName(); } return $matchingUsers; From cdf8c16942c71d0faf71b346beaad70ced22a2fa Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 14 Oct 2019 11:32:05 +0200 Subject: [PATCH 4/5] reformat Setup.php Signed-off-by: Arthur Schiwon --- lib/private/Setup.php | 114 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index a23ce2dbb0e..266c70846c6 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -81,14 +81,15 @@ class Setup { * @param ISecureRandom $random * @param Installer $installer */ - public function __construct(SystemConfig $config, - IniGetWrapper $iniWrapper, - IL10N $l10n, - Defaults $defaults, - ILogger $logger, - ISecureRandom $random, - Installer $installer - ) { + public function __construct( + SystemConfig $config, + IniGetWrapper $iniWrapper, + IL10N $l10n, + Defaults $defaults, + ILogger $logger, + ISecureRandom $random, + Installer $installer + ) { $this->config = $config; $this->iniWrapper = $iniWrapper; $this->l10n = $l10n; @@ -101,13 +102,14 @@ class Setup { static protected $dbSetupClasses = [ 'mysql' => \OC\Setup\MySQL::class, 'pgsql' => \OC\Setup\PostgreSQL::class, - 'oci' => \OC\Setup\OCI::class, + 'oci' => \OC\Setup\OCI::class, 'sqlite' => \OC\Setup\Sqlite::class, 'sqlite3' => \OC\Setup\Sqlite::class, ]; /** * Wrapper around the "class_exists" PHP function to be able to mock it + * * @param string $name * @return bool */ @@ -117,6 +119,7 @@ class Setup { /** * Wrapper around the "is_callable" PHP function to be able to mock it + * * @param string $name * @return bool */ @@ -142,7 +145,7 @@ class Setup { */ public function getSupportedDatabases($allowAllDatabases = false) { $availableDatabases = [ - 'sqlite' => [ + 'sqlite' => [ 'type' => 'pdo', 'call' => 'sqlite', 'name' => 'SQLite', @@ -169,24 +172,24 @@ class Setup { $configuredDatabases = $this->config->getValue('supportedDatabases', ['sqlite', 'mysql', 'pgsql']); } - if(!is_array($configuredDatabases)) { + if (!is_array($configuredDatabases)) { throw new Exception('Supported databases are not properly configured.'); } $supportedDatabases = array(); - foreach($configuredDatabases as $database) { - if(array_key_exists($database, $availableDatabases)) { + foreach ($configuredDatabases as $database) { + if (array_key_exists($database, $availableDatabases)) { $working = false; $type = $availableDatabases[$database]['type']; $call = $availableDatabases[$database]['call']; if ($type === 'function') { $working = $this->is_callable($call); - } elseif($type === 'pdo') { + } elseif ($type === 'pdo') { $working = in_array($call, $this->getAvailableDbDriversForPdo(), true); } - if($working) { + if ($working) { $supportedDatabases[$database] = $availableDatabases[$database]['name']; } } @@ -205,14 +208,14 @@ class Setup { public function getSystemInfo($allowAllDatabases = false) { $databases = $this->getSupportedDatabases($allowAllDatabases); - $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data'); + $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); $errors = []; // Create data directory to test whether the .htaccess works // Notice that this is not necessarily the same data directory as the one // that will effectively be used. - if(!file_exists($dataDir)) { + if (!file_exists($dataDir)) { @mkdir($dataDir); } $htAccessWorking = true; @@ -243,7 +246,7 @@ class Setup { ]; } - if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) { + if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) { $errors[] = [ 'error' => $this->l10n->t( 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' . @@ -276,14 +279,14 @@ class Setup { $error = array(); $dbType = $options['dbtype']; - if(empty($options['adminlogin'])) { + if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } - if(empty($options['adminpass'])) { + if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } - if(empty($options['directory'])) { - $options['directory'] = \OC::$SERVERROOT."/data"; + if (empty($options['directory'])) { + $options['directory'] = \OC::$SERVERROOT . "/data"; } if (!isset(self::$dbSetupClasses[$dbType])) { @@ -311,8 +314,8 @@ class Setup { $request = \OC::$server->getRequest(); //no errors, good - if(isset($options['trusted_domains']) - && is_array($options['trusted_domains'])) { + if (isset($options['trusted_domains']) + && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = [$request->getInsecureServerHost()]; @@ -330,12 +333,12 @@ class Setup { //write the config file $newConfigValues = [ - 'passwordsalt' => $salt, - 'secret' => $secret, - 'trusted_domains' => $trustedDomains, - 'datadirectory' => $dataDir, - 'dbtype' => $dbType, - 'version' => implode('.', \OCP\Util::getVersion()), + 'passwordsalt' => $salt, + 'secret' => $secret, + 'trusted_domains' => $trustedDomains, + 'datadirectory' => $dataDir, + 'dbtype' => $dbType, + 'version' => implode('.', \OCP\Util::getVersion()), ]; if ($this->config->getValue('overwrite.cli.url', null) === null) { @@ -364,13 +367,13 @@ class Setup { } //create the user and group - $user = null; + $user = null; try { $user = \OC::$server->getUserManager()->createUser($username, $password); if (!$user) { $error[] = "User <$username> could not be created."; } - } catch(Exception $exception) { + } catch (Exception $exception) { $error[] = $exception->getMessage(); } @@ -380,8 +383,8 @@ class Setup { $config->setAppValue('core', 'lastupdatedat', microtime(true)); $config->setAppValue('core', 'vendor', $this->getVendor()); - $group =\OC::$server->getGroupManager()->createGroup('admin'); - if($group instanceof IGroup) { + $group = \OC::$server->getGroupManager()->createGroup('admin'); + if ($group instanceof IGroup) { $group->addUser($user); } @@ -389,15 +392,16 @@ class Setup { Installer::installShippedApps(); $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib')); $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle(); - foreach($defaultInstallationBundles as $bundle) { + foreach ($defaultInstallationBundles as $bundle) { try { $this->installer->installAppBundle($bundle); - } catch (Exception $e) {} + } catch (Exception $e) { + } } // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory - file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); + file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); // Update .htaccess files self::updateHtaccess(); @@ -437,7 +441,7 @@ class Setup { * @return string Absolute path to htaccess */ private function pathToHtaccess() { - return \OC::$SERVERROOT.'/.htaccess'; + return \OC::$SERVERROOT . '/.htaccess'; } /** @@ -502,7 +506,7 @@ class Setup { // Add rewrite rules if the RewriteBase is configured $rewriteBase = $config->getValue('htaccess.RewriteBase', ''); - if($rewriteBase !== '') { + if ($rewriteBase !== '') { $content .= "\n"; $content .= "\n Options -MultiViews"; $content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]"; @@ -535,7 +539,7 @@ class Setup { if ($content !== '') { //suppress errors in case we don't have permissions for it - return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n"); + return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n"); } return false; @@ -543,21 +547,21 @@ class Setup { public static function protectDataDirectory() { //Require all denied - $now = date('Y-m-d H:i:s'); + $now = date('Y-m-d H:i:s'); $content = "# Generated by Nextcloud on $now\n"; - $content.= "# line below if for Apache 2.4\n"; - $content.= "\n"; - $content.= "Require all denied\n"; - $content.= "\n\n"; - $content.= "# line below if for Apache 2.2\n"; - $content.= "\n"; - $content.= "deny from all\n"; - $content.= "Satisfy All\n"; - $content.= "\n\n"; - $content.= "# section for Apache 2.2 and 2.4\n"; - $content.= "\n"; - $content.= "IndexIgnore *\n"; - $content.= "\n"; + $content .= "# line below if for Apache 2.4\n"; + $content .= "\n"; + $content .= "Require all denied\n"; + $content .= "\n\n"; + $content .= "# line below if for Apache 2.2\n"; + $content .= "\n"; + $content .= "deny from all\n"; + $content .= "Satisfy All\n"; + $content .= "\n\n"; + $content .= "# section for Apache 2.2 and 2.4\n"; + $content .= "\n"; + $content .= "IndexIgnore *\n"; + $content .= "\n"; $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); file_put_contents($baseDir . '/.htaccess', $content); @@ -575,6 +579,6 @@ class Setup { // this should really be a JSON file require \OC::$SERVERROOT . '/version.php'; /** @var string $vendor */ - return (string) $vendor; + return (string)$vendor; } } From b4408e4245ca4045df7a5f8fdf6ba9100730fa4f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 5 Nov 2019 16:17:24 +0100 Subject: [PATCH 5/5] fix and improve check of create group result Signed-off-by: Arthur Schiwon --- core/Command/Group/Add.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php index 284cf7a3e9d..4850ec9ce6c 100644 --- a/core/Command/Group/Add.php +++ b/core/Command/Group/Add.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace OC\Core\Command\Group; use OC\Core\Command\Base; +use OCP\IGroup; use OCP\IGroupManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -68,16 +69,17 @@ class Add extends Base { return 1; } else { $group = $this->groupManager->createGroup($gid); - if($group === false) { + if (!$group instanceof IGroup) { $output->writeln('Could not create group'); return 2; } $output->writeln('Created group "' . $group->getGID() . '"'); - $displayName = trim((string) $input->getOption('display-name')); + $displayName = trim((string)$input->getOption('display-name')); if ($displayName !== '') { $group->setDisplayName($displayName); } } + return 0; } }