Passed
Push — master ( c233ac...ceefe0 )
by Joas
14:23 queued 13s
created
core/Command/User/Delete.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -33,53 +33,53 @@
 block discarded – undo
33 33
 use Symfony\Component\Console\Output\OutputInterface;
34 34
 
35 35
 class Delete extends Base {
36
-	/** @var IUserManager */
37
-	protected $userManager;
36
+    /** @var IUserManager */
37
+    protected $userManager;
38 38
 
39
-	/**
40
-	 * @param IUserManager $userManager
41
-	 */
42
-	public function __construct(IUserManager $userManager) {
43
-		$this->userManager = $userManager;
44
-		parent::__construct();
45
-	}
39
+    /**
40
+     * @param IUserManager $userManager
41
+     */
42
+    public function __construct(IUserManager $userManager) {
43
+        $this->userManager = $userManager;
44
+        parent::__construct();
45
+    }
46 46
 
47
-	protected function configure() {
48
-		$this
49
-			->setName('user:delete')
50
-			->setDescription('deletes the specified user')
51
-			->addArgument(
52
-				'uid',
53
-				InputArgument::REQUIRED,
54
-				'the username'
55
-			);
56
-	}
47
+    protected function configure() {
48
+        $this
49
+            ->setName('user:delete')
50
+            ->setDescription('deletes the specified user')
51
+            ->addArgument(
52
+                'uid',
53
+                InputArgument::REQUIRED,
54
+                'the username'
55
+            );
56
+    }
57 57
 
58
-	protected function execute(InputInterface $input, OutputInterface $output): int {
59
-		$user = $this->userManager->get($input->getArgument('uid'));
60
-		if (is_null($user)) {
61
-			$output->writeln('<error>User does not exist</error>');
62
-			return 0;
63
-		}
58
+    protected function execute(InputInterface $input, OutputInterface $output): int {
59
+        $user = $this->userManager->get($input->getArgument('uid'));
60
+        if (is_null($user)) {
61
+            $output->writeln('<error>User does not exist</error>');
62
+            return 0;
63
+        }
64 64
 
65
-		if ($user->delete()) {
66
-			$output->writeln('<info>The specified user was deleted</info>');
67
-			return 0;
68
-		}
65
+        if ($user->delete()) {
66
+            $output->writeln('<info>The specified user was deleted</info>');
67
+            return 0;
68
+        }
69 69
 
70
-		$output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
71
-		return 1;
72
-	}
70
+        $output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
71
+        return 1;
72
+    }
73 73
 
74
-	/**
75
-	 * @param string $argumentName
76
-	 * @param CompletionContext $context
77
-	 * @return string[]
78
-	 */
79
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
80
-		if ($argumentName === 'uid') {
81
-			return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
82
-		}
83
-		return [];
84
-	}
74
+    /**
75
+     * @param string $argumentName
76
+     * @param CompletionContext $context
77
+     * @return string[]
78
+     */
79
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
80
+        if ($argumentName === 'uid') {
81
+            return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
82
+        }
83
+        return [];
84
+    }
85 85
 }
Please login to merge, or discard this patch.
core/Command/User/Disable.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -32,55 +32,55 @@
 block discarded – undo
32 32
 use Symfony\Component\Console\Output\OutputInterface;
33 33
 
34 34
 class Disable extends Base {
35
-	/** @var IUserManager */
36
-	protected $userManager;
35
+    /** @var IUserManager */
36
+    protected $userManager;
37 37
 
38
-	/**
39
-	 * @param IUserManager $userManager
40
-	 */
41
-	public function __construct(IUserManager $userManager) {
42
-		$this->userManager = $userManager;
43
-		parent::__construct();
44
-	}
38
+    /**
39
+     * @param IUserManager $userManager
40
+     */
41
+    public function __construct(IUserManager $userManager) {
42
+        $this->userManager = $userManager;
43
+        parent::__construct();
44
+    }
45 45
 
46
-	protected function configure() {
47
-		$this
48
-			->setName('user:disable')
49
-			->setDescription('disables the specified user')
50
-			->addArgument(
51
-				'uid',
52
-				InputArgument::REQUIRED,
53
-				'the username'
54
-			);
55
-	}
46
+    protected function configure() {
47
+        $this
48
+            ->setName('user:disable')
49
+            ->setDescription('disables the specified user')
50
+            ->addArgument(
51
+                'uid',
52
+                InputArgument::REQUIRED,
53
+                'the username'
54
+            );
55
+    }
56 56
 
57
-	protected function execute(InputInterface $input, OutputInterface $output): int {
58
-		$user = $this->userManager->get($input->getArgument('uid'));
59
-		if (is_null($user)) {
60
-			$output->writeln('<error>User does not exist</error>');
61
-			return 1;
62
-		}
57
+    protected function execute(InputInterface $input, OutputInterface $output): int {
58
+        $user = $this->userManager->get($input->getArgument('uid'));
59
+        if (is_null($user)) {
60
+            $output->writeln('<error>User does not exist</error>');
61
+            return 1;
62
+        }
63 63
 
64
-		$user->setEnabled(false);
65
-		$output->writeln('<info>The specified user is disabled</info>');
66
-		return 0;
67
-	}
64
+        $user->setEnabled(false);
65
+        $output->writeln('<info>The specified user is disabled</info>');
66
+        return 0;
67
+    }
68 68
 
69
-	/**
70
-	 * @param string $argumentName
71
-	 * @param CompletionContext $context
72
-	 * @return string[]
73
-	 */
74
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
75
-		if ($argumentName === 'uid') {
76
-			return array_map(
77
-				static fn (IUser $user) => $user->getUID(),
78
-				array_filter(
79
-					$this->userManager->search($context->getCurrentWord()),
80
-					static fn (IUser $user) => $user->isEnabled()
81
-				)
82
-			);
83
-		}
84
-		return [];
85
-	}
69
+    /**
70
+     * @param string $argumentName
71
+     * @param CompletionContext $context
72
+     * @return string[]
73
+     */
74
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
75
+        if ($argumentName === 'uid') {
76
+            return array_map(
77
+                static fn (IUser $user) => $user->getUID(),
78
+                array_filter(
79
+                    $this->userManager->search($context->getCurrentWord()),
80
+                    static fn (IUser $user) => $user->isEnabled()
81
+                )
82
+            );
83
+        }
84
+        return [];
85
+    }
86 86
 }
