MyBB Community Forums

Full Version: AdminCP / Forum Management / Permissions PHP8 warnings with Not Active forums)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What started out as attempting to edit permissions on a Not Active forum resulting in a bug report, turned into a thorough review of the forum management module. Because it does not make any sense to me to create a forum that is Active before it is set up and ready to use. This means creating a Not Active forum and setting group permissions and moderator permissions, and changing them as needed before the forum goes Active.

The previous post here included an attempt to show accurate administrator log entries as well where forum name was not populated. The following core edits solve both sets of problems.


In admin/modules/forum/management.php

If a forum is not active, forum permissions are inherited from the parent by default. In AdminCP / Forum Management, permissions can be changed by Set Custom Permissions, and if they've been changed, changing them again using Edit Forum Settings tab. The modal form would display and permit changing different permissions, and clicking the Save button would save the permissions, but not clear the form. Clicking the Cancel button would clear the form. In order to view the changes, you'd have to go back to select the forum again to view any changes made. This is not intuitive.

When viewing permissions on a Not Active forum, warnings are generated on lines 2502 and 2702 for each group id which does not have a custom permission set.
<error>
	<dateline>1707162846</dateline>
	<datetime>2024-02-05 19:54:06 UTC -0500</datetime>
	<script>admin/modules/forum/management.php</script>
	<line>2502</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Trying to access array offset on value of type bool</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/admin/modules/forum/management.php:2502]
#2  require() called at [/admin/index.php:834]
</back_trace>
</error>

<error>
	<dateline>1707162846</dateline>
	<datetime>2024-02-05 19:54:06 UTC -0500</datetime>
	<script>admin/modules/forum/management.php</script>
	<line>2507</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Trying to access array offset on value of type bool</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/admin/modules/forum/management.php:2507]
#2  require() called at [/admin/index.php:834]
</back_trace>
</error>

Line 2502 evaluates isset($cached_forum_perms[$forum['fid']][$usergroup['gid']])
Line 2507 evaluates isset($cached_forum_perms[$forum['pid']][$usergroup['gid']])

and the warning occurs because when a forum is not active neither $forum['fid'] nor $forum['pid'] are defined.
Hence the warning "Trying to access array offset on value of type bool".

Find line 2502
				elseif(is_array($cached_forum_perms) && isset($cached_forum_perms[$forum['fid']][$usergroup['gid']]) && $cached_forum_perms[$forum['fid']][$usergroup['gid']])
and replace with
				elseif(isset($forum['fid']) && is_array($cached_forum_perms) && isset($cached_forum_perms[$forum['fid']][$usergroup['gid']]) && $cached_forum_perms[$forum['fid']][$usergroup['gid']])

Find line 2507
				else if(is_array($cached_forum_perms) && isset($cached_forum_perms[$forum['pid']][$usergroup['gid']]) && $cached_forum_perms[$forum['pid']][$usergroup['gid']])
and replace with
				else if(isset($forum['pid']) && is_array($cached_forum_perms) && isset($cached_forum_perms[$forum['pid']][$usergroup['gid']]) && $cached_forum_perms[$forum['pid']][$usergroup['gid']])

When exercising all the options, for example, starting to edit permissions but making no changes and clicking save, a warning is generated,
<error>
	<dateline>1707306901</dateline>
	<datetime>2024-02-07 11:55:01 UTC -0500</datetime>
	<script>admin/modules/forum/management.php</script>
	<line>514</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key "permissions"</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/admin/modules/forum/management.php:514]
#2  require() called at [/admin/index.php:834]
</back_trace>
</error>

Find line 514
		if(is_array($mybb->input['permissions']))
and replace with
		if(isset($mybb->input['permissions']))

The root of all this problem (unable to edit Not Active) is when forum info is called using get_forum() function. A second argument specifies to override the Active-only default.

In lines 320, 501, 509, 1968, 2012, 2111, 2196, find
			$forum = get_forum($fid);
and replace with
			$forum = get_forum($fid, 1);


And finally, copying a Not Active forum generates a warning if no permissions are copied over in AdminCP / Tools & Maintenance / Administrator Log

<error>
 <dateline>1707225255</dateline>
 <datetime>2024-02-06 13:14:15 UTC -0500</datetime>
 <script>admin/modules/tools/adminlog.php</script>
 <line>416</line>
 <type>2</type>
 <friendly_type>Warning</friendly_type>
 <message>Undefined array key 4</message>
 <back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/admin/modules/tools/adminlog.php:416]
#2  get_admin_log_action() called at [/admin/modules/tools/adminlog.php:249]
#3  require() called at [/admin/index.php:834]
</back_trace>
</error>

Find in admin/modules/tools/adminlog.php line 416
if($logitem['data'][4])
and replace with
if(!empty($logitem['data'][4]))