Generate ACO records for your controllers and actions with AcoSyncShell

Continuing in my previous vein of ACL related topics. I’ve got another handy addition to the ACL user’s toolbox. In my previous tutorials on auth and acl I posted a little controller action that helped maintain the ACO side of your ACL. I got pretty good feedback on that snippet, and have taken the time to expand it into a shell.

Introducing the aco_sync shell

The aco_sync shell takes everything that was good about buildAcl() and adds a bit of flair. aco_sync retains its ability to non-destructively add nodes to the acos table based on changes made to your application since the last time it ran. This is done simply by running

Show Plain Text
cake aco_sync update

from your prompt. It also has the ability to remove uneeded controllers and actions from the ACL as well. By running

Show Plain Text
cake aco_sync sync

The shell will not only add all missing Actions and Controllers to your ACL table but also remove all no longer existing nodes. Making ACL management a snap. No longer do you have to manually add ACO records when creating new controllers and actions.

To use the shell simply Download the Aco Sync Shell and place it in either app/vendors/shells or cake/vendors/shells/. Open a prompt and cd into your cake/console directory. You should now be able to run the aco_sync shell. One warning though, the shell will not work if you don’t already have the ACL table in your database.

I hope you find this useful. Let me know if you have any troubles with it.

Update: You can find the newest version of this file in my github repository


Mark, this is AMAZING! I´m gonna add it to my apps right now! Thanks, you are my day-hero.

anonymous user on 8/1/08

Martin: I’m glad you found it useful. I’ve been using it on a few apps and it saves me a ton of time.

mark story on 8/22/08

Mark, thanks for this excellent tool. I noticed one change though. In the old buildAcl function private functions were not created in the ACO database, but the shell doesn’t make this difference. Could you fix that?

anonymous user on 9/15/08

Jan Boonen: I don’t know how I missed that but it has been fixed. Check my github for the new version.

mark story on 9/15/08

Very useful tool. :)

anonymous user on 10/10/08

Thanks for this very useful tool.
But, I have one little question…
For example I have controller ‘Users’.
What are these “appcontroller” and “userscontroller” alias with parent_id to ‘Users’?
It’s not a controller method…(?)

anonymous user on 11/19/08

This is very usefull.
Thanks :)

But when i run this script, i noticed private method also sync.
So, i have a little idea & Paste the code here.

/** * Check a node for existance, create it if it doesn’t exist. * * param string $path * param string $alias * param int $parentId * return array Aco Node array */ function _checkNode($path, $alias, $parentId = null) { $node = $this->Aco->node($path); if (!$node) { // Add HERE if (!strpos($alias, ‘_’, 0)) { $this->Aco->create(array(‘parent_id’ => $parentId, ‘model’ => null, ‘alias’ => $alias)); $node = $this->Aco->save(); $node[‘Aco’][‘id’] = $this->Aco->id; $this->out(sprintf(__(‘Created Aco node: %s’, true), $path)); } } else { $node = $node0; } return $node; }

lifegood on 1/6/09

So soory, i typoed…

Right code is

function _checkNode($path, $alias, $parentId = null) {


// Add HERE
if (!strpos($path, ‘_’, 0)) {



lifegood on 1/6/09

Great works!

William Notowidagdo on 2/21/09

What is the acl_extras.php file for in the GitHub repository? I just updated the acl_sync file from Git to get the private function ignore feature, and I noticed mention of the new file in commit comments.

Jeremy Luebke on 3/22/09

Thank you for this very useful tool!

Nikolay on 4/21/09

I have two-word controllers such as sync_types (i.e. model SyncTypes) and the script appears to put the model name in the alias and the ACL fails because it can’t find ACO “Sync_types”. Anyone else experiencing this? Should be an easy enough patch and if I sort out where the issue is, I’ll share it back. Also since the aco table has a column for the model, maybe that should be populated too?

Webguy on 6/19/09

Absolute legend!

Clinton Bruce on 2/15/10

Thanks so much, brilliant work. I think I saw it was removed from github?

Anyway, I extended lifegood (above) suggestion about ignoring private methods so that it only ignores methods that start with an underscore. (p.s. just a new php programmer, probably not very efficient/clear)

function _checkNode($path, $alias, $parentId = null) {
    // Just check the last part of the path
    $checkPath = strpos($path, '/', 0) ? substr($path, strrpos($path, '/') + 1) : $path;

    // Continue to process node if it doesn't start with an underscore
    $doesNotStartWithUs = (strpos($checkPath, '_', 0) === false) || (strpos($checkPath, '_', 0) != 0);

    if ($doesNotStartWithUs) {

redthor on 1/8/11

i have use NiceAuth plugin

طراحی وب سایت on 9/6/12

Comments are not open at this time.