public static function applyGlobalPermission($applyGroupId, $applyPermissionId, $dependGroupId = null, $dependPermissionId = null, $checkModerator = true)
{
$db = XenForo_Application::getDb();
XenForo_Db::beginTransaction($db);
if ($dependGroupId && $dependPermissionId)
{
$db->query("
INSERT IGNORE INTO xf_permission_entry
(user_group_id, user_id, permission_group_id, permission_id, permission_value, permission_value_int)
SELECT user_group_id, user_id, ?, ?, 'allow', 0
FROM xf_permission_entry
WHERE permission_group_id = ?
AND permission_id = ?
AND permission_value = 'allow'
", array($applyGroupId, $applyPermissionId, $dependGroupId, $dependPermissionId));
}
else
{
$db->query("
INSERT IGNORE INTO xf_permission_entry
(user_group_id, user_id, permission_group_id, permission_id, permission_value, permission_value_int)
SELECT DISTINCT user_group_id, user_id, ?, ?, 'allow', 0
FROM xf_permission_entry
", array($applyGroupId, $applyPermissionId));
}
if ($checkModerator)
{
$moderators = self::_getGlobalModPermissions();
foreach ($moderators AS $userId => $permissions)
{
if (!$dependGroupId || !$dependPermissionId || !empty($permissions[$dependGroupId][$dependPermissionId]))
{
$permissions[$applyGroupId][$applyPermissionId] = '1'; // string 1 is stored by the code
self::_updateGlobalModPermissions($userId, $permissions);
}
}
}
XenForo_Db::commit($db);
}