Please login to merge, or discard this patch.
core/Command/User/ResetPassword.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -41,110 +41,110 @@
 block discarded – undo
41 41
 
42 42
 class ResetPassword extends Base {
43 43
 
44
-	/** @var IUserManager */
45
-	protected $userManager;
46
-
47
-	public function __construct(IUserManager $userManager) {
48
-		$this->userManager = $userManager;
49
-		parent::__construct();
50
-	}
51
-
52
-	protected function configure() {
53
-		$this
54
-			->setName('user:resetpassword')
55
-			->setDescription('Resets the password of the named user')
56
-			->addArgument(
57
-				'user',
58
-				InputArgument::REQUIRED,
59
-				'Username to reset password'
60
-			)
61
-			->addOption(
62
-				'password-from-env',
63
-				null,
64
-				InputOption::VALUE_NONE,
65
-				'read password from environment variable OC_PASS'
66
-			)
67
-		;
68
-	}
69
-
70
-	protected function execute(InputInterface $input, OutputInterface $output): int {
71
-		$username = $input->getArgument('user');
72
-
73
-		$user = $this->userManager->get($username);
74
-		if (is_null($user)) {
75
-			$output->writeln('<error>User does not exist</error>');
76
-			return 1;
77
-		}
78
-
79
-		if ($input->getOption('password-from-env')) {
80
-			$password = getenv('OC_PASS');
81
-			if (!$password) {
82
-				$output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
83
-				return 1;
84
-			}
85
-		} elseif ($input->isInteractive()) {
86
-			/** @var QuestionHelper $helper */
87
-			$helper = $this->getHelper('question');
88
-
89
-			if (\OCP\App::isEnabled('encryption')) {
90
-				$output->writeln(
91
-					'<error>Warning: Resetting the password when using encryption will result in data loss!</error>'
92
-				);
93
-
94
-				$question = new ConfirmationQuestion('Do you want to continue?');
95
-				if (!$helper->ask($input, $output, $question)) {
96
-					return 1;
97
-				}
98
-			}
99
-
100
-			$question = new Question('Enter a new password: ');
101
-			$question->setHidden(true);
102
-			$password = $helper->ask($input, $output, $question);
103
-
104
-			if ($password === null) {
105
-				$output->writeln("<error>Password cannot be empty!</error>");
106
-				return 1;
107
-			}
108
-
109
-			$question = new Question('Confirm the new password: ');
110
-			$question->setHidden(true);
111
-			$confirm = $helper->ask($input, $output, $question);
112
-
113
-			if ($password !== $confirm) {
114
-				$output->writeln("<error>Passwords did not match!</error>");
115
-				return 1;
116
-			}
117
-		} else {
118
-			$output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>");
119
-			return 1;
120
-		}
121
-
122
-
123
-		try {
124
-			$success = $user->setPassword($password);
125
-		} catch (\Exception $e) {
126
-			$output->writeln('<error>' . $e->getMessage() . '</error>');
127
-			return 1;
128
-		}
129
-
130
-		if ($success) {
131
-			$output->writeln("<info>Successfully reset password for " . $username . "</info>");
132
-		} else {
133
-			$output->writeln("<error>Error while resetting password!</error>");
134
-			return 1;
135
-		}
136
-		return 0;
137
-	}
138
-
139
-	/**
140
-	 * @param string $argumentName
141
-	 * @param CompletionContext $context
142
-	 * @return string[]
143
-	 */
144
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
145
-		if ($argumentName === 'user') {
146
-			return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
147
-		}
148
-		return [];
149
-	}
44
+    /** @var IUserManager */
45
+    protected $userManager;
46
+
47
+    public function __construct(IUserManager $userManager) {
48
+        $this->userManager = $userManager;
49
+        parent::__construct();
50
+    }
51
+
52
+    protected function configure() {
53
+        $this
54
+            ->setName('user:resetpassword')
55
+            ->setDescription('Resets the password of the named user')
56
+            ->addArgument(
57
+                'user',
58
+                InputArgument::REQUIRED,
59
+                'Username to reset password'
60
+            )
61
+            ->addOption(
62
+                'password-from-env',
63
+                null,
64
+                InputOption::VALUE_NONE,
65
+                'read password from environment variable OC_PASS'
66
+            )
67
+        ;
68
+    }
69
+
70
+    protected function execute(InputInterface $input, OutputInterface $output): int {
71
+        $username = $input->getArgument('user');
72
+
73
+        $user = $this->userManager->get($username);
74
+        if (is_null($user)) {
75
+            $output->writeln('<error>User does not exist</error>');
76
+            return 1;
77
+        }
78
+
79
+        if ($input->getOption('password-from-env')) {
80
+            $password = getenv('OC_PASS');
81
+            if (!$password) {
82
+                $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
83
+                return 1;
84
+            }
85
+        } elseif ($input->isInteractive()) {
86
+            /** @var QuestionHelper $helper */
87
+            $helper = $this->getHelper('question');
88
+
89
+            if (\OCP\App::isEnabled('encryption')) {
90
+                $output->writeln(
91
+                    '<error>Warning: Resetting the password when using encryption will result in data loss!</error>'
92
+                );
93
+
94
+                $question = new ConfirmationQuestion('Do you want to continue?');
95
+                if (!$helper->ask($input, $output, $question)) {
96
+                    return 1;
97
+                }
98
+            }
99
+
100
+            $question = new Question('Enter a new password: ');
101
+            $question->setHidden(true);
102
+            $password = $helper->ask($input, $output, $question);
103
+
104
+            if ($password === null) {
105
+                $output->writeln("<error>Password cannot be empty!</error>");
106
+                return 1;
107
+            }
108
+
109
+            $question = new Question('Confirm the new password: ');
110
+            $question->setHidden(true);
111
+            $confirm = $helper->ask($input, $output, $question);
112
+
113
+            if ($password !== $confirm) {
114
+                $output->writeln("<error>Passwords did not match!</error>");
115
+                return 1;
116
+            }
117
+        } else {
118
+            $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>");
119
+            return 1;
120
+        }
121
+
122
+
123
+        try {
124
+            $success = $user->setPassword($password);
125
+        } catch (\Exception $e) {
126
+            $output->writeln('<error>' . $e->getMessage() . '</error>');
127
+            return 1;
128
+        }
129
+
130
+        if ($success) {
131
+            $output->writeln("<info>Successfully reset password for " . $username . "</info>");
132
+        } else {
133
+            $output->writeln("<error>Error while resetting password!</error>");
134
+            return 1;
135
+        }
136
+        return 0;
137
+    }
138
+
139
+    /**
140
+     * @param string $argumentName
141
+     * @param CompletionContext $context
142
+     * @return string[]
143
+     */
144
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
145
+        if ($argumentName === 'user') {
146
+            return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
147
+        }
148
+        return [];
149
+    }
150 150
 }
