Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Code inquiry!

chanhchanh ✭✭
edited February 2014 in Vanilla 2.0 - 2.8

I notice in Vanilla master branch and it uses code like this where it assign a string of text into an array element which mapped into a table with the data type of int which very likely to trip the Mysql strict mode where text can't be insert into an int field.

$PermissionModel->Define(array(
   'Garden.Email.View' => 'Garden.SignIn.Allow', (this in particular)
   'Garden.Settings.Manage',
   'Garden.Settings.View',
   'Garden.Messages.Manage',
   'Garden.SignIn.Allow' => 1,
   'Garden.Users.Add',
   'Garden.Users.Edit',
   'Garden.Users.Delete',
   'Garden.Users.Approve',
   'Garden.Activity.Delete',
   'Garden.Activity.View' => 1,
   'Garden.Profiles.View' => 1,
   'Garden.Profiles.Edit' => 'Garden.SignIn.Allow', (this in particular)
   'Garden.Curation.Manage' => 'Garden.Moderation.Manage', (this in particular)
   'Garden.Moderation.Manage',
   'Garden.PersonalInfo.View' => 'Garden.Moderation.Manage', (this in particular)
   'Garden.AdvancedNotifications.Allow'
   ));

I might miss something very obvious but not sure how this code would actually do during setup!

Thank you.

Comments

  • And the question is?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • What is the code suppose to do?
    If it suppose to assign the value of 'Garden.SignIn.Allow' to 'Garden.Email.View' then I don't see how it is accomplished.

  • Arrays in php can be mixed types. That is, they can be indexless (implicit numerical indexed), numerical indexed, or ask associative. All in the same array.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • I agree about array but the problem it when it is updating the database with wrong type and with strict mode it just cause the setup to "bonk". It took me sometime to figure this out on where it causes the bonk!

  • Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Besides of that, why should anybody do something like that? 'Garden.Email.View' => 'Garden.SignIn.Allow',

  • @R_J You mean in context of the framework, or in the context of any development?

    They might be using as a reference to something else later on in the code. Only the person that wrote it could tell you why they did it for this specific situation.

    Non-empty strings evaluate as true when cast to a bool.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • When adding new permissions to core, you can assign it the value of an existing permission which it will use as the default assignment for roles. For instance, when we added Garden.Curation.Manage, we wanted all existing moderators to have permission for it without the administrator needing to set it. It doesn't literally set the column to a string.

  • I don't see any where in the code that do the remapping of the fields. I look at the Define() where it just make the assignment and replace the records which cause the setup to fail immediately when MySQL is set in strict mode.

  • I found the code that does the substitution so just change this line from 'Garden.Moderation.Manage', to 'Garden.Moderation.Manage' => 0, then it will run just fine when MySQL is set in strict mode.

  • What does Garden.Email.View do?

Sign In or Register to comment.