loadPermissionsBatch() does not entirely load permission profiles
it confused me at first because I left $profile null,, expeting no data to be loaded.
Anyway, here my code
$group_data = Group::loadSimple(
Group::LOAD_NORMAL | (int) !empty(Config::$modSettings['permission_enable_postgroups']),
[Group::ADMIN, Group::MOD]
);
Group::loadPermissionsBatch(array_map(fn ($group) => $group->id, $group_data));
foreach ($group_data as $data) {
var_export([$data->name => $data->permissions['board_profiles']]);
Expected result
array (
'Guests' =>
array (
1 =>
array (
'poll_view' => 1,
),
2 =>
array (
'poll_view' => 1,
),
3 =>
array (
'poll_view' => 1,
),
4 =>
array (
'poll_view' => 1,
),
),
)array (
'Regular Members' =>
array (
1 =>
array (
'delete_own' => 1,
'lock_own' => 1,
'modify_own' => 1,
'poll_add_own' => 1,
'poll_edit_own' => 1,
'poll_lock_own' => 1,
'poll_post' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_own' => 1,
'report_any' => 1,
'view_attachments' => 1,
),
2 =>
array (
'delete_own' => 1,
'lock_own' => 1,
'modify_own' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_own' => 1,
'report_any' => 1,
'view_attachments' => 1,
),
3 =>
array (
'delete_own' => 1,
'lock_own' => 1,
'modify_own' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'remove_own' => 1,
'report_any' => 1,
'view_attachments' => 1,
),
4 =>
array (
'poll_view' => 1,
'poll_vote' => 1,
'report_any' => 1,
'view_attachments' => 1,
),
),
)array (
'Global Moderator' =>
array (
1 =>
array (
'approve_posts' => 1,
'delete_any' => 1,
'delete_own' => 1,
'lock_any' => 1,
'lock_own' => 1,
'make_sticky' => 1,
'merge_any' => 1,
'moderate_board' => 1,
'modify_any' => 1,
'modify_own' => 1,
'move_any' => 1,
'poll_add_any' => 1,
'poll_edit_any' => 1,
'poll_lock_any' => 1,
'poll_post' => 1,
'poll_remove_any' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_any' => 1,
'report_any' => 1,
'split_any' => 1,
'view_attachments' => 1,
),
2 =>
array (
'approve_posts' => 1,
'delete_any' => 1,
'delete_own' => 1,
'lock_any' => 1,
'lock_own' => 1,
'make_sticky' => 1,
'merge_any' => 1,
'moderate_board' => 1,
'modify_any' => 1,
'modify_own' => 1,
'move_any' => 1,
'poll_add_any' => 1,
'poll_edit_any' => 1,
'poll_lock_any' => 1,
'poll_post' => 1,
'poll_remove_any' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_any' => 1,
'report_any' => 1,
'split_any' => 1,
'view_attachments' => 1,
),
3 =>
array (
'approve_posts' => 1,
'delete_any' => 1,
'delete_own' => 1,
'lock_any' => 1,
'lock_own' => 1,
'make_sticky' => 1,
'merge_any' => 1,
'moderate_board' => 1,
'modify_any' => 1,
'modify_own' => 1,
'move_any' => 1,
'poll_add_any' => 1,
'poll_edit_any' => 1,
'poll_lock_any' => 1,
'poll_post' => 1,
'poll_remove_any' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_any' => 1,
'report_any' => 1,
'split_any' => 1,
'view_attachments' => 1,
),
4 =>
array (
'approve_posts' => 1,
'delete_any' => 1,
'delete_own' => 1,
'lock_any' => 1,
'lock_own' => 1,
'make_sticky' => 1,
'merge_any' => 1,
'moderate_board' => 1,
'modify_any' => 1,
'modify_own' => 1,
'move_any' => 1,
'poll_add_any' => 1,
'poll_edit_any' => 1,
'poll_lock_any' => 1,
'poll_post' => 1,
'poll_remove_any' => 1,
'poll_view' => 1,
'poll_vote' => 1,
'post_attachment' => 1,
'post_draft' => 1,
'post_new' => 1,
'post_reply_any' => 1,
'post_reply_own' => 1,
'post_unapproved_attachments' => 1,
'post_unapproved_replies_any' => 1,
'post_unapproved_replies_own' => 1,
'post_unapproved_topics' => 1,
'remove_any' => 1,
'report_any' => 1,
'split_any' => 1,
'view_attachments' => 1,
),
),
)
Actual result
array (
'Guests' =>
array (
1 =>
array (
'poll_view' => 1,
),
2 =>
array (
'poll_view' => 1,
),
3 =>
array (
'poll_view' => 1,
),
4 =>
array (
'poll_view' => 1,
),
),
)array (
'Regular Members' =>
array (
1 =>
array (
'delete_own' => 1,
),
2 =>
array (
'delete_own' => 1,
),
3 =>
array (
'delete_own' => 1,
),
4 =>
array (
'poll_view' => 1,
),
),
)array (
'Global Moderator' =>
array (
1 =>
array (
'approve_posts' => 1,
),
2 =>
array (
'approve_posts' => 1,
),
3 =>
array (
'approve_posts' => 1,
),
4 =>
array (
'approve_posts' => 1,
),
),
)
I got results by deleting deez https://github.com/SimpleMachines/SMF/blob/5ad2a2656099c02e6b8ffdaddfd6f68f95ad01af/Sources/Group.php#L2072-L2075
Should loading a permission profile be optional?
As I recall, those lines exist because there are situations where loadPermissionsBatch() is called after some permissions have already been loaded and potentially adjusted, and preserving such adjustments is desired.
In your case, I think you just need to set the $reload parameter of loadPermissionsBatch() to true in order to get the behaviour that you want.
Caveat: I am currently on my phone, so I haven't done a thorough analysis to verify this.