Please login to merge, or discard this patch.
core/Command/User/Info.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -35,92 +35,92 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Info extends Base {
38
-	/** @var IUserManager */
39
-	protected $userManager;
40
-	/** @var IGroupManager */
41
-	protected $groupManager;
38
+    /** @var IUserManager */
39
+    protected $userManager;
40
+    /** @var IGroupManager */
41
+    protected $groupManager;
42 42
 
43
-	/**
44
-	 * @param IUserManager $userManager
45
-	 * @param IGroupManager $groupManager
46
-	 */
47
-	public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
48
-		$this->userManager = $userManager;
49
-		$this->groupManager = $groupManager;
50
-		parent::__construct();
51
-	}
43
+    /**
44
+     * @param IUserManager $userManager
45
+     * @param IGroupManager $groupManager
46
+     */
47
+    public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
48
+        $this->userManager = $userManager;
49
+        $this->groupManager = $groupManager;
50
+        parent::__construct();
51
+    }
52 52
 
53
-	protected function configure() {
54
-		$this
55
-			->setName('user:info')
56
-			->setDescription('show user info')
57
-			->addArgument(
58
-				'user',
59
-				InputArgument::REQUIRED,
60
-				'user to show'
61
-			)->addOption(
62
-				'output',
63
-				null,
64
-				InputOption::VALUE_OPTIONAL,
65
-				'Output format (plain, json or json_pretty, default is plain)',
66
-				$this->defaultOutputFormat
67
-			);
68
-	}
53
+    protected function configure() {
54
+        $this
55
+            ->setName('user:info')
56
+            ->setDescription('show user info')
57
+            ->addArgument(
58
+                'user',
59
+                InputArgument::REQUIRED,
60
+                'user to show'
61
+            )->addOption(
62
+                'output',
63
+                null,
64
+                InputOption::VALUE_OPTIONAL,
65
+                'Output format (plain, json or json_pretty, default is plain)',
66
+                $this->defaultOutputFormat
67
+            );
68
+    }
69 69
 
70
-	protected function execute(InputInterface $input, OutputInterface $output): int {
71
-		$user = $this->userManager->get($input->getArgument('user'));
72
-		if (is_null($user)) {
73
-			$output->writeln('<error>user not found</error>');
74
-			return 1;
75
-		}
76
-		$groups = $this->groupManager->getUserGroupIds($user);
77
-		$data = [
78
-			'user_id' => $user->getUID(),
79
-			'display_name' => $user->getDisplayName(),
80
-			'email' => (string)$user->getSystemEMailAddress(),
81
-			'cloud_id' => $user->getCloudId(),
82
-			'enabled' => $user->isEnabled(),
83
-			'groups' => $groups,
84
-			'quota' => $user->getQuota(),
85
-			'storage' => $this->getStorageInfo($user),
86
-			'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601
87
-			'user_directory' => $user->getHome(),
88
-			'backend' => $user->getBackendClassName()
89
-		];
90
-		$this->writeArrayInOutputFormat($input, $output, $data);
91
-		return 0;
92
-	}
70
+    protected function execute(InputInterface $input, OutputInterface $output): int {
71
+        $user = $this->userManager->get($input->getArgument('user'));
72
+        if (is_null($user)) {
73
+            $output->writeln('<error>user not found</error>');
74
+            return 1;
75
+        }
76
+        $groups = $this->groupManager->getUserGroupIds($user);
77
+        $data = [
78
+            'user_id' => $user->getUID(),
79
+            'display_name' => $user->getDisplayName(),
80
+            'email' => (string)$user->getSystemEMailAddress(),
81
+            'cloud_id' => $user->getCloudId(),
82
+            'enabled' => $user->isEnabled(),
83
+            'groups' => $groups,
84
+            'quota' => $user->getQuota(),
85
+            'storage' => $this->getStorageInfo($user),
86
+            'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601
87
+            'user_directory' => $user->getHome(),
88
+            'backend' => $user->getBackendClassName()
89
+        ];
90
+        $this->writeArrayInOutputFormat($input, $output, $data);
91
+        return 0;
92
+    }
93 93
 
94
-	/**
95
-	 * @param IUser $user
96
-	 * @return array
97
-	 */
98
-	protected function getStorageInfo(IUser $user): array {
99
-		\OC_Util::tearDownFS();
100
-		\OC_Util::setupFS($user->getUID());
101
-		try {
102
-			$storage = \OC_Helper::getStorageInfo('/');
103
-		} catch (\OCP\Files\NotFoundException $e) {
104
-			return [];
105
-		}
106
-		return [
107
-			'free' => $storage['free'],
108
-			'used' => $storage['used'],
109
-			'total' => $storage['total'],
110
-			'relative' => $storage['relative'],
111
-			'quota' => $storage['quota'],
112
-		];
113
-	}
94
+    /**
95
+     * @param IUser $user
96
+     * @return array
97
+     */
98
+    protected function getStorageInfo(IUser $user): array {
99
+        \OC_Util::tearDownFS();
100
+        \OC_Util::setupFS($user->getUID());
101
+        try {
102
+            $storage = \OC_Helper::getStorageInfo('/');
103
+        } catch (\OCP\Files\NotFoundException $e) {
104
+            return [];
105
+        }
106
+        return [
107
+            'free' => $storage['free'],
108
+            'used' => $storage['used'],
109
+            'total' => $storage['total'],
110
+            'relative' => $storage['relative'],
111
+            'quota' => $storage['quota'],
112
+        ];
113
+    }
114 114
 
