[Duplicate] Predefined warnings aren't stored with their warning type
#1
Bug 
Hi again.

Short description:

When warning a user with a predefined warning, the points, duration, admin comments etc. are stored correctly. But the warning type isn't. This leads to only e.g. "(+30 Points)" being displayed in user profiles at /warnings.php?uid=1234 instead of "The predefined reason for this warning (+30 Points)".

Details and potential bugfix:

Set up some warning types in ACP in "admin/index.php?module=config-warning". When issuing such a warning to a user directly (at the page "/warnings.php?action=warn&uid=1234") the points, admin comments and duration will be stored correctly. But the type of the warning will never reach the database.

There are two bugs in datahandlers/warnings.php

First: The method "validate_post()" does
if(!isset($warning['tid']))
{
  $warning['tid'] = $post['tid'];
}

This is wrong, because "tid" of warning isn't supposed to be a "thread id", it is supposed to be the warning "type id". This assignment simply shouldn't be made at all, the whole if-block quoted above can and should be removed.

Second: The final assignment of the data for insertion into the database doesn't respect or handle the actual warning "type".

In the function insert_warning() you will find:
$warning = &$this->data;
$this->write_warning_data = array(
"uid" => (int)$warning['uid'],
"tid" => (int)$warning['tid'],
"pid" => (int)$warning['pid'],
"title" => $db->escape_string($warning['title']),
"points" => (int)$warning['points'],
"dateline" => TIME_NOW,
"issuedby" => (int)$mybb->user['uid'],
"expires" => $db->escape_string($warning['expires']),
"expired" => 0,
"revokereason" => '',
"notes" => $db->escape_string($warning['notes'])
);

Here we can see that the database field "tid" (warning "type id") is assigned the value of "$warning['tid']", which (after fixing the first bug) would be empty anyway. But it should store the warning type, which is available as 'type' in the $warning object. Like this:

"tid" => (int)$warning['type'],

At this point 'type' should be either 'custom' or a number (the warning 'type id'). You may want to do instead some additional validation at this point or somewhere earlier (e.g. in validate_type() ) to ensure that, but it should already work out fine anyway thanks to the (int) cast at that line, converting "custom" to 0 and keeping numeric ids the way they are.
Reply


Messages In This Thread
Predefined warnings aren't stored with their warning type - by Evenprime - 2014-12-03, 09:34 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)