Guest User

Untitled

a guest
May 27th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1.  
  2.  
  3. public function admin_fix_aros(){
  4. $this->autoRender = false;
  5. $this->loadModel('Aro');
  6.  
  7. $users = $this->User->find('all');
  8. foreach ($users as $user) {
  9.  
  10. $params = array('conditions' => array(
  11. 'model' => 'User',
  12. 'foreign_key' => $user['User']['id'],
  13. 'parent_id' => $user['User']['role_id'],
  14. ));
  15. $aro = $this->Aro->find('first', $params);
  16.  
  17. // Create new ARO
  18. if(!count($aro)){
  19. debug('CREATING ARO FOR USER '.$user['User']['id'].' > '.$user['User']['name']);
  20.  
  21. $this->Aro->create();
  22. $this->Aro->save(array(
  23. 'model' => 'User',
  24. 'foreign_key' => $user['User']['id'],
  25. 'parent_id' => $user['User']['role_id'],
  26. 'alias' => $user['User']['username'],
  27. ));
  28. }
  29. // Override ARO
  30. else{
  31. $this->Aro->save(array(
  32. 'id' => $aro['Aro']['id'],
  33. 'model' => 'User',
  34. 'foreign_key' => $user['User']['id'],
  35. 'parent_id' => $user['User']['role_id'],
  36. 'alias' => $user['User']['username'],
  37. ));
  38.  
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment