Welcome, Guest. Please Login or Register.
May 10, 2025, 11:43:07 AM
Home Help Search Log in Register
News: If you are still using YaBB SE, please consider upgrading to SMF as soon as possible.

YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Delete old posts by board? « previous next »
Pages: [1] Reply Ignore Print
Author Topic: Delete old posts by board?  (Read 341 times)
Akimbo
Noobie
*
Posts: 3


ZeroOne

WWW
Delete old posts by board?
« on: February 17, 2003, 06:15:09 AM »
Reply with quote

Has anyone thought about something like this?  I have some boards in which that I would like to delete all posts that are older than 30 days, and I have some that I would like to keep for archival purposes.

Would anyone else find this useful?
Logged
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Delete old posts by board?
« Reply #1 on: February 17, 2003, 06:27:02 AM »
Reply with quote

I agree, would be useful.
Logged

[Unknown]
Global Moderator
YaBB God
*****
Posts: 7830


ICQ - 179721867unknownbrackets@hotmail.com WWW
Re:Delete old posts by board?
« Reply #2 on: February 17, 2003, 07:43:44 AM »
Reply with quote

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 "&nbsp;&nbsp;$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 "&nbsp;&nbsp;$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]
Logged
Chris77
Noobie
*
Posts: 23


christ77@teminfo.be WWW
Re:Delete old posts by board?
« Reply #3 on: February 17, 2003, 12:01:58 PM »
Reply with quote

Have you are this mod for the version 1.4.1, Thank you.  ;)
Logged

Pages: [1] Reply Ignore Print 
YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Delete old posts by board? « previous - next »
 


Powered by MySQL Powered by PHP YaBB SE Community | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
SMF 2.1.4 © 2023, Simple Machines
Valid XHTML 1.0! Valid CSS

Page created in 0.098 seconds with 21 queries.