@@ 137-184 (lines=48) @@ | ||
134 | * @see \FreeIPA\APIAccess\Connection\buildRequest() |
|
135 | * @throws \Exception if the request was not completed successfully |
|
136 | */ |
|
137 | public function addMember($group_name = null, $data = array()) |
|
138 | { |
|
139 | if (!$group_name || !$data) { |
|
140 | return false; |
|
141 | } |
|
142 | ||
143 | // Obtained with the command: ipa -vv group_add_member group_one --users="stallman" |
|
144 | $args = array($group_name); |
|
145 | $default_options = array( |
|
146 | 'all' => true, |
|
147 | 'no_members' => false, |
|
148 | 'raw' => false, |
|
149 | ); |
|
150 | if (is_array($data)) { |
|
151 | $final_options = array_merge($default_options, $data); |
|
152 | } else if (is_string($data)) { |
|
153 | $final_options = array_merge($default_options, array('user' => array($data))); |
|
154 | } else { |
|
155 | return false; |
|
156 | } |
|
157 | ||
158 | $response = $this->getConnection()->buildRequest('group_add_member', $args, $final_options); //returns json and http code of response |
|
159 | if (!$response) { |
|
160 | return false; |
|
161 | } |
|
162 | $returned_json = $response[0]; |
|
163 | if (!$returned_json->result->completed) { |
|
164 | $message = "Error while inserting members in group \"$group_name\"."; |
|
165 | if (!empty($returned_json->result->failed->member->group) || |
|
166 | !empty($returned_json->result->failed->member->user)) { |
|
167 | $message .= 'Details: '; |
|
168 | } |
|
169 | ||
170 | if (!empty($returned_json->result->failed->member->group)) { |
|
171 | $message .= implode(' ', $returned_json->result->failed->member->group[0]); |
|
172 | } |
|
173 | ||
174 | if (!empty($returned_json->result->failed->member->user)) { |
|
175 | $message .= implode(' ', $returned_json->result->failed->member->user[0]); |
|
176 | } |
|
177 | ||
178 | throw new \Exception($message); |
|
179 | } |
|
180 | ||
181 | // Unlike other methods, where $returned_json->result->result is returned, |
|
182 | // here the $returned_json->result contain usefull information |
|
183 | return $returned_json->result; |
|
184 | } |
|
185 | ||
186 | /** |
|
187 | * Deletes members (users or other groups) to group |
|
@@ 199-246 (lines=48) @@ | ||
196 | * @see \FreeIPA\APIAccess\Connection\buildRequest() |
|
197 | * @throws \Exception if the request was not completed successfully |
|
198 | */ |
|
199 | public function removeMember($group_name = null, $data = array()) |
|
200 | { |
|
201 | if (!$group_name || !$data) { |
|
202 | return false; |
|
203 | } |
|
204 | ||
205 | // Obtained with the command: ipa -vv group_remove_member group_one --users="stallman" |
|
206 | $args = array($group_name); |
|
207 | $default_options = array( |
|
208 | 'all' => true, |
|
209 | 'no_members' => false, |
|
210 | 'raw' => false, |
|
211 | ); |
|
212 | if (is_array($data)) { |
|
213 | $final_options = array_merge($default_options, $data); |
|
214 | } else if (is_string($data)) { |
|
215 | $final_options = array_merge($default_options, array('user' => array($data))); |
|
216 | } else { |
|
217 | return false; |
|
218 | } |
|
219 | ||
220 | $response = $this->getConnection()->buildRequest('group_remove_member', $args, $final_options); //returns json and http code of response |
|
221 | if (!$response) { |
|
222 | return false; |
|
223 | } |
|
224 | $returned_json = $response[0]; |
|
225 | if (!$returned_json->result->completed) { |
|
226 | $message = "Error while removing members in group \"$group_name\"."; |
|
227 | if (!empty($returned_json->result->failed->member->group) || |
|
228 | !empty($returned_json->result->failed->member->user)) { |
|
229 | $message .= 'Details: '; |
|
230 | } |
|
231 | ||
232 | if (!empty($returned_json->result->failed->member->group)) { |
|
233 | $message .= implode(' ', $returned_json->result->failed->member->group[0]); |
|
234 | } |
|
235 | ||
236 | if (!empty($returned_json->result->failed->member->user)) { |
|
237 | $message .= implode(' ', $returned_json->result->failed->member->user[0]); |
|
238 | } |
|
239 | ||
240 | throw new \Exception($message); |
|
241 | } |
|
242 | ||
243 | // Unlike other methods, where $returned_json->result->result is returned, |
|
244 | // here the $returned_json->result contain usefull information |
|
245 | return $returned_json->result; |
|
246 | } |
|
247 | ||
248 | /** |
|
249 | * Search group through of group_find method. |