Missing ARO for auto-created users

106 views
Skip to first unread message

Roberto Vidal

unread,
May 27, 2017, 9:58:54 AM5/27/17
to Croogo
Hello, I´m stuck with this from a long time, I came to ask for some help.
I automatically create users importing a CSV. Some of this users don´t have a related row at the "aros" table, I don´t know why.

When launching a script that applies uppercase to all the usernames, the ones that don´t have a related aro fail to save.
The error is: [CakeException] AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => User [Aro0.foreign_key] => 14 )

This is true: in the "aros" table there isn´t any row with Model = User and foreign_key = 14.
I found the console tool to regenerate and repair ACL trees, also to sync content, but none of this commands regenerated the right ARO for this user.
Any help would be appreciated.

Commands I´ve tried:
    cake Acl.Extras recover aro
    cake
Acl.Extras recover aco
    cake
Acl.Extras verify aro
    cake
Acl.Extras verify aco
    cake
Acl.Extras aco_sync_contents Users.User
    cake
Acl.Extras aco_update
    cake
Acl.Extras aco_sync  


   
// One of these creates duplicated rows in "aros" table, but not the one I need (foreign_key=14)
    cake acl create aro parent_ARO
User.user_id
    cake acl create aro
0 Users

Roberto Vidal

unread,
May 27, 2017, 7:21:20 PM5/27/17
to Croogo
I´m not sure I´m understanding what´s going on here with the aros/acos, but I found a valid solution after reading this: https://stackoverflow.com/questions/25783937/cake-php-how-to-update-aros

Basically, I must re-create the missing aros. I found strange that this cannot be done with the ACL console commands, something tells me this is not how I must fix the missing aros problem. Anyway, here´s the full method I made to fix it:

 public function admin_fix_aros(){
    $this
->autoRender =
    $this
->loadModel('Aro');
 
    $users
= $this->User->find('all');
   
foreach ($users as $user) {
       $params
= array('conditions' => array(
         
'model' => 'User',
         
'foreign_key' => $user['User']['id'],
         
'parent_id' => $user['User']['role_id'],
       
));
       $aro
= $this->Aro->find('first', $params);
 
       
// Create new ARO
       
if(!count($aro)){
          debug
('CREATING ARO FOR USER '.$user['User']['id'].' > '.$user['User']['name']);
 
          $this
->Aro->create();
          $this
->Aro->save(array(
             
'model' => 'User',
             
'foreign_key' => $user['User']['id'],
             
'parent_id' => $user['User']['role_id'],
             
'alias' => $user['User']['username'],
         
));
     
}
     
// Override ARO
     
else{
         $this
->Aro->save(array(
           
'id' => $aro['Aro']['id'],
           
'model' => 'User',
           
'foreign_key' => $user['User']['id'],
           
'parent_id' => $user['User']['role_id'],
           
'alias' => $user['User']['username'],
         
));  
   
 }
 
}
 
}

Roberto Vidal

unread,
May 27, 2017, 7:23:58 PM5/27/17
to Croogo
Sorry, the copy-paste has some errors..
Here´s the method on PasteBin in case it´s useful for anyone in the future:

Rachman Chavik

unread,
May 29, 2017, 2:44:37 AM5/29/17
to Croogo


On Saturday, May 27, 2017 at 8:58:54 PM UTC+7, Roberto Vidal wrote:
Hello, I´m stuck with this from a long time, I came to ask for some help.
I automatically create users importing a CSV. Some of this users don´t have a related row at the "aros" table, I don´t know why.

When launching a script that applies uppercase to all the usernames, the ones that don´t have a related aro fail to save.
The error is: [CakeException] AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => User [Aro0.foreign_key] => 14 )

This is true: in the "aros" table there isn´t any row with Model = User and foreign_key = 14.
I found the console tool to regenerate and repair ACL trees, also to sync content, but none of this commands regenerated the right ARO for this user.
Any help would be appreciated.


You'll to create users by loading the model from the Users plugin. When you do that, it should automatically create the ARO.

Eg;

$User = ClassRegistry::init('Users.Users'); // this will instantiate the Users model with the UserAroBehavior loaded. 
// That behavior will create the ARO record for the user (in its afterSave() callback).
$newUser = $User->create(...);
$User->save($newUser);


Roberto Vidal

unread,
May 29, 2017, 7:46:35 AM5/29/17
to Croogo
So I was missing the ClassRegistry part.
I was simply loading the model, but it seems that´s not enough.
Thanks, Rachman!

Roberto Vidal

unread,
Apr 20, 2020, 8:18:17 PM4/20/20
to Croogo
Rachman, how would you do the same thing in Croogo/Cakephp 3?
I spent the last days trying to figure out and I cannot do it.
I have an array of data with the user information, and then I create an entity that I later save:

$patched = $this->Users->newEntity($userData);
$save = $this->Users->save( $patched );

But I don´t know how to apply the "->create()" concept here to have the AROS/ACOS working.
I can create the user, but if I try to delete it via admin panel, an error says that there are missing AROS/ACOS.

Thanks in advance

Roberto Vidal

unread,
Apr 21, 2020, 12:25:21 PM4/21/20
to Croogo
Found the solution. I was initialiting the Users table in the wrong way.
Instead of:
$this->Users = TableRegistry::get('Users');

You must call it like this:
$this->Users = TableRegistry::get('Croogo/Users.Users');

Using the first code will in fact store the new user in the database table "users".
But it won´t include AROS/ACOS and other behaviors. The second one does.

Also, if you want to ignore validations, you can create the entity like this:
$patched = $this->Users->newEntity($relatedData, ['validate' => false]);
Reply all
Reply to author
Forward
0 new messages