115
-	/**
116
-	 * @param string $argumentName
117
-	 * @param CompletionContext $context
118
-	 * @return string[]
119
-	 */
120
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
121
-		if ($argumentName === 'user') {
122
-			return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
123
-		}
124
-		return [];
125
-	}
115
+    /**
116
+     * @param string $argumentName
117
+     * @param CompletionContext $context
118
+     * @return string[]
119
+     */
120
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
121
+        if ($argumentName === 'user') {
122
+            return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
123
+        }
124
+        return [];
125
+    }
126 126
 }
Please login to merge, or discard this patch.
core/Command/User/Enable.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -32,55 +32,55 @@
 block discarded – undo
32 32
 use Symfony\Component\Console\Output\OutputInterface;
33 33
 
34 34
 class Enable extends Base {
35
-	/** @var IUserManager */
36
-	protected $userManager;
35
+    /** @var IUserManager */
36
+    protected $userManager;
37 37
 
38
-	/**
39
-	 * @param IUserManager $userManager
40
-	 */
41
-	public function __construct(IUserManager $userManager) {
42
-		$this->userManager = $userManager;
43
-		parent::__construct();
44
-	}
38
+    /**
39
+     * @param IUserManager $userManager
40
+     */
41
+    public function __construct(IUserManager $userManager) {
42
+        $this->userManager = $userManager;
43
+        parent::__construct();
44
+    }
45 45
 
46
-	protected function configure() {
47
-		$this
48
-			->setName('user:enable')
49
-			->setDescription('enables the specified user')
50
-			->addArgument(
51
-				'uid',
52
-				InputArgument::REQUIRED,
53
-				'the username'
54
-			);
55
-	}
46
+    protected function configure() {
47
+        $this
48
+            ->setName('user:enable')
49
+            ->setDescription('enables the specified user')
50
+            ->addArgument(
51
+                'uid',
52
+                InputArgument::REQUIRED,
53
+                'the username'
54
+            );
55
+    }
56 56
 
57
-	protected function execute(InputInterface $input, OutputInterface $output): int {
58
-		$user = $this->userManager->get($input->getArgument('uid'));
59
-		if (is_null($user)) {
60
-			$output->writeln('<error>User does not exist</error>');
61
-			return 1;
62
-		}
57
+    protected function execute(InputInterface $input, OutputInterface $output): int {
58
+        $user = $this->userManager->get($input->getArgument('uid'));
59
+        if (is_null($user)) {
60
+            $output->writeln('<error>User does not exist</error>');
61
+            return 1;
62
+        }
63 63
 
64
-		$user->setEnabled(true);
65
-		$output->writeln('<info>The specified user is enabled</info>');
66
-		return 0;
67
-	}
64
+        $user->setEnabled(true);
65
+        $output->writeln('<info>The specified user is enabled</info>');
66
+        return 0;
67
+    }
68 68
 
69
-	/**
70
-	 * @param string $argumentName
71
-	 * @param CompletionContext $context
72
-	 * @return string[]
73
-	 */
74
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
75
-		if ($argumentName === 'uid') {
76
-			return array_map(
77
-				static fn (IUser $user) => $user->getUID(),
78
-				array_filter(
79
-					$this->userManager->search($context->getCurrentWord()),
80
-					static fn (IUser $user) => !$user->isEnabled()
81
-				)
82
-			);
83
-		}
84
-		return [];
85
-	}
69
+    /**
70
+     * @param string $argumentName
71
+     * @param CompletionContext $context
72
+     * @return string[]
73
+     */
74
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
75
+        if ($argumentName === 'uid') {
76
+            return array_map(
77
+                static fn (IUser $user) => $user->getUID(),
78
+                array_filter(
79
+                    $this->userManager->search($context->getCurrentWord()),
80
+                    static fn (IUser $user) => !$user->isEnabled()
81
+                )
82
+            );
83
+        }
84
+        return [];
85
+    }
86 86
 }
Please login to merge, or discard this patch.
core/Command/User/Setting.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -36,247 +36,247 @@
 block discarded – undo
36 36
 use Symfony\Component\Console\Output\OutputInterface;
37 37
 
