@@ -34,34 +34,34 @@ |
||
| 34 | 34 | * @package OC\Core\Command\Integrity |
| 35 | 35 | */ |
| 36 | 36 | class CheckCore extends Base { |
| 37 | - /** |
|
| 38 | - * @var Checker |
|
| 39 | - */ |
|
| 40 | - private $checker; |
|
| 37 | + /** |
|
| 38 | + * @var Checker |
|
| 39 | + */ |
|
| 40 | + private $checker; |
|
| 41 | 41 | |
| 42 | - public function __construct(Checker $checker) { |
|
| 43 | - parent::__construct(); |
|
| 44 | - $this->checker = $checker; |
|
| 45 | - } |
|
| 42 | + public function __construct(Checker $checker) { |
|
| 43 | + parent::__construct(); |
|
| 44 | + $this->checker = $checker; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritdoc } |
|
| 49 | - */ |
|
| 50 | - protected function configure() { |
|
| 51 | - parent::configure(); |
|
| 52 | - $this |
|
| 53 | - ->setName('integrity:check-core') |
|
| 54 | - ->setDescription('Check integrity of core code using a signature.'); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritdoc } |
|
| 49 | + */ |
|
| 50 | + protected function configure() { |
|
| 51 | + parent::configure(); |
|
| 52 | + $this |
|
| 53 | + ->setName('integrity:check-core') |
|
| 54 | + ->setDescription('Check integrity of core code using a signature.'); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * {@inheritdoc } |
|
| 59 | - */ |
|
| 60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 61 | - $result = $this->checker->verifyCoreSignature(); |
|
| 62 | - $this->writeArrayInOutputFormat($input, $output, $result); |
|
| 63 | - if (count($result)>0){ |
|
| 64 | - return 1; |
|
| 65 | - } |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * {@inheritdoc } |
|
| 59 | + */ |
|
| 60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 61 | + $result = $this->checker->verifyCoreSignature(); |
|
| 62 | + $this->writeArrayInOutputFormat($input, $output, $result); |
|
| 63 | + if (count($result)>0){ |
|
| 64 | + return 1; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 61 | 61 | $result = $this->checker->verifyCoreSignature(); |
| 62 | 62 | $this->writeArrayInOutputFormat($input, $output, $result); |
| 63 | - if (count($result)>0){ |
|
| 63 | + if (count($result) > 0) { |
|
| 64 | 64 | return 1; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -32,44 +32,44 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Input\InputArgument; |
| 33 | 33 | |
| 34 | 34 | class LastSeen extends Command { |
| 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:lastseen') |
|
| 49 | - ->setDescription('shows when the user was logged in last time') |
|
| 50 | - ->addArgument( |
|
| 51 | - 'uid', |
|
| 52 | - InputArgument::REQUIRED, |
|
| 53 | - 'the username' |
|
| 54 | - ); |
|
| 55 | - } |
|
| 46 | + protected function configure() { |
|
| 47 | + $this |
|
| 48 | + ->setName('user:lastseen') |
|
| 49 | + ->setDescription('shows when the user was logged in last time') |
|
| 50 | + ->addArgument( |
|
| 51 | + 'uid', |
|
| 52 | + InputArgument::REQUIRED, |
|
| 53 | + 'the username' |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 58 | - $user = $this->userManager->get($input->getArgument('uid')); |
|
| 59 | - if(is_null($user)) { |
|
| 60 | - $output->writeln('<error>User does not exist</error>'); |
|
| 61 | - return; |
|
| 62 | - } |
|
| 57 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 58 | + $user = $this->userManager->get($input->getArgument('uid')); |
|
| 59 | + if(is_null($user)) { |
|
| 60 | + $output->writeln('<error>User does not exist</error>'); |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $lastLogin = $user->getLastLogin(); |
|
| 65 | - if($lastLogin === 0) { |
|
| 66 | - $output->writeln('User ' . $user->getUID() . |
|
| 67 | - ' has never logged in, yet.'); |
|
| 68 | - } else { |
|
| 69 | - $date = new \DateTime(); |
|
| 70 | - $date->setTimestamp($lastLogin); |
|
| 71 | - $output->writeln($user->getUID() . |
|
| 72 | - '`s last login: ' . $date->format('d.m.Y H:i')); |
|
| 73 | - } |
|
| 74 | - } |
|
| 64 | + $lastLogin = $user->getLastLogin(); |
|
| 65 | + if($lastLogin === 0) { |
|
| 66 | + $output->writeln('User ' . $user->getUID() . |
|
| 67 | + ' has never logged in, yet.'); |
|
| 68 | + } else { |
|
| 69 | + $date = new \DateTime(); |
|
| 70 | + $date->setTimestamp($lastLogin); |
|
| 71 | + $output->writeln($user->getUID() . |
|
| 72 | + '`s last login: ' . $date->format('d.m.Y H:i')); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -56,20 +56,20 @@ |
||
| 56 | 56 | |
| 57 | 57 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 58 | 58 | $user = $this->userManager->get($input->getArgument('uid')); |
| 59 | - if(is_null($user)) { |
|
| 59 | + if (is_null($user)) { |
|
| 60 | 60 | $output->writeln('<error>User does not exist</error>'); |
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $lastLogin = $user->getLastLogin(); |
| 65 | - if($lastLogin === 0) { |
|
| 66 | - $output->writeln('User ' . $user->getUID() . |
|
| 65 | + if ($lastLogin === 0) { |
|
| 66 | + $output->writeln('User '.$user->getUID(). |
|
| 67 | 67 | ' has never logged in, yet.'); |
| 68 | 68 | } else { |
| 69 | 69 | $date = new \DateTime(); |
| 70 | 70 | $date->setTimestamp($lastLogin); |
| 71 | - $output->writeln($user->getUID() . |
|
| 72 | - '`s last login: ' . $date->format('d.m.Y H:i')); |
|
| 71 | + $output->writeln($user->getUID(). |
|
| 72 | + '`s last login: '.$date->format('d.m.Y H:i')); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -32,58 +32,58 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class ListCommand 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:list') |
|
| 49 | - ->setDescription('list configured users') |
|
| 50 | - ->addOption( |
|
| 51 | - 'limit', |
|
| 52 | - 'l', |
|
| 53 | - InputOption::VALUE_OPTIONAL, |
|
| 54 | - 'Number of users to retrieve', |
|
| 55 | - 500 |
|
| 56 | - )->addOption( |
|
| 57 | - 'offset', |
|
| 58 | - 'o', |
|
| 59 | - InputOption::VALUE_OPTIONAL, |
|
| 60 | - 'Offset for retrieving users', |
|
| 61 | - 0 |
|
| 62 | - )->addOption( |
|
| 63 | - 'output', |
|
| 64 | - null, |
|
| 65 | - InputOption::VALUE_OPTIONAL, |
|
| 66 | - 'Output format (plain, json or json_pretty, default is plain)', |
|
| 67 | - $this->defaultOutputFormat |
|
| 68 | - ); |
|
| 69 | - } |
|
| 46 | + protected function configure() { |
|
| 47 | + $this |
|
| 48 | + ->setName('user:list') |
|
| 49 | + ->setDescription('list configured users') |
|
| 50 | + ->addOption( |
|
| 51 | + 'limit', |
|
| 52 | + 'l', |
|
| 53 | + InputOption::VALUE_OPTIONAL, |
|
| 54 | + 'Number of users to retrieve', |
|
| 55 | + 500 |
|
| 56 | + )->addOption( |
|
| 57 | + 'offset', |
|
| 58 | + 'o', |
|
| 59 | + InputOption::VALUE_OPTIONAL, |
|
| 60 | + 'Offset for retrieving users', |
|
| 61 | + 0 |
|
| 62 | + )->addOption( |
|
| 63 | + 'output', |
|
| 64 | + null, |
|
| 65 | + InputOption::VALUE_OPTIONAL, |
|
| 66 | + 'Output format (plain, json or json_pretty, default is plain)', |
|
| 67 | + $this->defaultOutputFormat |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 72 | - $users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
| 73 | - $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users)); |
|
| 74 | - } |
|
| 71 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 72 | + $users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
| 73 | + $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users)); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @param IUser[] $users |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - private function formatUsers(array $users) { |
|
| 81 | - $keys = array_map(function (IUser $user) { |
|
| 82 | - return $user->getUID(); |
|
| 83 | - }, $users); |
|
| 84 | - $values = array_map(function (IUser $user) { |
|
| 85 | - return $user->getDisplayName(); |
|
| 86 | - }, $users); |
|
| 87 | - return array_combine($keys, $values); |
|
| 88 | - } |
|
| 76 | + /** |
|
| 77 | + * @param IUser[] $users |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + private function formatUsers(array $users) { |
|
| 81 | + $keys = array_map(function (IUser $user) { |
|
| 82 | + return $user->getUID(); |
|
| 83 | + }, $users); |
|
| 84 | + $values = array_map(function (IUser $user) { |
|
| 85 | + return $user->getDisplayName(); |
|
| 86 | + }, $users); |
|
| 87 | + return array_combine($keys, $values); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 72 | - $users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset')); |
|
| 72 | + $users = $this->userManager->search('', (int) $input->getOption('limit'), (int) $input->getOption('offset')); |
|
| 73 | 73 | $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users)); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | private function formatUsers(array $users) { |
| 81 | - $keys = array_map(function (IUser $user) { |
|
| 81 | + $keys = array_map(function(IUser $user) { |
|
| 82 | 82 | return $user->getUID(); |
| 83 | 83 | }, $users); |
| 84 | - $values = array_map(function (IUser $user) { |
|
| 84 | + $values = array_map(function(IUser $user) { |
|
| 85 | 85 | return $user->getDisplayName(); |
| 86 | 86 | }, $users); |
| 87 | 87 | return array_combine($keys, $values); |
@@ -33,212 +33,212 @@ |
||
| 33 | 33 | use Symfony\Component\Console\Input\InputArgument; |
| 34 | 34 | |
| 35 | 35 | class Setting extends Base { |
| 36 | - /** @var IUserManager */ |
|
| 37 | - protected $userManager; |
|
| 38 | - |
|
| 39 | - /** @var IConfig */ |
|
| 40 | - protected $config; |
|
| 41 | - |
|
| 42 | - /** @var IDBConnection */ |
|
| 43 | - protected $connection; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param IUserManager $userManager |
|
| 47 | - * @param IConfig $config |
|
| 48 | - * @param IDBConnection $connection |
|
| 49 | - */ |
|
| 50 | - public function __construct(IUserManager $userManager, IConfig $config, IDBConnection $connection) { |
|
| 51 | - parent::__construct(); |
|
| 52 | - $this->userManager = $userManager; |
|
| 53 | - $this->config = $config; |
|
| 54 | - $this->connection = $connection; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - protected function configure() { |
|
| 58 | - parent::configure(); |
|
| 59 | - $this |
|
| 60 | - ->setName('user:setting') |
|
| 61 | - ->setDescription('Read and modify user settings') |
|
| 62 | - ->addArgument( |
|
| 63 | - 'uid', |
|
| 64 | - InputArgument::REQUIRED, |
|
| 65 | - 'User ID used to login' |
|
| 66 | - ) |
|
| 67 | - ->addArgument( |
|
| 68 | - 'app', |
|
| 69 | - InputArgument::OPTIONAL, |
|
| 70 | - 'Restrict the settings to a given app', |
|
| 71 | - '' |
|
| 72 | - ) |
|
| 73 | - ->addArgument( |
|
| 74 | - 'key', |
|
| 75 | - InputArgument::OPTIONAL, |
|
| 76 | - 'Setting key to set, get or delete', |
|
| 77 | - '' |
|
| 78 | - ) |
|
| 79 | - ->addOption( |
|
| 80 | - 'ignore-missing-user', |
|
| 81 | - null, |
|
| 82 | - InputOption::VALUE_NONE, |
|
| 83 | - 'Use this option to ignore errors when the user does not exist' |
|
| 84 | - ) |
|
| 85 | - |
|
| 86 | - // Get |
|
| 87 | - ->addOption( |
|
| 88 | - 'default-value', |
|
| 89 | - null, |
|
| 90 | - InputOption::VALUE_REQUIRED, |
|
| 91 | - '(Only applicable on get) If no default value is set and the config does not exist, the command will exit with 1' |
|
| 92 | - ) |
|
| 93 | - |
|
| 94 | - // Set |
|
| 95 | - ->addArgument( |
|
| 96 | - 'value', |
|
| 97 | - InputArgument::OPTIONAL, |
|
| 98 | - 'The new value of the setting', |
|
| 99 | - null |
|
| 100 | - ) |
|
| 101 | - ->addOption( |
|
| 102 | - 'update-only', |
|
| 103 | - null, |
|
| 104 | - InputOption::VALUE_NONE, |
|
| 105 | - 'Only updates the value, if it is not set before, it is not being added' |
|
| 106 | - ) |
|
| 107 | - |
|
| 108 | - // Delete |
|
| 109 | - ->addOption( |
|
| 110 | - 'delete', |
|
| 111 | - null, |
|
| 112 | - InputOption::VALUE_NONE, |
|
| 113 | - 'Specify this option to delete the config' |
|
| 114 | - ) |
|
| 115 | - ->addOption( |
|
| 116 | - 'error-if-not-exists', |
|
| 117 | - null, |
|
| 118 | - InputOption::VALUE_NONE, |
|
| 119 | - 'Checks whether the setting exists before deleting it' |
|
| 120 | - ) |
|
| 121 | - ; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - protected function checkInput(InputInterface $input) { |
|
| 125 | - $uid = $input->getArgument('uid'); |
|
| 126 | - if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) { |
|
| 127 | - throw new \InvalidArgumentException('The user "' . $uid . '" does not exists.'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) { |
|
| 131 | - throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) { |
|
| 135 | - throw new \InvalidArgumentException('The value argument can only be used when specifying a key.'); |
|
| 136 | - } |
|
| 137 | - if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) { |
|
| 138 | - throw new \InvalidArgumentException('The value argument can not be used together with "default-value".'); |
|
| 139 | - } |
|
| 140 | - if ($input->getOption('update-only') && $input->getArgument('value') === null) { |
|
| 141 | - throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($input->getArgument('key') === '' && $input->getOption('delete')) { |
|
| 145 | - throw new \InvalidArgumentException('The "delete" option can only be used when specifying a key.'); |
|
| 146 | - } |
|
| 147 | - if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) { |
|
| 148 | - throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".'); |
|
| 149 | - } |
|
| 150 | - if ($input->getOption('delete') && $input->getArgument('value') !== null) { |
|
| 151 | - throw new \InvalidArgumentException('The "delete" option can not be used together with "value".'); |
|
| 152 | - } |
|
| 153 | - if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) { |
|
| 154 | - throw new \InvalidArgumentException('The "error-if-not-exists" option can only be used together with "delete".'); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 159 | - try { |
|
| 160 | - $this->checkInput($input); |
|
| 161 | - } catch (\InvalidArgumentException $e) { |
|
| 162 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 163 | - return 1; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $uid = $input->getArgument('uid'); |
|
| 167 | - $app = $input->getArgument('app'); |
|
| 168 | - $key = $input->getArgument('key'); |
|
| 169 | - |
|
| 170 | - if ($key !== '') { |
|
| 171 | - $value = $this->config->getUserValue($uid, $app, $key, null); |
|
| 172 | - if ($input->getArgument('value') !== null) { |
|
| 173 | - if ($input->hasParameterOption('--update-only') && $value === null) { |
|
| 174 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 175 | - return 1; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($app === 'settings' && $key === 'email') { |
|
| 179 | - $user = $this->userManager->get($uid); |
|
| 180 | - if ($user instanceof IUser) { |
|
| 181 | - $user->setEMailAddress($input->getArgument('value')); |
|
| 182 | - return 0; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $this->config->setUserValue($uid, $app, $key, $input->getArgument('value')); |
|
| 187 | - return 0; |
|
| 188 | - |
|
| 189 | - } else if ($input->hasParameterOption('--delete')) { |
|
| 190 | - if ($input->hasParameterOption('--error-if-not-exists') && $value === null) { |
|
| 191 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 192 | - return 1; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($app === 'settings' && $key === 'email') { |
|
| 196 | - $user = $this->userManager->get($uid); |
|
| 197 | - if ($user instanceof IUser) { |
|
| 198 | - $user->setEMailAddress(''); |
|
| 199 | - return 0; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $this->config->deleteUserValue($uid, $app, $key); |
|
| 204 | - return 0; |
|
| 205 | - |
|
| 206 | - } else if ($value !== null) { |
|
| 207 | - $output->writeln($value); |
|
| 208 | - return 0; |
|
| 209 | - } else { |
|
| 210 | - if ($input->hasParameterOption('--default-value')) { |
|
| 211 | - $output->writeln($input->getOption('default-value')); |
|
| 212 | - return 0; |
|
| 213 | - } else { |
|
| 214 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 215 | - return 1; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } else { |
|
| 219 | - $settings = $this->getUserSettings($uid, $app); |
|
| 220 | - $this->writeArrayInOutputFormat($input, $output, $settings); |
|
| 221 | - return 0; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - protected function getUserSettings($uid, $app) { |
|
| 226 | - $query = $this->connection->getQueryBuilder(); |
|
| 227 | - $query->select('*') |
|
| 228 | - ->from('preferences') |
|
| 229 | - ->where($query->expr()->eq('userid', $query->createNamedParameter($uid))); |
|
| 230 | - |
|
| 231 | - if ($app !== '') { |
|
| 232 | - $query->andWhere($query->expr()->eq('appid', $query->createNamedParameter($app))); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $result = $query->execute(); |
|
| 236 | - $settings = []; |
|
| 237 | - while ($row = $result->fetch()) { |
|
| 238 | - $settings[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
| 239 | - } |
|
| 240 | - $result->closeCursor(); |
|
| 241 | - |
|
| 242 | - return $settings; |
|
| 243 | - } |
|
| 36 | + /** @var IUserManager */ |
|
| 37 | + protected $userManager; |
|
| 38 | + |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + protected $config; |
|
| 41 | + |
|
| 42 | + /** @var IDBConnection */ |
|
| 43 | + protected $connection; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param IUserManager $userManager |
|
| 47 | + * @param IConfig $config |
|
| 48 | + * @param IDBConnection $connection |
|
| 49 | + */ |
|
| 50 | + public function __construct(IUserManager $userManager, IConfig $config, IDBConnection $connection) { |
|
| 51 | + parent::__construct(); |
|
| 52 | + $this->userManager = $userManager; |
|
| 53 | + $this->config = $config; |
|
| 54 | + $this->connection = $connection; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + protected function configure() { |
|
| 58 | + parent::configure(); |
|
| 59 | + $this |
|
| 60 | + ->setName('user:setting') |
|
| 61 | + ->setDescription('Read and modify user settings') |
|
| 62 | + ->addArgument( |
|
| 63 | + 'uid', |
|
| 64 | + InputArgument::REQUIRED, |
|
| 65 | + 'User ID used to login' |
|
| 66 | + ) |
|
| 67 | + ->addArgument( |
|
| 68 | + 'app', |
|
| 69 | + InputArgument::OPTIONAL, |
|
| 70 | + 'Restrict the settings to a given app', |
|
| 71 | + '' |
|
| 72 | + ) |
|
| 73 | + ->addArgument( |
|
| 74 | + 'key', |
|
| 75 | + InputArgument::OPTIONAL, |
|
| 76 | + 'Setting key to set, get or delete', |
|
| 77 | + '' |
|
| 78 | + ) |
|
| 79 | + ->addOption( |
|
| 80 | + 'ignore-missing-user', |
|
| 81 | + null, |
|
| 82 | + InputOption::VALUE_NONE, |
|
| 83 | + 'Use this option to ignore errors when the user does not exist' |
|
| 84 | + ) |
|
| 85 | + |
|
| 86 | + // Get |
|
| 87 | + ->addOption( |
|
| 88 | + 'default-value', |
|
| 89 | + null, |
|
| 90 | + InputOption::VALUE_REQUIRED, |
|
| 91 | + '(Only applicable on get) If no default value is set and the config does not exist, the command will exit with 1' |
|
| 92 | + ) |
|
| 93 | + |
|
| 94 | + // Set |
|
| 95 | + ->addArgument( |
|
| 96 | + 'value', |
|
| 97 | + InputArgument::OPTIONAL, |
|
| 98 | + 'The new value of the setting', |
|
| 99 | + null |
|
| 100 | + ) |
|
| 101 | + ->addOption( |
|
| 102 | + 'update-only', |
|
| 103 | + null, |
|
| 104 | + InputOption::VALUE_NONE, |
|
| 105 | + 'Only updates the value, if it is not set before, it is not being added' |
|
| 106 | + ) |
|
| 107 | + |
|
| 108 | + // Delete |
|
| 109 | + ->addOption( |
|
| 110 | + 'delete', |
|
| 111 | + null, |
|
| 112 | + InputOption::VALUE_NONE, |
|
| 113 | + 'Specify this option to delete the config' |
|
| 114 | + ) |
|
| 115 | + ->addOption( |
|
| 116 | + 'error-if-not-exists', |
|
| 117 | + null, |
|
| 118 | + InputOption::VALUE_NONE, |
|
| 119 | + 'Checks whether the setting exists before deleting it' |
|
| 120 | + ) |
|
| 121 | + ; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + protected function checkInput(InputInterface $input) { |
|
| 125 | + $uid = $input->getArgument('uid'); |
|
| 126 | + if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) { |
|
| 127 | + throw new \InvalidArgumentException('The user "' . $uid . '" does not exists.'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) { |
|
| 131 | + throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) { |
|
| 135 | + throw new \InvalidArgumentException('The value argument can only be used when specifying a key.'); |
|
| 136 | + } |
|
| 137 | + if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) { |
|
| 138 | + throw new \InvalidArgumentException('The value argument can not be used together with "default-value".'); |
|
| 139 | + } |
|
| 140 | + if ($input->getOption('update-only') && $input->getArgument('value') === null) { |
|
| 141 | + throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($input->getArgument('key') === '' && $input->getOption('delete')) { |
|
| 145 | + throw new \InvalidArgumentException('The "delete" option can only be used when specifying a key.'); |
|
| 146 | + } |
|
| 147 | + if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) { |
|
| 148 | + throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".'); |
|
| 149 | + } |
|
| 150 | + if ($input->getOption('delete') && $input->getArgument('value') !== null) { |
|
| 151 | + throw new \InvalidArgumentException('The "delete" option can not be used together with "value".'); |
|
| 152 | + } |
|
| 153 | + if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) { |
|
| 154 | + throw new \InvalidArgumentException('The "error-if-not-exists" option can only be used together with "delete".'); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 159 | + try { |
|
| 160 | + $this->checkInput($input); |
|
| 161 | + } catch (\InvalidArgumentException $e) { |
|
| 162 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 163 | + return 1; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $uid = $input->getArgument('uid'); |
|
| 167 | + $app = $input->getArgument('app'); |
|
| 168 | + $key = $input->getArgument('key'); |
|
| 169 | + |
|
| 170 | + if ($key !== '') { |
|
| 171 | + $value = $this->config->getUserValue($uid, $app, $key, null); |
|
| 172 | + if ($input->getArgument('value') !== null) { |
|
| 173 | + if ($input->hasParameterOption('--update-only') && $value === null) { |
|
| 174 | + $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 175 | + return 1; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($app === 'settings' && $key === 'email') { |
|
| 179 | + $user = $this->userManager->get($uid); |
|
| 180 | + if ($user instanceof IUser) { |
|
| 181 | + $user->setEMailAddress($input->getArgument('value')); |
|
| 182 | + return 0; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $this->config->setUserValue($uid, $app, $key, $input->getArgument('value')); |
|
| 187 | + return 0; |
|
| 188 | + |
|
| 189 | + } else if ($input->hasParameterOption('--delete')) { |
|
| 190 | + if ($input->hasParameterOption('--error-if-not-exists') && $value === null) { |
|
| 191 | + $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 192 | + return 1; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($app === 'settings' && $key === 'email') { |
|
| 196 | + $user = $this->userManager->get($uid); |
|
| 197 | + if ($user instanceof IUser) { |
|
| 198 | + $user->setEMailAddress(''); |
|
| 199 | + return 0; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $this->config->deleteUserValue($uid, $app, $key); |
|
| 204 | + return 0; |
|
| 205 | + |
|
| 206 | + } else if ($value !== null) { |
|
| 207 | + $output->writeln($value); |
|
| 208 | + return 0; |
|
| 209 | + } else { |
|
| 210 | + if ($input->hasParameterOption('--default-value')) { |
|
| 211 | + $output->writeln($input->getOption('default-value')); |
|
| 212 | + return 0; |
|
| 213 | + } else { |
|
| 214 | + $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 215 | + return 1; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $settings = $this->getUserSettings($uid, $app); |
|
| 220 | + $this->writeArrayInOutputFormat($input, $output, $settings); |
|
| 221 | + return 0; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + protected function getUserSettings($uid, $app) { |
|
| 226 | + $query = $this->connection->getQueryBuilder(); |
|
| 227 | + $query->select('*') |
|
| 228 | + ->from('preferences') |
|
| 229 | + ->where($query->expr()->eq('userid', $query->createNamedParameter($uid))); |
|
| 230 | + |
|
| 231 | + if ($app !== '') { |
|
| 232 | + $query->andWhere($query->expr()->eq('appid', $query->createNamedParameter($app))); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $result = $query->execute(); |
|
| 236 | + $settings = []; |
|
| 237 | + while ($row = $result->fetch()) { |
|
| 238 | + $settings[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
| 239 | + } |
|
| 240 | + $result->closeCursor(); |
|
| 241 | + |
|
| 242 | + return $settings; |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | protected function checkInput(InputInterface $input) { |
| 125 | 125 | $uid = $input->getArgument('uid'); |
| 126 | 126 | if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) { |
| 127 | - throw new \InvalidArgumentException('The user "' . $uid . '" does not exists.'); |
|
| 127 | + throw new \InvalidArgumentException('The user "'.$uid.'" does not exists.'); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) { |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | try { |
| 160 | 160 | $this->checkInput($input); |
| 161 | 161 | } catch (\InvalidArgumentException $e) { |
| 162 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 162 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 163 | 163 | return 1; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $value = $this->config->getUserValue($uid, $app, $key, null); |
| 172 | 172 | if ($input->getArgument('value') !== null) { |
| 173 | 173 | if ($input->hasParameterOption('--update-only') && $value === null) { |
| 174 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 174 | + $output->writeln('<error>The setting does not exist for user "'.$uid.'".</error>'); |
|
| 175 | 175 | return 1; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | } else if ($input->hasParameterOption('--delete')) { |
| 190 | 190 | if ($input->hasParameterOption('--error-if-not-exists') && $value === null) { |
| 191 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 191 | + $output->writeln('<error>The setting does not exist for user "'.$uid.'".</error>'); |
|
| 192 | 192 | return 1; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $output->writeln($input->getOption('default-value')); |
| 212 | 212 | return 0; |
| 213 | 213 | } else { |
| 214 | - $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
|
| 214 | + $output->writeln('<error>The setting does not exist for user "'.$uid.'".</error>'); |
|
| 215 | 215 | return 1; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -30,36 +30,36 @@ |
||
| 30 | 30 | use Symfony\Component\Console\Input\InputArgument; |
| 31 | 31 | |
| 32 | 32 | class Enable extends Command { |
| 33 | - /** @var IUserManager */ |
|
| 34 | - protected $userManager; |
|
| 33 | + /** @var IUserManager */ |
|
| 34 | + protected $userManager; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param IUserManager $userManager |
|
| 38 | - */ |
|
| 39 | - public function __construct(IUserManager $userManager) { |
|
| 40 | - $this->userManager = $userManager; |
|
| 41 | - parent::__construct(); |
|
| 42 | - } |
|
| 36 | + /** |
|
| 37 | + * @param IUserManager $userManager |
|
| 38 | + */ |
|
| 39 | + public function __construct(IUserManager $userManager) { |
|
| 40 | + $this->userManager = $userManager; |
|
| 41 | + parent::__construct(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - protected function configure() { |
|
| 45 | - $this |
|
| 46 | - ->setName('user:enable') |
|
| 47 | - ->setDescription('enables the specified user') |
|
| 48 | - ->addArgument( |
|
| 49 | - 'uid', |
|
| 50 | - InputArgument::REQUIRED, |
|
| 51 | - 'the username' |
|
| 52 | - ); |
|
| 53 | - } |
|
| 44 | + protected function configure() { |
|
| 45 | + $this |
|
| 46 | + ->setName('user:enable') |
|
| 47 | + ->setDescription('enables the specified user') |
|
| 48 | + ->addArgument( |
|
| 49 | + 'uid', |
|
| 50 | + InputArgument::REQUIRED, |
|
| 51 | + 'the username' |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | - $user = $this->userManager->get($input->getArgument('uid')); |
|
| 57 | - if (is_null($user)) { |
|
| 58 | - $output->writeln('<error>User does not exist</error>'); |
|
| 59 | - return; |
|
| 60 | - } |
|
| 55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | + $user = $this->userManager->get($input->getArgument('uid')); |
|
| 57 | + if (is_null($user)) { |
|
| 58 | + $output->writeln('<error>User does not exist</error>'); |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $user->setEnabled(true); |
|
| 63 | - $output->writeln('<info>The specified user is enabled</info>'); |
|
| 64 | - } |
|
| 62 | + $user->setEnabled(true); |
|
| 63 | + $output->writeln('<info>The specified user is enabled</info>'); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -30,36 +30,36 @@ |
||
| 30 | 30 | use Symfony\Component\Console\Input\InputArgument; |
| 31 | 31 | |
| 32 | 32 | class Disable extends Command { |
| 33 | - /** @var IUserManager */ |
|
| 34 | - protected $userManager; |
|
| 33 | + /** @var IUserManager */ |
|
| 34 | + protected $userManager; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param IUserManager $userManager |
|
| 38 | - */ |
|
| 39 | - public function __construct(IUserManager $userManager) { |
|
| 40 | - $this->userManager = $userManager; |
|
| 41 | - parent::__construct(); |
|
| 42 | - } |
|
| 36 | + /** |
|
| 37 | + * @param IUserManager $userManager |
|
| 38 | + */ |
|
| 39 | + public function __construct(IUserManager $userManager) { |
|
| 40 | + $this->userManager = $userManager; |
|
| 41 | + parent::__construct(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - protected function configure() { |
|
| 45 | - $this |
|
| 46 | - ->setName('user:disable') |
|
| 47 | - ->setDescription('disables the specified user') |
|
| 48 | - ->addArgument( |
|
| 49 | - 'uid', |
|
| 50 | - InputArgument::REQUIRED, |
|
| 51 | - 'the username' |
|
| 52 | - ); |
|
| 53 | - } |
|
| 44 | + protected function configure() { |
|
| 45 | + $this |
|
| 46 | + ->setName('user:disable') |
|
| 47 | + ->setDescription('disables the specified user') |
|
| 48 | + ->addArgument( |
|
| 49 | + 'uid', |
|
| 50 | + InputArgument::REQUIRED, |
|
| 51 | + 'the username' |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | - $user = $this->userManager->get($input->getArgument('uid')); |
|
| 57 | - if (is_null($user)) { |
|
| 58 | - $output->writeln('<error>User does not exist</error>'); |
|
| 59 | - return; |
|
| 60 | - } |
|
| 55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | + $user = $this->userManager->get($input->getArgument('uid')); |
|
| 57 | + if (is_null($user)) { |
|
| 58 | + $output->writeln('<error>User does not exist</error>'); |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $user->setEnabled(false); |
|
| 63 | - $output->writeln('<info>The specified user is disabled</info>'); |
|
| 64 | - } |
|
| 62 | + $user->setEnabled(false); |
|
| 63 | + $output->writeln('<info>The specified user is disabled</info>'); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -117,12 +117,12 @@ |
||
| 117 | 117 | try { |
| 118 | 118 | $success = $user->setPassword($password); |
| 119 | 119 | } catch (\Exception $e) { |
| 120 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 120 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 121 | 121 | return 1; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if ($success) { |
| 125 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 125 | + $output->writeln("<info>Successfully reset password for ".$username."</info>"); |
|
| 126 | 126 | } else { |
| 127 | 127 | $output->writeln("<error>Error while resetting password!</error>"); |
| 128 | 128 | return 1; |
@@ -39,98 +39,98 @@ |
||
| 39 | 39 | |
| 40 | 40 | class ResetPassword extends Command { |
| 41 | 41 | |
| 42 | - /** @var IUserManager */ |
|
| 43 | - protected $userManager; |
|
| 44 | - |
|
| 45 | - public function __construct(IUserManager $userManager) { |
|
| 46 | - $this->userManager = $userManager; |
|
| 47 | - parent::__construct(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - protected function configure() { |
|
| 51 | - $this |
|
| 52 | - ->setName('user:resetpassword') |
|
| 53 | - ->setDescription('Resets the password of the named user') |
|
| 54 | - ->addArgument( |
|
| 55 | - 'user', |
|
| 56 | - InputArgument::REQUIRED, |
|
| 57 | - 'Username to reset password' |
|
| 58 | - ) |
|
| 59 | - ->addOption( |
|
| 60 | - 'password-from-env', |
|
| 61 | - null, |
|
| 62 | - InputOption::VALUE_NONE, |
|
| 63 | - 'read password from environment variable OC_PASS' |
|
| 64 | - ) |
|
| 65 | - ; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 69 | - $username = $input->getArgument('user'); |
|
| 70 | - |
|
| 71 | - /** @var $user \OCP\IUser */ |
|
| 72 | - $user = $this->userManager->get($username); |
|
| 73 | - if (is_null($user)) { |
|
| 74 | - $output->writeln('<error>User does not exist</error>'); |
|
| 75 | - return 1; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ($input->getOption('password-from-env')) { |
|
| 79 | - $password = getenv('OC_PASS'); |
|
| 80 | - if (!$password) { |
|
| 81 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 82 | - return 1; |
|
| 83 | - } |
|
| 84 | - } elseif ($input->isInteractive()) { |
|
| 85 | - /** @var QuestionHelper $helper */ |
|
| 86 | - $helper = $this->getHelper('question'); |
|
| 87 | - |
|
| 88 | - if (\OCP\App::isEnabled('encryption')) { |
|
| 89 | - $output->writeln( |
|
| 90 | - '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 94 | - if (!$helper->ask($input, $output, $question)) { |
|
| 95 | - return 1; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $question = new Question('Enter a new password: '); |
|
| 100 | - $question->setHidden(true); |
|
| 101 | - $password = $helper->ask($input, $output, $question); |
|
| 102 | - |
|
| 103 | - if ($password === null) { |
|
| 104 | - $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 105 | - return 1; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $question = new Question('Confirm the new password: '); |
|
| 109 | - $question->setHidden(true); |
|
| 110 | - $confirm = $helper->ask($input, $output, $question); |
|
| 111 | - |
|
| 112 | - if ($password !== $confirm) { |
|
| 113 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
| 114 | - return 1; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 118 | - return 1; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - try { |
|
| 123 | - $success = $user->setPassword($password); |
|
| 124 | - } catch (\Exception $e) { |
|
| 125 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 126 | - return 1; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($success) { |
|
| 130 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 131 | - } else { |
|
| 132 | - $output->writeln("<error>Error while resetting password!</error>"); |
|
| 133 | - return 1; |
|
| 134 | - } |
|
| 135 | - } |
|
| 42 | + /** @var IUserManager */ |
|
| 43 | + protected $userManager; |
|
| 44 | + |
|
| 45 | + public function __construct(IUserManager $userManager) { |
|
| 46 | + $this->userManager = $userManager; |
|
| 47 | + parent::__construct(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + protected function configure() { |
|
| 51 | + $this |
|
| 52 | + ->setName('user:resetpassword') |
|
| 53 | + ->setDescription('Resets the password of the named user') |
|
| 54 | + ->addArgument( |
|
| 55 | + 'user', |
|
| 56 | + InputArgument::REQUIRED, |
|
| 57 | + 'Username to reset password' |
|
| 58 | + ) |
|
| 59 | + ->addOption( |
|
| 60 | + 'password-from-env', |
|
| 61 | + null, |
|
| 62 | + InputOption::VALUE_NONE, |
|
| 63 | + 'read password from environment variable OC_PASS' |
|
| 64 | + ) |
|
| 65 | + ; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 69 | + $username = $input->getArgument('user'); |
|
| 70 | + |
|
| 71 | + /** @var $user \OCP\IUser */ |
|
| 72 | + $user = $this->userManager->get($username); |
|
| 73 | + if (is_null($user)) { |
|
| 74 | + $output->writeln('<error>User does not exist</error>'); |
|
| 75 | + return 1; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ($input->getOption('password-from-env')) { |
|
| 79 | + $password = getenv('OC_PASS'); |
|
| 80 | + if (!$password) { |
|
| 81 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 82 | + return 1; |
|
| 83 | + } |
|
| 84 | + } elseif ($input->isInteractive()) { |
|
| 85 | + /** @var QuestionHelper $helper */ |
|
| 86 | + $helper = $this->getHelper('question'); |
|
| 87 | + |
|
| 88 | + if (\OCP\App::isEnabled('encryption')) { |
|
| 89 | + $output->writeln( |
|
| 90 | + '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 94 | + if (!$helper->ask($input, $output, $question)) { |
|
| 95 | + return 1; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $question = new Question('Enter a new password: '); |
|
| 100 | + $question->setHidden(true); |
|
| 101 | + $password = $helper->ask($input, $output, $question); |
|
| 102 | + |
|
| 103 | + if ($password === null) { |
|
| 104 | + $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 105 | + return 1; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $question = new Question('Confirm the new password: '); |
|
| 109 | + $question->setHidden(true); |
|
| 110 | + $confirm = $helper->ask($input, $output, $question); |
|
| 111 | + |
|
| 112 | + if ($password !== $confirm) { |
|
| 113 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
| 114 | + return 1; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 118 | + return 1; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + try { |
|
| 123 | + $success = $user->setPassword($password); |
|
| 124 | + } catch (\Exception $e) { |
|
| 125 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 126 | + return 1; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($success) { |
|
| 130 | + $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 131 | + } else { |
|
| 132 | + $output->writeln("<error>Error while resetting password!</error>"); |
|
| 133 | + return 1; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -36,125 +36,125 @@ |
||
| 36 | 36 | use Symfony\Component\Console\Question\Question; |
| 37 | 37 | |
| 38 | 38 | class Add extends Command { |
| 39 | - /** @var \OCP\IUserManager */ |
|
| 40 | - protected $userManager; |
|
| 41 | - |
|
| 42 | - /** @var \OCP\IGroupManager */ |
|
| 43 | - protected $groupManager; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param IUserManager $userManager |
|
| 47 | - * @param IGroupManager $groupManager |
|
| 48 | - */ |
|
| 49 | - public function __construct(IUserManager $userManager, IGroupManager $groupManager) { |
|
| 50 | - parent::__construct(); |
|
| 51 | - $this->userManager = $userManager; |
|
| 52 | - $this->groupManager = $groupManager; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - protected function configure() { |
|
| 56 | - $this |
|
| 57 | - ->setName('user:add') |
|
| 58 | - ->setDescription('adds a user') |
|
| 59 | - ->addArgument( |
|
| 60 | - 'uid', |
|
| 61 | - InputArgument::REQUIRED, |
|
| 62 | - 'User ID used to login (must only contain a-z, A-Z, 0-9, -, _ and @)' |
|
| 63 | - ) |
|
| 64 | - ->addOption( |
|
| 65 | - 'password-from-env', |
|
| 66 | - null, |
|
| 67 | - InputOption::VALUE_NONE, |
|
| 68 | - 'read password from environment variable OC_PASS' |
|
| 69 | - ) |
|
| 70 | - ->addOption( |
|
| 71 | - 'display-name', |
|
| 72 | - null, |
|
| 73 | - InputOption::VALUE_OPTIONAL, |
|
| 74 | - 'User name used in the web UI (can contain any characters)' |
|
| 75 | - ) |
|
| 76 | - ->addOption( |
|
| 77 | - 'group', |
|
| 78 | - 'g', |
|
| 79 | - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
| 80 | - 'groups the user should be added to (The group will be created if it does not exist)' |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 85 | - $uid = $input->getArgument('uid'); |
|
| 86 | - if ($this->userManager->userExists($uid)) { |
|
| 87 | - $output->writeln('<error>The user "' . $uid . '" already exists.</error>'); |
|
| 88 | - return 1; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($input->getOption('password-from-env')) { |
|
| 92 | - $password = getenv('OC_PASS'); |
|
| 93 | - if (!$password) { |
|
| 94 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 95 | - return 1; |
|
| 96 | - } |
|
| 97 | - } elseif ($input->isInteractive()) { |
|
| 98 | - /** @var QuestionHelper $helper */ |
|
| 99 | - $helper = $this->getHelper('question'); |
|
| 100 | - |
|
| 101 | - $question = new Question('Enter password: '); |
|
| 102 | - $question->setHidden(true); |
|
| 103 | - $password = $helper->ask($input, $output, $question); |
|
| 104 | - |
|
| 105 | - $question = new Question('Confirm password: '); |
|
| 106 | - $question->setHidden(true); |
|
| 107 | - $confirm = $helper->ask($input, $output,$question); |
|
| 108 | - |
|
| 109 | - if ($password !== $confirm) { |
|
| 110 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
| 111 | - return 1; |
|
| 112 | - } |
|
| 113 | - } else { |
|
| 114 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>"); |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - try { |
|
| 119 | - $user = $this->userManager->createUser( |
|
| 120 | - $input->getArgument('uid'), |
|
| 121 | - $password |
|
| 122 | - ); |
|
| 123 | - } catch (\Exception $e) { |
|
| 124 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 125 | - return 1; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - if ($user instanceof IUser) { |
|
| 130 | - $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>'); |
|
| 131 | - } else { |
|
| 132 | - $output->writeln('<error>An error occurred while creating the user</error>'); |
|
| 133 | - return 1; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if ($input->getOption('display-name')) { |
|
| 137 | - $user->setDisplayName($input->getOption('display-name')); |
|
| 138 | - $output->writeln('Display name set to "' . $user->getDisplayName() . '"'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $groups = $input->getOption('group'); |
|
| 142 | - |
|
| 143 | - if (!empty($groups)) { |
|
| 144 | - // Make sure we init the Filesystem for the user, in case we need to |
|
| 145 | - // init some group shares. |
|
| 146 | - Filesystem::init($user->getUID(), ''); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - foreach ($groups as $groupName) { |
|
| 150 | - $group = $this->groupManager->get($groupName); |
|
| 151 | - if (!$group) { |
|
| 152 | - $this->groupManager->createGroup($groupName); |
|
| 153 | - $group = $this->groupManager->get($groupName); |
|
| 154 | - $output->writeln('Created group "' . $group->getGID() . '"'); |
|
| 155 | - } |
|
| 156 | - $group->addUser($user); |
|
| 157 | - $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); |
|
| 158 | - } |
|
| 159 | - } |
|
| 39 | + /** @var \OCP\IUserManager */ |
|
| 40 | + protected $userManager; |
|
| 41 | + |
|
| 42 | + /** @var \OCP\IGroupManager */ |
|
| 43 | + protected $groupManager; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param IUserManager $userManager |
|
| 47 | + * @param IGroupManager $groupManager |
|
| 48 | + */ |
|
| 49 | + public function __construct(IUserManager $userManager, IGroupManager $groupManager) { |
|
| 50 | + parent::__construct(); |
|
| 51 | + $this->userManager = $userManager; |
|
| 52 | + $this->groupManager = $groupManager; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + protected function configure() { |
|
| 56 | + $this |
|
| 57 | + ->setName('user:add') |
|
| 58 | + ->setDescription('adds a user') |
|
| 59 | + ->addArgument( |
|
| 60 | + 'uid', |
|
| 61 | + InputArgument::REQUIRED, |
|
| 62 | + 'User ID used to login (must only contain a-z, A-Z, 0-9, -, _ and @)' |
|
| 63 | + ) |
|
| 64 | + ->addOption( |
|
| 65 | + 'password-from-env', |
|
| 66 | + null, |
|
| 67 | + InputOption::VALUE_NONE, |
|
| 68 | + 'read password from environment variable OC_PASS' |
|
| 69 | + ) |
|
| 70 | + ->addOption( |
|
| 71 | + 'display-name', |
|
| 72 | + null, |
|
| 73 | + InputOption::VALUE_OPTIONAL, |
|
| 74 | + 'User name used in the web UI (can contain any characters)' |
|
| 75 | + ) |
|
| 76 | + ->addOption( |
|
| 77 | + 'group', |
|
| 78 | + 'g', |
|
| 79 | + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
|
| 80 | + 'groups the user should be added to (The group will be created if it does not exist)' |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 85 | + $uid = $input->getArgument('uid'); |
|
| 86 | + if ($this->userManager->userExists($uid)) { |
|
| 87 | + $output->writeln('<error>The user "' . $uid . '" already exists.</error>'); |
|
| 88 | + return 1; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($input->getOption('password-from-env')) { |
|
| 92 | + $password = getenv('OC_PASS'); |
|
| 93 | + if (!$password) { |
|
| 94 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 95 | + return 1; |
|
| 96 | + } |
|
| 97 | + } elseif ($input->isInteractive()) { |
|
| 98 | + /** @var QuestionHelper $helper */ |
|
| 99 | + $helper = $this->getHelper('question'); |
|
| 100 | + |
|
| 101 | + $question = new Question('Enter password: '); |
|
| 102 | + $question->setHidden(true); |
|
| 103 | + $password = $helper->ask($input, $output, $question); |
|
| 104 | + |
|
| 105 | + $question = new Question('Confirm password: '); |
|
| 106 | + $question->setHidden(true); |
|
| 107 | + $confirm = $helper->ask($input, $output,$question); |
|
| 108 | + |
|
| 109 | + if ($password !== $confirm) { |
|
| 110 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
| 111 | + return 1; |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>"); |
|
| 115 | + return 1; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + try { |
|
| 119 | + $user = $this->userManager->createUser( |
|
| 120 | + $input->getArgument('uid'), |
|
| 121 | + $password |
|
| 122 | + ); |
|
| 123 | + } catch (\Exception $e) { |
|
| 124 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 125 | + return 1; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + if ($user instanceof IUser) { |
|
| 130 | + $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>'); |
|
| 131 | + } else { |
|
| 132 | + $output->writeln('<error>An error occurred while creating the user</error>'); |
|
| 133 | + return 1; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if ($input->getOption('display-name')) { |
|
| 137 | + $user->setDisplayName($input->getOption('display-name')); |
|
| 138 | + $output->writeln('Display name set to "' . $user->getDisplayName() . '"'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $groups = $input->getOption('group'); |
|
| 142 | + |
|
| 143 | + if (!empty($groups)) { |
|
| 144 | + // Make sure we init the Filesystem for the user, in case we need to |
|
| 145 | + // init some group shares. |
|
| 146 | + Filesystem::init($user->getUID(), ''); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + foreach ($groups as $groupName) { |
|
| 150 | + $group = $this->groupManager->get($groupName); |
|
| 151 | + if (!$group) { |
|
| 152 | + $this->groupManager->createGroup($groupName); |
|
| 153 | + $group = $this->groupManager->get($groupName); |
|
| 154 | + $output->writeln('Created group "' . $group->getGID() . '"'); |
|
| 155 | + } |
|
| 156 | + $group->addUser($user); |
|
| 157 | + $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 85 | 85 | $uid = $input->getArgument('uid'); |
| 86 | 86 | if ($this->userManager->userExists($uid)) { |
| 87 | - $output->writeln('<error>The user "' . $uid . '" already exists.</error>'); |
|
| 87 | + $output->writeln('<error>The user "'.$uid.'" already exists.</error>'); |
|
| 88 | 88 | return 1; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $question = new Question('Confirm password: '); |
| 106 | 106 | $question->setHidden(true); |
| 107 | - $confirm = $helper->ask($input, $output,$question); |
|
| 107 | + $confirm = $helper->ask($input, $output, $question); |
|
| 108 | 108 | |
| 109 | 109 | if ($password !== $confirm) { |
| 110 | 110 | $output->writeln("<error>Passwords did not match!</error>"); |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | $password |
| 122 | 122 | ); |
| 123 | 123 | } catch (\Exception $e) { |
| 124 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 124 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 125 | 125 | return 1; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
| 129 | 129 | if ($user instanceof IUser) { |
| 130 | - $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>'); |
|
| 130 | + $output->writeln('<info>The user "'.$user->getUID().'" was created successfully</info>'); |
|
| 131 | 131 | } else { |
| 132 | 132 | $output->writeln('<error>An error occurred while creating the user</error>'); |
| 133 | 133 | return 1; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | if ($input->getOption('display-name')) { |
| 137 | 137 | $user->setDisplayName($input->getOption('display-name')); |
| 138 | - $output->writeln('Display name set to "' . $user->getDisplayName() . '"'); |
|
| 138 | + $output->writeln('Display name set to "'.$user->getDisplayName().'"'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $groups = $input->getOption('group'); |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | if (!$group) { |
| 152 | 152 | $this->groupManager->createGroup($groupName); |
| 153 | 153 | $group = $this->groupManager->get($groupName); |
| 154 | - $output->writeln('Created group "' . $group->getGID() . '"'); |
|
| 154 | + $output->writeln('Created group "'.$group->getGID().'"'); |
|
| 155 | 155 | } |
| 156 | 156 | $group->addUser($user); |
| 157 | - $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"'); |
|
| 157 | + $output->writeln('User "'.$user->getUID().'" added to group "'.$group->getGID().'"'); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -32,56 +32,56 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class Report extends Command { |
| 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:report') |
|
| 49 | - ->setDescription('shows how many users have access'); |
|
| 50 | - } |
|
| 46 | + protected function configure() { |
|
| 47 | + $this |
|
| 48 | + ->setName('user:report') |
|
| 49 | + ->setDescription('shows how many users have access'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 53 | - $table = new Table($output); |
|
| 54 | - $table->setHeaders(array('User Report', '')); |
|
| 55 | - $userCountArray = $this->countUsers(); |
|
| 56 | - if(!empty($userCountArray)) { |
|
| 57 | - $total = 0; |
|
| 58 | - $rows = array(); |
|
| 59 | - foreach($userCountArray as $classname => $users) { |
|
| 60 | - $total += $users; |
|
| 61 | - $rows[] = array($classname, $users); |
|
| 62 | - } |
|
| 52 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 53 | + $table = new Table($output); |
|
| 54 | + $table->setHeaders(array('User Report', '')); |
|
| 55 | + $userCountArray = $this->countUsers(); |
|
| 56 | + if(!empty($userCountArray)) { |
|
| 57 | + $total = 0; |
|
| 58 | + $rows = array(); |
|
| 59 | + foreach($userCountArray as $classname => $users) { |
|
| 60 | + $total += $users; |
|
| 61 | + $rows[] = array($classname, $users); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $rows[] = array(' '); |
|
| 65 | - $rows[] = array('total users', $total); |
|
| 66 | - } else { |
|
| 67 | - $rows[] = array('No backend enabled that supports user counting', ''); |
|
| 68 | - } |
|
| 64 | + $rows[] = array(' '); |
|
| 65 | + $rows[] = array('total users', $total); |
|
| 66 | + } else { |
|
| 67 | + $rows[] = array('No backend enabled that supports user counting', ''); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $userDirectoryCount = $this->countUserDirectories(); |
|
| 71 | - $rows[] = array(' '); |
|
| 72 | - $rows[] = array('user directories', $userDirectoryCount); |
|
| 70 | + $userDirectoryCount = $this->countUserDirectories(); |
|
| 71 | + $rows[] = array(' '); |
|
| 72 | + $rows[] = array('user directories', $userDirectoryCount); |
|
| 73 | 73 | |
| 74 | - $table->setRows($rows); |
|
| 75 | - $table->render(); |
|
| 76 | - } |
|
| 74 | + $table->setRows($rows); |
|
| 75 | + $table->render(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - private function countUsers() { |
|
| 79 | - return $this->userManager->countUsers(); |
|
| 80 | - } |
|
| 78 | + private function countUsers() { |
|
| 79 | + return $this->userManager->countUsers(); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function countUserDirectories() { |
|
| 83 | - $dataview = new \OC\Files\View('/'); |
|
| 84 | - $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory'); |
|
| 85 | - return count($userDirectories); |
|
| 86 | - } |
|
| 82 | + private function countUserDirectories() { |
|
| 83 | + $dataview = new \OC\Files\View('/'); |
|
| 84 | + $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory'); |
|
| 85 | + return count($userDirectories); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -53,10 +53,10 @@ |
||
| 53 | 53 | $table = new Table($output); |
| 54 | 54 | $table->setHeaders(array('User Report', '')); |
| 55 | 55 | $userCountArray = $this->countUsers(); |
| 56 | - if(!empty($userCountArray)) { |
|
| 56 | + if (!empty($userCountArray)) { |
|
| 57 | 57 | $total = 0; |
| 58 | 58 | $rows = array(); |
| 59 | - foreach($userCountArray as $classname => $users) { |
|
| 59 | + foreach ($userCountArray as $classname => $users) { |
|
| 60 | 60 | $total += $users; |
| 61 | 61 | $rows[] = array($classname, $users); |
| 62 | 62 | } |