| @@ 277-303 (lines=27) @@ | ||
| 274 | return $this->execute($sql); |
|
| 275 | } |
|
| 276 | ||
| 277 | private function _dealWithOldParentRoles($original_parent_roles, $new_roles_to_add, $rolename) |
|
| 278 | { |
|
| 279 | $old = explode(',', $original_parent_roles); |
|
| 280 | ||
| 281 | // Grant the roles of the old role owners to the new owner |
|
| 282 | foreach ($new_roles_to_add as $m) { |
|
| 283 | if (!in_array($m, $old, true)) { |
|
| 284 | $status = $this->grantRole($m, $rolename); |
|
| 285 | if ($status != 0) { |
|
| 286 | return -1; |
|
| 287 | } |
|
| 288 | } |
|
| 289 | } |
|
| 290 | ||
| 291 | // Revoke the new role to the old members if they don't have the requested role name |
|
| 292 | ||
| 293 | foreach ($old as $o) { |
|
| 294 | if (!in_array($o, $new_roles_to_add, true)) { |
|
| 295 | $status = $this->revokeRole($o, $rolename, 0, 'CASCADE'); |
|
| 296 | if ($status != 0) { |
|
| 297 | return -1; |
|
| 298 | } |
|
| 299 | } |
|
| 300 | } |
|
| 301 | ||
| 302 | return 0; |
|
| 303 | } |
|
| 304 | ||
| 305 | private function _dealWithOriginalMembers($original_members, $new_members_of_role, $rolename) |
|
| 306 | { |
|
| @@ 305-329 (lines=25) @@ | ||
| 302 | return 0; |
|
| 303 | } |
|
| 304 | ||
| 305 | private function _dealWithOriginalMembers($original_members, $new_members_of_role, $rolename) |
|
| 306 | { |
|
| 307 | //members |
|
| 308 | $old = explode(',', $original_members); |
|
| 309 | foreach ($new_members_of_role as $m) { |
|
| 310 | if (!in_array($m, $old, true)) { |
|
| 311 | $status = $this->grantRole($rolename, $m); |
|
| 312 | if ($status != 0) { |
|
| 313 | return -1; |
|
| 314 | } |
|
| 315 | } |
|
| 316 | } |
|
| 317 | if ($original_members) { |
|
| 318 | foreach ($old as $o) { |
|
| 319 | if (!in_array($o, $new_members_of_role, true)) { |
|
| 320 | $status = $this->revokeRole($rolename, $o, 0, 'CASCADE'); |
|
| 321 | if ($status != 0) { |
|
| 322 | return -1; |
|
| 323 | } |
|
| 324 | } |
|
| 325 | } |
|
| 326 | } |
|
| 327 | ||
| 328 | return 0; |
|
| 329 | } |
|
| 330 | ||
| 331 | private function _dealWithOriginalAdmins($original_admins, $new_admins_of_role, $rolename) |
|
| 332 | { |
|
| @@ 331-353 (lines=23) @@ | ||
| 328 | return 0; |
|
| 329 | } |
|
| 330 | ||
| 331 | private function _dealWithOriginalAdmins($original_admins, $new_admins_of_role, $rolename) |
|
| 332 | { |
|
| 333 | $old = explode(',', $original_admins); |
|
| 334 | foreach ($new_admins_of_role as $m) { |
|
| 335 | if (!in_array($m, $old, true)) { |
|
| 336 | $status = $this->grantRole($rolename, $m, 1); |
|
| 337 | if ($status != 0) { |
|
| 338 | return -1; |
|
| 339 | } |
|
| 340 | } |
|
| 341 | } |
|
| 342 | ||
| 343 | foreach ($old as $o) { |
|
| 344 | if (!in_array($o, $new_admins_of_role, true)) { |
|
| 345 | $status = $this->revokeRole($rolename, $o, 1, 'CASCADE'); |
|
| 346 | if ($status != 0) { |
|
| 347 | return -1; |
|
| 348 | } |
|
| 349 | } |
|
| 350 | } |
|
| 351 | ||
| 352 | return 0; |
|
| 353 | } |
|
| 354 | ||
| 355 | private function _alterRole($rolename, $password, $connlimit, $expiry, $superuser, $createdb, $createrole, $inherits, $login) |
|
| 356 | { |
|