38 38
 class Setting extends Base {
39
-	/** @var IUserManager */
40
-	protected $userManager;
39
+    /** @var IUserManager */
40
+    protected $userManager;
41 41
 
42
-	/** @var IConfig */
43
-	protected $config;
42
+    /** @var IConfig */
43
+    protected $config;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param IConfig $config
48
-	 */
49
-	public function __construct(IUserManager $userManager, IConfig $config) {
50
-		parent::__construct();
51
-		$this->userManager = $userManager;
52
-		$this->config = $config;
53
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param IConfig $config
48
+     */
49
+    public function __construct(IUserManager $userManager, IConfig $config) {
50
+        parent::__construct();
51
+        $this->userManager = $userManager;
52
+        $this->config = $config;
53
+    }
54 54
 
55
-	protected function configure() {
56
-		parent::configure();
57
-		$this
58
-			->setName('user:setting')
59
-			->setDescription('Read and modify user settings')
60
-			->addArgument(
61
-				'uid',
62
-				InputArgument::REQUIRED,
63
-				'User ID used to login'
64
-			)
65
-			->addArgument(
66
-				'app',
67
-				InputArgument::OPTIONAL,
68
-				'Restrict the settings to a given app',
69
-				''
70
-			)
71
-			->addArgument(
72
-				'key',
73
-				InputArgument::OPTIONAL,
74
-				'Setting key to set, get or delete',
75
-				''
76
-			)
77
-			->addOption(
78
-				'ignore-missing-user',
79
-				null,
80
-				InputOption::VALUE_NONE,
81
-				'Use this option to ignore errors when the user does not exist'
82
-			)
55
+    protected function configure() {
56
+        parent::configure();
57
+        $this
58
+            ->setName('user:setting')
59
+            ->setDescription('Read and modify user settings')
60
+            ->addArgument(
61
+                'uid',
62
+                InputArgument::REQUIRED,
63
+                'User ID used to login'
64
+            )
65
+            ->addArgument(
66
+                'app',
67
+                InputArgument::OPTIONAL,
68
+                'Restrict the settings to a given app',
69
+                ''
70
+            )
71
+            ->addArgument(
72
+                'key',
73
+                InputArgument::OPTIONAL,
74
+                'Setting key to set, get or delete',
75
+                ''
76
+            )
77
+            ->addOption(
78
+                'ignore-missing-user',
79
+                null,
80
+                InputOption::VALUE_NONE,
81
+                'Use this option to ignore errors when the user does not exist'
82
+            )
83 83
 
84
-			// Get
85
-			->addOption(
86
-				'default-value',
87
-				null,
88
-				InputOption::VALUE_REQUIRED,
89
-				'(Only applicable on get) If no default value is set and the config does not exist, the command will exit with 1'
90
-			)
84
+            // Get
85
+            ->addOption(
86
+                'default-value',
87
+                null,
88
+                InputOption::VALUE_REQUIRED,
89
+                '(Only applicable on get) If no default value is set and the config does not exist, the command will exit with 1'
90
+            )
91 91
 
92
-			// Set
93
-			->addArgument(
94
-				'value',
95
-				InputArgument::OPTIONAL,
96
-				'The new value of the setting',
97
-				null
98
-			)
99
-			->addOption(
100
-				'update-only',
101
-				null,
102
-				InputOption::VALUE_NONE,
103
-				'Only updates the value, if it is not set before, it is not being added'
104
-			)
92
+            // Set
93
+            ->addArgument(
94
+                'value',
95
+                InputArgument::OPTIONAL,
96
+                'The new value of the setting',
97
+                null
98
+            )
99
+            ->addOption(
100
+                'update-only',
101
+                null,
102
+                InputOption::VALUE_NONE,
103
+                'Only updates the value, if it is not set before, it is not being added'
104
+            )
105 105
 
106
-			// Delete
107
-			->addOption(
108
-				'delete',
109
-				null,
110
-				InputOption::VALUE_NONE,
111
-				'Specify this option to delete the config'
112
-			)
113
-			->addOption(
114
-				'error-if-not-exists',
115
-				null,
116
-				InputOption::VALUE_NONE,
117
-				'Checks whether the setting exists before deleting it'
118
-			)
119
-		;
120
-	}
106
+            // Delete
107
+            ->addOption(
108
+                'delete',
109
+                null,
110
+                InputOption::VALUE_NONE,
111
+                'Specify this option to delete the config'
112
+            )
113
+            ->addOption(
114
+                'error-if-not-exists',
115
+                null,
116
+                InputOption::VALUE_NONE,
117
+                'Checks whether the setting exists before deleting it'
118
+            )
119
+        ;
120
+    }
121 121
 
122
-	protected function checkInput(InputInterface $input) {
123
-		$uid = $input->getArgument('uid');
124
-		if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) {
125
-			throw new \InvalidArgumentException('The user "' . $uid . '" does not exist.');
126
-		}
122
+    protected function checkInput(InputInterface $input) {
123
+        $uid = $input->getArgument('uid');
124
+        if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) {
125
+            throw new \InvalidArgumentException('The user "' . $uid . '" does not exist.');
126
+        }
127 127
 
128
-		if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) {
129
-			throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.');
130
-		}
128
+        if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) {
129
+            throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.');
130
+        }
131 131
 
132
-		if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) {
133
-			throw new \InvalidArgumentException('The value argument can only be used when specifying a key.');
134
-		}
135
-		if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) {
136
-			throw new \InvalidArgumentException('The value argument can not be used together with "default-value".');
137
-		}
138
-		if ($input->getOption('update-only') && $input->getArgument('value') === null) {
139
-			throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".');
140
-		}
132
+        if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) {
133
+            throw new \InvalidArgumentException('The value argument can only be used when specifying a key.');
134
+        }
135
+        if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) {
136
+            throw new \InvalidArgumentException('The value argument can not be used together with "default-value".');
137
+        }
138
+        if ($input->getOption('update-only') && $input->getArgument('value') === null) {
139
+            throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".');
140
+        }
141 141
 
142
-		if ($input->getArgument('key') === '' && $input->getOption('delete')) {
143
-			throw new \InvalidArgumentException('The "delete" option can only be used when specifying a key.');
144
-		}
145
-		if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) {
146
-			throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".');
147
-		}
148
-		if ($input->getOption('delete') && $input->getArgument('value') !== null) {
149
-			throw new \InvalidArgumentException('The "delete" option can not be used together with "value".');
150
-		}
151
-		if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) {
152
-			throw new \InvalidArgumentException('The "error-if-not-exists" option can only be used together with "delete".');
153
-		}
154
-	}
142
+        if ($input->getArgument('key') === '' && $input->getOption('delete')) {
143
+            throw new \InvalidArgumentException('The "delete" option can only be used when specifying a key.');
144
+        }
145
+        if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) {
146
+            throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".');
147
+        }
148
+        if ($input->getOption('delete') && $input->getArgument('value') !== null) {
149
+            throw new \InvalidArgumentException('The "delete" option can not be used together with "value".');
150
+        }
151
+        if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) {
152
+            throw new \InvalidArgumentException('The "error-if-not-exists" option can only be used together with "delete".');
153
+        }
154
+    }
155 155
 
