Skip to content

Instantly share code, notes, and snippets.

@williamn
Created June 23, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamn/42aa76bcdb877736141d to your computer and use it in GitHub Desktop.
Save williamn/42aa76bcdb877736141d to your computer and use it in GitHub Desktop.
CakePHP ARO rebuild shell task
<?php
class RebuildAroShell extends AppShell {
public $uses = array('User', 'Group');
public function main() {
$groups = $this->Group->find('all');
$users = $this->User->find('all');
$aro = new Aro();
foreach ($groups as $group) {
$aro->create();
$aro->save(array(
'foreign_key' => $group['Group']['id'],
'model' => 'Group',
'parent_id' => null
));
}
$aros = array();
// Index
$i = 0;
foreach ($users as $user) {
$aros[$i++] = array(
'foreign_key' => $user['User']['id'],
'model' => 'User',
'parent_id' => $user['User']['group_id']
);
}
foreach ($aros as $data) {
$aro->create();
$aro->save($data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment