MyBB Community Forums

Full Version: [F] Attachments: bug returned
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
See attachment.

Last user, who has been deleted before is a top 5 username there. But nothing's shown there.
Easy fix:
in admin/modules/forum/attachments.php find:
	$query = $db->query("
		SELECT a.*, u.uid, u.username, SUM(a.filesize) as totalsize
		FROM ".TABLE_PREFIX."attachments a  
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
		GROUP BY a.uid
		ORDER BY totalsize DESC
		LIMIT 5
	");
replace with
	$query = $db->query("
		SELECT a.*, u.uid, u.username, SUM(a.filesize) as totalsize
		FROM ".TABLE_PREFIX."attachments a  
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
		WHERE u.uid != 0
		GROUP BY a.uid
		ORDER BY totalsize DESC
		LIMIT 5
	");
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.
Actually, wait, I might have made a mistake, does that actually work with MySQL? u.uid is probably actually NULL, but I think MySQL treats it as 0, but that's just a guess...
(I can't test things here at Uni)
Yes, I believe MySQL will treat it as a null if the column row doesn't exist when left joining. a u.uid > 0 is probably better since that would include null's too (null can't be more then 0)
So what's the fix now then?
Try This:
Still the same as before...
I think there's a bit of an issue with using this:
		if(!$user['uid'])
		{
			$user['username'] = $lang->na;
		}
Since "a.*" will pull in a uid with a number. Try changing something like this
SELECT a.*, u.uid, u.username, SUM(a.filesize) as totalsize
to
SELECT a.*, u.uid AS useruid, u.username, SUM(a.filesize) as totalsize
and make the other appropriate change.

(or, if you wanted to, you could check for the username)
How will it put in a uid with a number higher then 0 if it doesn't even exist? Either way my "if statement" should catch all cases - It's not a strict comparison.
Pages: 1 2