156
-	protected function execute(InputInterface $input, OutputInterface $output): int {
157
-		try {
158
-			$this->checkInput($input);
159
-		} catch (\InvalidArgumentException $e) {
160
-			$output->writeln('<error>' . $e->getMessage() . '</error>');
161
-			return 1;
162
-		}
156
+    protected function execute(InputInterface $input, OutputInterface $output): int {
157
+        try {
158
+            $this->checkInput($input);
159
+        } catch (\InvalidArgumentException $e) {
160
+            $output->writeln('<error>' . $e->getMessage() . '</error>');
161
+            return 1;
162
+        }
163 163
 
164
-		$uid = $input->getArgument('uid');
165
-		$app = $input->getArgument('app');
166
-		$key = $input->getArgument('key');
164
+        $uid = $input->getArgument('uid');
165
+        $app = $input->getArgument('app');
166
+        $key = $input->getArgument('key');
167 167
 
168
-		if ($key !== '') {
169
-			$value = $this->config->getUserValue($uid, $app, $key, null);
170
-			if ($input->getArgument('value') !== null) {
171
-				if ($input->hasParameterOption('--update-only') && $value === null) {
172
-					$output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
173
-					return 1;
174
-				}
168
+        if ($key !== '') {
169
+            $value = $this->config->getUserValue($uid, $app, $key, null);
170
+            if ($input->getArgument('value') !== null) {
171
+                if ($input->hasParameterOption('--update-only') && $value === null) {
172
+                    $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
173
+                    return 1;
174
+                }
175 175
 
176
-				if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
177
-					$user = $this->userManager->get($uid);
178
-					if ($user instanceof IUser) {
179
-						if ($key === 'email') {
180
-							$user->setEMailAddress($input->getArgument('value'));
181
-						} elseif ($key === 'display_name') {
182
-							if (!$user->setDisplayName($input->getArgument('value'))) {
183
-								if ($user->getDisplayName() === $input->getArgument('value')) {
184
-									$output->writeln('<error>New and old display name are the same</error>');
185
-								} elseif ($input->getArgument('value') === '') {
186
-									$output->writeln('<error>New display name can\'t be empty</error>');
187
-								} else {
188
-									$output->writeln('<error>Could not set display name</error>');
189
-								}
190
-								return 1;
191
-							}
192
-						}
193
-						// setEmailAddress and setDisplayName both internally set the value
194
-						return 0;
195
-					}
196
-				}
176
+                if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
177
+                    $user = $this->userManager->get($uid);
178
+                    if ($user instanceof IUser) {
179
+                        if ($key === 'email') {
180
+                            $user->setEMailAddress($input->getArgument('value'));
181
+                        } elseif ($key === 'display_name') {
182
+                            if (!$user->setDisplayName($input->getArgument('value'))) {
183
+                                if ($user->getDisplayName() === $input->getArgument('value')) {
184
+                                    $output->writeln('<error>New and old display name are the same</error>');
185
+                                } elseif ($input->getArgument('value') === '') {
186
+                                    $output->writeln('<error>New display name can\'t be empty</error>');
187
+                                } else {
188
+                                    $output->writeln('<error>Could not set display name</error>');
189
+                                }
190
+                                return 1;
191
+                            }
192
+                        }
193
+                        // setEmailAddress and setDisplayName both internally set the value
194
+                        return 0;
195
+                    }
196
+                }
197 197
 
198
-				$this->config->setUserValue($uid, $app, $key, $input->getArgument('value'));
199
-				return 0;
200
-			} elseif ($input->hasParameterOption('--delete')) {
201
-				if ($input->hasParameterOption('--error-if-not-exists') && $value === null) {
202
-					$output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
203
-					return 1;
204
-				}
198
+                $this->config->setUserValue($uid, $app, $key, $input->getArgument('value'));
199
+                return 0;
200
+            } elseif ($input->hasParameterOption('--delete')) {
201
+                if ($input->hasParameterOption('--error-if-not-exists') && $value === null) {
202
+                    $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
203
+                    return 1;
204
+                }
205 205
 
206
-				if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
207
-					$user = $this->userManager->get($uid);
208
-					if ($user instanceof IUser) {
209
-						if ($key === 'email') {
210
-							$user->setEMailAddress('');
211
-							// setEmailAddress already deletes the value
212
-							return 0;
213
-						} elseif ($key === 'display_name') {
214
-							$output->writeln('<error>Display name can\'t be deleted.</error>');
215
-							return 1;
216
-						}
217
-					}
218
-				}
206
+                if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
207
+                    $user = $this->userManager->get($uid);
208
+                    if ($user instanceof IUser) {
209
+                        if ($key === 'email') {
210
+                            $user->setEMailAddress('');
211
+                            // setEmailAddress already deletes the value
212
+                            return 0;
213
+                        } elseif ($key === 'display_name') {
214
+                            $output->writeln('<error>Display name can\'t be deleted.</error>');
215
+                            return 1;
216
+                        }
217
+                    }
218
+                }
219 219
 
220
-				$this->config->deleteUserValue($uid, $app, $key);
221
-				return 0;
222
-			} elseif ($value !== null) {
223
-				$output->writeln($value);
224
-				return 0;
225
-			} elseif ($input->hasParameterOption('--default-value')) {
226
-				$output->writeln($input->getOption('default-value'));
227
-				return 0;
228
-			} else {
229
-				if ($app === 'settings' && $key === 'display_name') {
230
-					$user = $this->userManager->get($uid);
231
-					$output->writeln($user->getDisplayName());
232
-					return 0;
233
-				}
234
-				$output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
235
-				return 1;
236
-			}
237
-		} else {
238
-			$settings = $this->getUserSettings($uid, $app);
239
-			$this->writeArrayInOutputFormat($input, $output, $settings);
240
-			return 0;
241
-		}
242
-	}
220
+                $this->config->deleteUserValue($uid, $app, $key);
221
+                return 0;
222
+            } elseif ($value !== null) {
223
+                $output->writeln($value);
224
+                return 0;
225
+            } elseif ($input->hasParameterOption('--default-value')) {
226
+                $output->writeln($input->getOption('default-value'));
227
+                return 0;
228
+            } else {
229
+                if ($app === 'settings' && $key === 'display_name') {
230
+                    $user = $this->userManager->get($uid);
231
+                    $output->writeln($user->getDisplayName());
232
+                    return 0;
233
+                }
234
+                $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
235
+                return 1;
236
+            }
237
+        } else {
238
+            $settings = $this->getUserSettings($uid, $app);
239
+            $this->writeArrayInOutputFormat($input, $output, $settings);
240
+            return 0;
241
+        }
242
+    }
243 243
 
244
-	protected function getUserSettings($uid, $app) {
245
-		$settings = $this->config->getAllUserValues($uid);
246
-		if ($app !== '') {
247
-			if (isset($settings[$app])) {
248
-				$settings = [$app => $settings[$app]];
249
-			} else {
250
-				$settings = [];
251
-			}
252
-		}
244
+    protected function getUserSettings($uid, $app) {
245
+        $settings = $this->config->getAllUserValues($uid);
246
+        if ($app !== '') {
247
+            if (isset($settings[$app])) {
248
+                $settings = [$app => $settings[$app]];
249
+            } else {
250
+                $settings = [];
251
+            }
252
+        }
253 253
 
254
-		$user = $this->userManager->get($uid);
255
-		$settings['settings']['display_name'] = $user->getDisplayName();
254
+        $user = $this->userManager->get($uid);
255
+        $settings['settings']['display_name'] = $user->getDisplayName();
256 256
 
257
-		return $settings;
258
-	}
257
+        return $settings;
258
+    }
259 259
 
