[Unknown]
Global Moderator
YaBB God
    
Posts: 7830


|
 |
Re:Delete old posts by board?
« Reply #2 on: February 17, 2003, 07:43:44 AM » |
|
This was the first thing I ever wrote, and I really mussed up bad.
Anyhow, here is a new one - fixed completely. (or hopefully so.)
<edit file> Sources/RemoveOldThreads.php </edit file>
<search for> echo ' <table width="450" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF"> <tr> <td width="100%" valign="top"> <table width="100%" border="0" cellspacing="1" bgcolor="#6394BD" class="bordercolor"> <tr> <td bgcolor="#6E94B7" class="titlebg"><font size="2" color="#FFFFFF" class="text1"><b>' . $txt[120] . ' ' . $maxdays . '</b></font></td> </tr><tr> <td align="center" bgcolor="#AFC6DB" class="windowbg"><br /> <form action="?action=removeoldthreads2" method="post"> <font size="2">' . $txt[124] . ' <input type="text" name="maxdays" value="' . $maxdays . '" size="2" /> ' . $txt[579] . ' <input type="submit" value="' . $txt[31] . '" /></font> <br /><br /><b><a href="?action=admin">' . $txt[193] . '</a></b> <input type="hidden" name="sc" value="' . $sc . '" /> </form> </td> </tr> </table> </td> </tr> </table>'; </search for>
<replace> echo ' <table width="450" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF"> <tr> <td width="100%" valign="top"> <table width="100%" border="0" cellspacing="1" bgcolor="#6394BD" class="bordercolor"> <tr> <td bgcolor="#6E94B7" class="titlebg"><font size="2" color="#FFFFFF" class="text1"><b>' . $txt[120] . ' ' . $maxdays . '</b></font></td> </tr><tr> <td align="center" bgcolor="#AFC6DB" class="windowbg"><br /> <form action="?action=removeoldthreads2" method="post"> <font size="2">' . $txt[124] . ' <input type="text" name="maxdays" value="' . $maxdays . '" size="2" /> ' . $txt[579] . '<br /><br />'; $remoldthreadsboards = mysql_query(" SELECT b.ID_BOARD, b.name FROM {$db_prefix}boards as b, {$db_prefix}categories as c WHERE b.ID_CAT = c.ID_CAT ORDER BY c.catOrder, b.boardOrder;") or database_error(__FILE__, __LINE__); while($row = mysql_fetch_assoc($remoldthreadsboards)) { echo ' <input type="checkbox" name="doboard[]" value="' . $row['ID_BOARD'] . '" />' . $row['name'] . '<br />'; } echo ' <br /> <input type="submit" value="' . $txt[31] . '" /></font> <br /><br /><b><a href="?action=admin">' . $txt[193] . '</a></b> <input type="hidden" name="sc" value="' . $sc . '" /> </form> </td> </tr> </table> </td> </tr> </table>'; </replace>
<search for> function RemoveOldThreads2() { global $yytitle, $settings, $txt, $db_prefix, $modSettings, $maxdays;
checkSession(); if ($settings[7] != "Administrator") fatal_error($txt[1]);
$yytitle = "$txt[120] $maxdays"; $threshold = time()-(24*60*60*$maxdays); template_header(); $request = mysql_query("SELECT t.ID_TOPIC, t.ID_BOARD, t.ID_POLL FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m WHERE (m.ID_MSG = t.ID_LAST_MSG AND m.posterTime < $threshold);") or database_error(__FILE__, __LINE__); while ($row = mysql_fetch_row($request)) { $msgs = 0; echo "$txt[50] - $row[0]<br />\n"; echo " $txt[49]<br />\n"; //Lines 81-86 all there to delete attachments on thread deletion - Jeff $result = mysql_query("SELECT attachmentFilename FROM {$db_prefix}messages WHERE ID_TOPIC=$row[0] AND (attachmentFilename IS NOT NULL);") or database_error(__FILE__, __LINE__); if (mysql_num_rows($result) > 0) while ($attachRow = mysql_fetch_array($result)) unlink($modSettings['attachmentUploadDir'] . "/" . $attachRow['attachmentFilename']); $result = mysql_query ("DELETE FROM {$db_prefix}messages WHERE ID_TOPIC='$row[0]';") or database_error(__FILE__, __LINE__); $msgs = mysql_affected_rows(); $result = mysql_query("DELETE FROM {$db_prefix}polls WHERE ID_POLL='$row[2]' LIMIT 1;") or database_error(__FILE__, __LINE__); $result = mysql_query ("DELETE FROM {$db_prefix}topics WHERE ID_TOPIC='$row[0]';") or database_error(__FILE__, __LINE__); $result = mysql_query("DELETE FROM {$db_prefix}log_topics WHERE ID_TOPIC='$row[0]'") or database_error(__FILE__, __LINE__); $result = mysql_query ("DELETE FROM {$db_prefix}calendar WHERE ID_TOPIC='$row[0]'") or database_error(__FILE__, __LINE__); $result = mysql_query ("UPDATE {$db_prefix}boards SET numTopics=numTopics-1, numPosts=numPosts-$msgs WHERE ID_BOARD=$row[1];") or database_error(__FILE__, __LINE__);
updateStats('message'); updateStats('topic'); updateLastMessage($row[1]); } echo " <br />$txt[51]<br /> <br />"; footer(); obExit(); } </search for>
<replace> function RemoveOldThreads2() { global $yytitle, $settings, $txt, $db_prefix, $modSettings, $maxdays, $doboard;
checkSession(); is_admin();
$yytitle = $txt[120] . ' ' . $maxdays; $threshold = time() - (24 * 60 * 60 * $maxdays); template_header();
foreach($doboard as $remoldthreadsboard) { $request = mysql_query(" SELECT t.ID_TOPIC, t.ID_BOARD, t.ID_POLL FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m WHERE m.ID_MSG = t.ID_LAST_MSG AND m.posterTime < $threshold AND t.ID_BOARD = $remoldthreadsboard"); while ($row = mysql_fetch_assoc($request)) { $msgs = 0; echo "$txt[50] - $row[ID_TOPIC]<br />\n"; echo " $txt[49]<br />\n"; //Lines 81-86 all there to delete attachments on thread deletion - Jeff $result = mysql_query("SELECT attachmentFilename FROM {$db_prefix}messages WHERE ID_TOPIC=$row[ID_TOPIC] AND (attachmentFilename IS NOT NULL);") or database_error(__FILE__, __LINE__); if (mysql_num_rows($result) > 0) while ($attachRow = mysql_fetch_assoc($result)) unlink($modSettings['attachmentUploadDir'] . '/' . $attachRow['attachmentFilename']); mysql_query ("DELETE FROM {$db_prefix}messages WHERE ID_TOPIC=$row[ID_TOPIC];") or database_error(__FILE__, __LINE__); $msgs = mysql_affected_rows();
mysql_query("DELETE FROM {$db_prefix}polls WHERE ID_POLL=$row[ID_POLL] LIMIT 1;") or database_error(__FILE__, __LINE__); mysql_query("DELETE FROM {$db_prefix}topics WHERE ID_TOPIC=$row[ID_TOPIC];") or database_error(__FILE__, __LINE__); mysql_query("DELETE FROM {$db_prefix}log_topics WHERE ID_TOPIC=$row[ID_TOPIC]") or database_error(__FILE__, __LINE__); mysql_query("DELETE FROM {$db_prefix}calendar WHERE ID_TOPIC=$row[ID_TOPIC]") or database_error(__FILE__, __LINE__);
mysql_query("UPDATE {$db_prefix}boards SET numTopics=numTopics-1, numPosts=numPosts-$msgs WHERE ID_BOARD=$remoldthreadsboard;") or database_error(__FILE__, __LINE__); }
updateLastMessage($remoldthreadsboard); } updateStats('message'); updateStats('topic');
echo " <br />$txt[51]<br /> <br />"; footer(); obExit(); } </replace>
(substitute a tab for any three spaces.)
-[Unknown]
|