Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UF 4.2.1 DefaultPermissions seed results in SQL errors #981

Closed
noellekimiko opened this issue May 22, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@noellekimiko
Copy link

commented May 22, 2019

UserFrosting Forum thread: https://forums.userfrosting.com/t/defaultpermissions-seed-doesnt-run/543

The Permission class doesn't have an id property, so the database calls in the syncPermissionsRole() function actually result in SQL errors because the permission_id is not defined.

I was able to run it by adding this code to the top of the syncPermissionsRole() function:

$permissionIds = [];
        foreach ($permissions as $slug => $permission) {
            $permissionIds[$slug] = Permission::where(['slug' => $permission->slug, 'conditions' => $permission->conditions])->first()->id;
        }

and then changing the various $permissions['PERMISSION_NAME']->id calls to be $permissionIds['PERMISSION_NAME'].

@lcharette

This comment has been minimized.

Copy link
Member

commented May 23, 2019

This solution is not perfect as it requires an additional db query. The id is actually generated when save is executed.

The real problem is $permissions here is not changed by the actions in savePermissions. A more simple fix would probably be to pass the variable by reference here:

protected function savePermissions(array &$permissions)

@lcharette lcharette added this to the 4.2.x milestone May 23, 2019

@amosfolz

This comment has been minimized.

Copy link
Contributor

commented May 23, 2019

This looks like something within my skill set. I will work on it this weekend if no one else gets to it before then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.