260
-	/**
261
-	 * @param string $argumentName
262
-	 * @param CompletionContext $context
263
-	 * @return string[]
264
-	 */
265
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
266
-		if ($argumentName === 'uid') {
267
-			return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
268
-		}
269
-		if ($argumentName === 'app') {
270
-			$userId = $context->getWordAtIndex($context->getWordIndex() - 1);
271
-			$settings = $this->getUserSettings($userId, '');
272
-			return array_keys($settings);
273
-		}
274
-		if ($argumentName === 'key') {
275
-			$userId = $context->getWordAtIndex($context->getWordIndex() - 2);
276
-			$app = $context->getWordAtIndex($context->getWordIndex() - 1);
277
-			$settings = $this->getUserSettings($userId, $app);
278
-			return array_keys($settings[$app]);
279
-		}
280
-		return [];
281
-	}
260
+    /**
261
+     * @param string $argumentName
262
+     * @param CompletionContext $context
263
+     * @return string[]
264
+     */
265
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
266
+        if ($argumentName === 'uid') {
267
+            return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
268
+        }
269
+        if ($argumentName === 'app') {
270
+            $userId = $context->getWordAtIndex($context->getWordIndex() - 1);
271
+            $settings = $this->getUserSettings($userId, '');
272
+            return array_keys($settings);
273
+        }
274
+        if ($argumentName === 'key') {
275
+            $userId = $context->getWordAtIndex($context->getWordIndex() - 2);
276
+            $app = $context->getWordAtIndex($context->getWordIndex() - 1);
277
+            $settings = $this->getUserSettings($userId, $app);
278
+            return array_keys($settings[$app]);
279
+        }
280
+        return [];
281
+    }
282 282
 }
Please login to merge, or discard this patch.
core/Command/User/LastSeen.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -34,57 +34,57 @@
 block discarded – undo
34 34
 use Symfony\Component\Console\Output\OutputInterface;
35 35
 
36 36
 class LastSeen extends Base {
37
-	/** @var IUserManager */
38
-	protected $userManager;
37
+    /** @var IUserManager */
38
+    protected $userManager;
39 39
 
40
-	/**
41
-	 * @param IUserManager $userManager
42
-	 */
43
-	public function __construct(IUserManager $userManager) {
44
-		$this->userManager = $userManager;
45
-		parent::__construct();
46
-	}
40
+    /**
41
+     * @param IUserManager $userManager
42
+     */
43
+    public function __construct(IUserManager $userManager) {
44
+        $this->userManager = $userManager;
45
+        parent::__construct();
46
+    }
47 47
 
48
-	protected function configure() {
49
-		$this
50
-			->setName('user:lastseen')
51
-			->setDescription('shows when the user was logged in last time')
52
-			->addArgument(
53
-				'uid',
54
-				InputArgument::REQUIRED,
55
-				'the username'
56
-			);
57
-	}
48
+    protected function configure() {
49
+        $this
50
+            ->setName('user:lastseen')
51
+            ->setDescription('shows when the user was logged in last time')
52
+            ->addArgument(
53
+                'uid',
54
+                InputArgument::REQUIRED,
55
+                'the username'
56
+            );
57
+    }
58 58
 
59
-	protected function execute(InputInterface $input, OutputInterface $output): int {
60
-		$user = $this->userManager->get($input->getArgument('uid'));
61
-		if (is_null($user)) {
62
-			$output->writeln('<error>User does not exist</error>');
63
-			return 1;
64
-		}
59
+    protected function execute(InputInterface $input, OutputInterface $output): int {
60
+        $user = $this->userManager->get($input->getArgument('uid'));
61
+        if (is_null($user)) {
62
+            $output->writeln('<error>User does not exist</error>');
63
+            return 1;
64
+        }
65 65
 
66
-		$lastLogin = $user->getLastLogin();
67
-		if ($lastLogin === 0) {
68
-			$output->writeln('User ' . $user->getUID() .
69
-				' has never logged in, yet.');
70
-		} else {
71
-			$date = new \DateTime();
72
-			$date->setTimestamp($lastLogin);
73
-			$output->writeln($user->getUID() .
74
-				'`s last login: ' . $date->format('d.m.Y H:i'));
75
-		}
76
-		return 0;
77
-	}
66
+        $lastLogin = $user->getLastLogin();
67
+        if ($lastLogin === 0) {
68
+            $output->writeln('User ' . $user->getUID() .
69
+                ' has never logged in, yet.');
70
+        } else {
71
+            $date = new \DateTime();
72
+            $date->setTimestamp($lastLogin);
73
+            $output->writeln($user->getUID() .
74
+                '`s last login: ' . $date->format('d.m.Y H:i'));
75
+        }
76
+        return 0;
77
+    }
78 78
 
79
-	/**
80
-	 * @param string $argumentName
81
-	 * @param CompletionContext $context
82
-	 * @return string[]
83
-	 */
84
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
85
-		if ($argumentName === 'uid') {
86
-			return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
87
-		}
88
-		return [];
89
-	}
79
+    /**
80
+     * @param string $argumentName
81
+     * @param CompletionContext $context
82
+     * @return string[]
83
+     */
84
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
85
+        if ($argumentName === 'uid') {
86
+            return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
87
+        }
88
+        return [];
89
+    }
90 90
 }
