@@ -37,98 +37,98 @@ |
||
| 37 | 37 | use OCP\IConfig; |
| 38 | 38 | |
| 39 | 39 | class Search extends Command { |
| 40 | - /** @var \OCP\IConfig */ |
|
| 41 | - protected $ocConfig; |
|
| 40 | + /** @var \OCP\IConfig */ |
|
| 41 | + protected $ocConfig; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param \OCP\IConfig $ocConfig |
|
| 45 | - */ |
|
| 46 | - public function __construct(IConfig $ocConfig) { |
|
| 47 | - $this->ocConfig = $ocConfig; |
|
| 48 | - parent::__construct(); |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @param \OCP\IConfig $ocConfig |
|
| 45 | + */ |
|
| 46 | + public function __construct(IConfig $ocConfig) { |
|
| 47 | + $this->ocConfig = $ocConfig; |
|
| 48 | + parent::__construct(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - protected function configure() { |
|
| 52 | - $this |
|
| 53 | - ->setName('ldap:search') |
|
| 54 | - ->setDescription('executes a user or group search') |
|
| 55 | - ->addArgument( |
|
| 56 | - 'search', |
|
| 57 | - InputArgument::REQUIRED, |
|
| 58 | - 'the search string (can be empty)' |
|
| 59 | - ) |
|
| 60 | - ->addOption( |
|
| 61 | - 'group', |
|
| 62 | - null, |
|
| 63 | - InputOption::VALUE_NONE, |
|
| 64 | - 'searches groups instead of users' |
|
| 65 | - ) |
|
| 66 | - ->addOption( |
|
| 67 | - 'offset', |
|
| 68 | - null, |
|
| 69 | - InputOption::VALUE_REQUIRED, |
|
| 70 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
| 71 | - 0 |
|
| 72 | - ) |
|
| 73 | - ->addOption( |
|
| 74 | - 'limit', |
|
| 75 | - null, |
|
| 76 | - InputOption::VALUE_REQUIRED, |
|
| 77 | - 'limit the results. 0 means no limit, defaults to 15', |
|
| 78 | - 15 |
|
| 79 | - ) |
|
| 80 | - ; |
|
| 81 | - } |
|
| 51 | + protected function configure() { |
|
| 52 | + $this |
|
| 53 | + ->setName('ldap:search') |
|
| 54 | + ->setDescription('executes a user or group search') |
|
| 55 | + ->addArgument( |
|
| 56 | + 'search', |
|
| 57 | + InputArgument::REQUIRED, |
|
| 58 | + 'the search string (can be empty)' |
|
| 59 | + ) |
|
| 60 | + ->addOption( |
|
| 61 | + 'group', |
|
| 62 | + null, |
|
| 63 | + InputOption::VALUE_NONE, |
|
| 64 | + 'searches groups instead of users' |
|
| 65 | + ) |
|
| 66 | + ->addOption( |
|
| 67 | + 'offset', |
|
| 68 | + null, |
|
| 69 | + InputOption::VALUE_REQUIRED, |
|
| 70 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
| 71 | + 0 |
|
| 72 | + ) |
|
| 73 | + ->addOption( |
|
| 74 | + 'limit', |
|
| 75 | + null, |
|
| 76 | + InputOption::VALUE_REQUIRED, |
|
| 77 | + 'limit the results. 0 means no limit, defaults to 15', |
|
| 78 | + 15 |
|
| 79 | + ) |
|
| 80 | + ; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Tests whether the offset and limit options are valid |
|
| 85 | - * @param int $offset |
|
| 86 | - * @param int $limit |
|
| 87 | - * @throws \InvalidArgumentException |
|
| 88 | - */ |
|
| 89 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
| 90 | - if($limit < 0) { |
|
| 91 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
| 92 | - } |
|
| 93 | - if($offset < 0) { |
|
| 94 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
| 95 | - } |
|
| 96 | - if($limit === 0 && $offset !== 0) { |
|
| 97 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
| 98 | - } |
|
| 99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
| 100 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
| 101 | - } |
|
| 102 | - } |
|
| 83 | + /** |
|
| 84 | + * Tests whether the offset and limit options are valid |
|
| 85 | + * @param int $offset |
|
| 86 | + * @param int $limit |
|
| 87 | + * @throws \InvalidArgumentException |
|
| 88 | + */ |
|
| 89 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
| 90 | + if($limit < 0) { |
|
| 91 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
| 92 | + } |
|
| 93 | + if($offset < 0) { |
|
| 94 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
| 95 | + } |
|
| 96 | + if($limit === 0 && $offset !== 0) { |
|
| 97 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
| 98 | + } |
|
| 99 | + if($offset > 0 && ($offset % $limit !== 0)) { |
|
| 100 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 105 | - $helper = new Helper($this->ocConfig); |
|
| 106 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 107 | - $ldapWrapper = new LDAP(); |
|
| 104 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 105 | + $helper = new Helper($this->ocConfig); |
|
| 106 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 107 | + $ldapWrapper = new LDAP(); |
|
| 108 | 108 | |
| 109 | - $offset = intval($input->getOption('offset')); |
|
| 110 | - $limit = intval($input->getOption('limit')); |
|
| 111 | - $this->validateOffsetAndLimit($offset, $limit); |
|
| 109 | + $offset = intval($input->getOption('offset')); |
|
| 110 | + $limit = intval($input->getOption('limit')); |
|
| 111 | + $this->validateOffsetAndLimit($offset, $limit); |
|
| 112 | 112 | |
| 113 | - if($input->getOption('group')) { |
|
| 114 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 115 | - $getMethod = 'getGroups'; |
|
| 116 | - $printID = false; |
|
| 117 | - // convert the limit of groups to null. This will show all the groups available instead of |
|
| 118 | - // nothing, and will match the same behaviour the search for users has. |
|
| 119 | - if ($limit === 0) { |
|
| 120 | - $limit = null; |
|
| 121 | - } |
|
| 122 | - } else { |
|
| 123 | - $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
| 124 | - $getMethod = 'getDisplayNames'; |
|
| 125 | - $printID = true; |
|
| 126 | - } |
|
| 113 | + if($input->getOption('group')) { |
|
| 114 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 115 | + $getMethod = 'getGroups'; |
|
| 116 | + $printID = false; |
|
| 117 | + // convert the limit of groups to null. This will show all the groups available instead of |
|
| 118 | + // nothing, and will match the same behaviour the search for users has. |
|
| 119 | + if ($limit === 0) { |
|
| 120 | + $limit = null; |
|
| 121 | + } |
|
| 122 | + } else { |
|
| 123 | + $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
| 124 | + $getMethod = 'getDisplayNames'; |
|
| 125 | + $printID = true; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
| 129 | - foreach($result as $id => $name) { |
|
| 130 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
| 131 | - $output->writeln($line); |
|
| 132 | - } |
|
| 133 | - } |
|
| 128 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
| 129 | + foreach($result as $id => $name) { |
|
| 130 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
| 131 | + $output->writeln($line); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |