SMF Development > Fixed or Bogus Bugs

2.0 RC3: GM approve attachment - not shown in log.

<< < (2/5) > >>

Arantor:
Yay, because I was solving your first problem I missed your other posts.

If I'm honest I'm also a little annoyed you seem to assume I'd provide a fix for you. I AM providing a possible fix but it's not tested and I'm doing it to help the devs out with the mountain of bugs, not just for your specific benefit.


Here's the function that does it in ManageAttachments.php.


--- Code: ---function ApproveAttachments($attachments)
{
global $smcFunc;

if (empty($attachments))
return 0;

// For safety, check for thumbnails...
$request = $smcFunc['db_query']('', '
SELECT
a.id_attach, a.id_member, IFNULL(thumb.id_attach, 0) AS id_thumb
FROM {db_prefix}attachments AS a
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)
WHERE a.id_attach IN ({array_int:attachments})
AND a.attachment_type = {int:attachment_type}',
array(
'attachments' => $attachments,
'attachment_type' => 0,
)
);
$attachments = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Update the thumbnail too...
if (!empty($row['id_thumb']))
$attachments[] = $row['id_thumb'];

$attachments[] = $row['id_attach'];
}
$smcFunc['db_free_result']($request);

// Approving an attachment is not hard - it's easy.
$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET approved = {int:is_approved}
WHERE id_attach IN ({array_int:attachments})',
array(
'attachments' => $attachments,
'is_approved' => 1,
)
);

// Remove from the approval queue.
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}approval_queue
WHERE id_attach IN ({array_int:attachments})',
array(
'attachments' => $attachments,
)
);
}
--- End code ---

Here's the function I'd suggest in replacement.

--- Code: ---function ApproveAttachments($attachments)
{
global $smcFunc;

if (empty($attachments))
return 0;

// For safety, check for thumbnails...
$request = $smcFunc['db_query']('', '
SELECT
a.id_attach, a.id_member, IFNULL(thumb.id_attach, 0) AS id_thumb
FROM {db_prefix}attachments AS a
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)
WHERE a.id_attach IN ({array_int:attachments})
AND a.attachment_type = {int:attachment_type}',
array(
'attachments' => $attachments,
'attachment_type' => 0,
)
);
$attachments = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Update the thumbnail too...
if (!empty($row['id_thumb']))
$attachments[] = $row['id_thumb'];

$attachments[] = $row['id_attach'];
}
$smcFunc['db_free_result']($request);

// Approving an attachment is not hard - it's easy.
$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET approved = {int:is_approved}
WHERE id_attach IN ({array_int:attachments})',
array(
'attachments' => $attachments,
'is_approved' => 1,
)
);

if (!empty($attachments))
{
// In order to log the attachments, we really need their message and filename
$request = $smcFunc['db_query']('', '
SELECT m.id_msg, a.filename
FROM {db_prefix}attachments AS a
INNER JOIN {db_prefix}messages AS m ON (a.id_msg = m.id_msg)
WHERE a.id_attach IN ({array_int:attachments})
AND a.attachment_type = {int:attachment_type}',
array(
'attachments' => $attachments,
'attachment_type' => 0,
)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
logAction(
'approve_attach',
array(
'message' => $row['id_msg'],
'filename' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($row['filename'])),
)
);
}
}

// Remove from the approval queue.
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}approval_queue
WHERE id_attach IN ({array_int:attachments})',
array(
'attachments' => $attachments,
)
);
}
--- End code ---

Also needs the following language string. This would go in Modlog.english.php.


--- Code: ---$txt['modlog_ac_approve_attach'] = 'Approved &quot;{filename}&quot; in &quot;{message}&quot;';
--- End code ---

I HAVE NOT TESTED THIS!


If I get time I'll look at adding an entry to the remove function too.

fiver:
Hi Arantor,


Please do not be annoyed. I do not assume you'd provide a fix for me. I am simply reporting what I discovered, suggest what I feel is logical in the shoes of an admin, and hope these suggestions will help improve smf. It's not just for my specific benefit.


I have some requests for coding in other boards without getting any solution, and I did not whine about it. In fact I laugh about it when I think - would it be just as fast if I try to learn php than to wait 6 to 12 months for no reply. ;D


I am reading "PHP 6 MySQL Programming for the Absolute Beginner, 2009 Andy Harris" and up to the page on variables and constants ;) , maybe it will take me another few months (if not years) and I can help other members here.


I did try to help reply to a few members here within my limited knowledge.


Many thanks again for your response.

Arantor:
The way your comment came out seemed very much as if you were asking me to fix it, while all I was doing was establishing that if it is a bug (which it is, it's not doing something it probably should be), what the correct course of action is. I did overreact, I'm sorry, just I am sick to the back teeth of people posting and expecting answers.

Anyway the above should fix you up for attachment approval logging.

As for attachment removal, surprisingly that's actually a lot more complex, though simpler when I did it in SimpleDesk because it doesn't have to navigate the 1k lines of code that makes up the single big save-post function in SMF. You possibly could do it in the master remove attachments routine though if you're careful about it, and again it's down to whether you do one or multiple log items (for SD we did just one item for added or removed attachments, there's enough in the action log there!)

fiver:
I know how you feel. ;D


I have a Personal Request board for free birth chart reading by any learning/practising members. Some people bump their requests within hours, sobbing that no one wants to read their charts.


My GM and I have to remind them that it is free reading, and sometimes it takes weeks to get a respond. But last few weeks that board has become so hot because a few new and old members are helping to read birth charts again.  And now people are expecting to get a free reading within hours again. ;D  And there are some who hijack another's topic. Some double post their birthdate in 2 or 3 wrong boards. That's Life in the internet forums. ;D


Hope you have a nice weekend.

ѕησω:
When i apply your fix Arantor, my test account makes a reply with a attachment, the attachment is approved automatically without nothing in the mod log.

I've double checked my test users permissions as well. Post attachments, but hide until approved is unchecked in board permission default.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version