Created
June 23, 2014 12:51
-
-
Save williamn/42aa76bcdb877736141d to your computer and use it in GitHub Desktop.
CakePHP ARO rebuild shell task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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