Please login to merge, or discard this patch.
core/Command/Group/Delete.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -35,57 +35,57 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Delete extends Base {
38
-	/** @var IGroupManager */
39
-	protected $groupManager;
38
+    /** @var IGroupManager */
39
+    protected $groupManager;
40 40
 
41
-	/**
42
-	 * @param IGroupManager $groupManager
43
-	 */
44
-	public function __construct(IGroupManager $groupManager) {
45
-		$this->groupManager = $groupManager;
46
-		parent::__construct();
47
-	}
41
+    /**
42
+     * @param IGroupManager $groupManager
43
+     */
44
+    public function __construct(IGroupManager $groupManager) {
45
+        $this->groupManager = $groupManager;
46
+        parent::__construct();
47
+    }
48 48
 
49
-	protected function configure() {
50
-		$this
51
-			->setName('group:delete')
52
-			->setDescription('Remove a group')
53
-			->addArgument(
54
-				'groupid',
55
-				InputArgument::REQUIRED,
56
-				'Group name'
57
-			);
58
-	}
49
+    protected function configure() {
50
+        $this
51
+            ->setName('group:delete')
52
+            ->setDescription('Remove a group')
53
+            ->addArgument(
54
+                'groupid',
55
+                InputArgument::REQUIRED,
56
+                'Group name'
57
+            );
58
+    }
59 59
 
60
-	protected function execute(InputInterface $input, OutputInterface $output): int {
61
-		$gid = $input->getArgument('groupid');
62
-		if ($gid === 'admin') {
63
-			$output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
64
-			return 1;
65
-		}
66
-		if (!$this->groupManager->groupExists($gid)) {
67
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
68
-			return 1;
69
-		}
70
-		$group = $this->groupManager->get($gid);
71
-		if ($group->delete()) {
72
-			$output->writeln('Group "' . $gid . '" was removed');
73
-		} else {
74
-			$output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>');
75
-			return 1;
76
-		}
77
-		return 0;
78
-	}
60
+    protected function execute(InputInterface $input, OutputInterface $output): int {
61
+        $gid = $input->getArgument('groupid');
62
+        if ($gid === 'admin') {
63
+            $output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
64
+            return 1;
65
+        }
66
+        if (!$this->groupManager->groupExists($gid)) {
67
+            $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
68
+            return 1;
69
+        }
70
+        $group = $this->groupManager->get($gid);
71
+        if ($group->delete()) {
72
+            $output->writeln('Group "' . $gid . '" was removed');
73
+        } else {
74
+            $output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>');
75
+            return 1;
76
+        }
77
+        return 0;
78
+    }
79 79
 
80
-	/**
81
-	 * @param string $argumentName
82
-	 * @param CompletionContext $context
83
-	 * @return string[]
84
-	 */
85
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
86
-		if ($argumentName === 'groupid') {
87
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
88
-		}
89
-		return [];
90
-	}
80
+    /**
81
+     * @param string $argumentName
82
+     * @param CompletionContext $context
83
+     * @return string[]
84
+     */
85
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
86
+        if ($argumentName === 'groupid') {
87
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
88
+        }
89
+        return [];
90
+    }
91 91
 }
Please login to merge, or discard this patch.
core/Command/Group/AddUser.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -34,71 +34,71 @@
 block discarded – undo
34 34
 use Symfony\Component\Console\Output\OutputInterface;
35 35
 
36 36
 class AddUser extends Base {
37
-	/** @var IUserManager */
38
-	protected $userManager;
39
-	/** @var IGroupManager */
40
-	protected $groupManager;
37
+    /** @var IUserManager */
38
+    protected $userManager;
39
+    /** @var IGroupManager */
40
+    protected $groupManager;
41 41
 
42
-	/**
43
-	 * @param IUserManager $userManager
44
-	 * @param IGroupManager $groupManager
45
-	 */
46
-	public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
47
-		$this->userManager = $userManager;
48
-		$this->groupManager = $groupManager;
49
-		parent::__construct();
50
-	}
42
+    /**
43
+     * @param IUserManager $userManager
44
+     * @param IGroupManager $groupManager
45
+     */
46
+    public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
47
+        $this->userManager = $userManager;
48
+        $this->groupManager = $groupManager;
49
+        parent::__construct();
50
+    }
51 51
 
52
-	protected function configure() {
53
-		$this
54
-			->setName('group:adduser')
55
-			->setDescription('add a user to a group')
56
-			->addArgument(
57
-				'group',
58
-				InputArgument::REQUIRED,
59
-				'group to add the user to'
60
-			)->addArgument(
61
-				'user',
62
-				InputArgument::REQUIRED,
63
-				'user to add to the group'
64
-			);
65
-	}
52
+    protected function configure() {
53
+        $this
54
+            ->setName('group:adduser')
55
+            ->setDescription('add a user to a group')
56
+            ->addArgument(
57
+                'group',
58
+                InputArgument::REQUIRED,
59
+                'group to add the user to'
60
+            )->addArgument(
61
+                'user',
62
+                InputArgument::REQUIRED,
63
+                'user to add to the group'
64
+            );
65
+    }
66 66
 
67
-	protected function execute(InputInterface $input, OutputInterface $output): int {
68
-		$group = $this->groupManager->get($input->getArgument('group'));
69
-		if (is_null($group)) {
70
-			$output->writeln('<error>group not found</error>');
71
-			return 1;
72
-		}
73
-		$user = $this->userManager->get($input->getArgument('user'));
74
-		if (is_null($user)) {
75
-			$output->writeln('<error>user not found</error>');
76
-			return 1;
77
-		}
78
-		$group->addUser($user);
79
-		return 0;
80
-	}
67
+    protected function execute(InputInterface $input, OutputInterface $output): int {
68
+        $group = $this->groupManager->get($input->getArgument('group'));
69
+        if (is_null($group)) {
70
+            $output->writeln('<error>group not found</error>');
71
+            return 1;
72
+        }
73
+        $user = $this->userManager->get($input->getArgument('user'));
74
+        if (is_null($user)) {
75
+            $output->writeln('<error>user not found</error>');
76
+            return 1;
77
+        }
78
+        $group->addUser($user);
79
+        return 0;
80
+    }
81 81
 
82
-	/**
83
-	 * @param string $argumentName
84
-	 * @param CompletionContext $context
85
-	 * @return string[]
86
-	 */
87
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
88
-		if ($argumentName === 'group') {
89
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
90
-		}
91
-		if ($argumentName === 'user') {
92
-			$groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
93
-			$group = $this->groupManager->get($groupId);
94
-			if ($group === null) {
95
-				return [];
96
-			}
82
+    /**
83
+     * @param string $argumentName
84
+     * @param CompletionContext $context
85
+     * @return string[]
86
+     */
87
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
88
+        if ($argumentName === 'group') {
89
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
90
+        }
91
+        if ($argumentName === 'user') {
92
+            $groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
93
+            $group = $this->groupManager->get($groupId);
94
+            if ($group === null) {
95
+                return [];
96
+            }
97 97
 
98
-			$members = array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
99
-			$users = array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
100
-			return array_diff($users, $members);
101
-		}
102
-		return [];
103
-	}
98
+            $members = array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
99
+            $users = array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
100
+            return array_diff($users, $members);
101
+        }
102
+        return [];
103
+    }
104 104
 }
Please login to merge, or discard this patch.