Skip to content

Undefined value from adding member to group #7740

@jdarwood007

Description

@jdarwood007

Description

The error log produces these entries:

Sources/Logging.php (Line 567)
The database value you're trying to insert does not exist: id_member
Function: logActions
Sources/Logging.php (Line 546)
2: Trying to access array offset on value of type null

This one took me a bit to walk backwards through the data. So I will walk through the important pieces.
This is coming from a task, specifically GroupAct-Notify.php

In that code this is triggered

				addMembersToGroup($row['id_member'], $row['id_group'], $row['hidden'] == 2 ? 'only_additional' : 'auto', true);

Which at the end of that logic the logging is called:

	require_once($sourcedir . '/Logging.php');
	foreach ($members as $member)
		logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');

The important piece is the array of data.

Which the logging function takes:

function logAction($action, array $extra = array(), $log_type = 'moderate')
{
	return logActions(array(array(
		'action' => $action,
		'log_type' => $log_type,
		'extra' => $extra,
	)));
}

Which finally we end up with this:

		if (isset($log['extra']['member_affected']))
			$memID = $log['extra']['member_affected'];
		else
			$memID = $user_info['id'];

The problem is that $memID is null because it tried to access $user_info['id'], which isn't properly defined since we don't load the user up during cron actions. Thus a error is logged for this.

There is two ways to fix this.

  1. member_affected needs added to the logAction data.
  2. Handle the null of $memID and set it to 0.

I'm omitting how to reproduce, because it seems like it may take very specific steps. But I would have to guess this can be triggered by a member requesting access to a group, the moderator acting on it and another member wanting to receive notifications of the action.

Environment (complete as necessary)

  • Version/Git revision: 2.1.4
  • Database Type: N/A
  • Database Version: N/A
  • PHP Version: 8.1

Additional information/references

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions