Recycle all topics older then x days

Started by DeadMetal, November 05, 2004, 06:21:25 AM

Previous topic - Next topic

DeadMetal

Hi,

What I would like to do is recycle instead of delete all topics older then x days. Is that already possible? It would be a nice feature.

Kender

try this
  • go to admin
  • go to edit features and options
  • go to the bottom of basic forum features
  • check enable recycling of deleted topics
  • choose a board

it wont 'auto' take care of it in XX days but it will take deleted messages there
http://chucknorris2012.com  Avoid a roundhouse kick to the head!  Sign the petition

DeadMetal

Yeah, manually deleted topics end up in the recycle bin, but in the Admin panel there is a possibility to 'Delete all topics older then x days'. When I do that, they don't.

Oldiesmann

Create a script with this in it and put it in your main SMF directory, then run it whenever you want to move the topics... Replace {days} with the number of days (ie 30).

<?php
include_once('SSI.php');
include_once(
'Sources/RemoveTopic.php');

$query db_query("SELECT t.ID_TOPIC
     FROM 
{$db_prefix}topics AS t, {$db_prefix}messages AS m
     WHERE m.ID_MSG = t.ID_LAST_MSG
     AND m.posterTime < " 
time() * 3600 24 * {days} . (empty($modSettings['enableStickyTopics']) ? '' "
     AND t.isSticky = 0"
), __FILE____LINE__);

while(
$result mysql_fetch_assoc($query))
{
$topics[] = $result['ID_TOPIC'];
}

mysql_free_result($query);

removeTopics($topicsfalsefalse);
?>
Michael Eshom
Christian Metal Fans

DeadMetal

Hmm, that moved almost all my topics to the recycle bin! (even the newest ones).

It should only move topics that hasn't had new messages for x days or more, but it shouldn't move stickys.

Grudge

This:

" . time() * 3600 * 24 * {days}


Should be:

" . time() - 3600 * 24 * {days}
I'm only a half geek really...

Oldiesmann

Whoops! Sorry about that. Thanks for the correction Grudge. Apologies for moving so many of your topics :)
Michael Eshom
Christian Metal Fans

DeadMetal

Not a problem Oldies!
But it doesn't seem to work right now, using this code:


<?php
include_once('SSI.php');
include_once(
'Sources/RemoveTopic.php');

$query db_query("SELECT t.ID_TOPIC
     FROM 
{$db_prefix}topics AS t, {$db_prefix}messages AS m
     WHERE m.ID_MSG = t.ID_LAST_MSG
     AND m.posterTime < " 
time() - 3600 24 30 . (empty($modSettings['enableStickyTopics']) ? '' "
     AND t.isSticky = 0"
), __FILE____LINE__);

while(
$result mysql_fetch_assoc($query))
{
$topics[] = $result['ID_TOPIC'];
}

mysql_free_result($query);

removeTopics($topicsfalsefalse);
?>



Error:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '-2592000
AND t.isSticky = 0' at line 1
Bestand: /home/binaries/public_html/danielforum/recycle_old_topics.php
Regel: 9


dschwab9

#8
Try this:

You'll need to replace 30 with the correct number of days in this line:
         AND m.posterTime < " . (time() - 3600 * 24 * 30) . (empty($modSettings['enableStickyTopics']) ? '' : "

And 9, 25, etc with the correct board numbers in this line:
         AND t.ID_BOARD IN ('9', '10', '25', '34')",__FILE__, __LINE__);

And set the path to settings.php here:
include_once('public_html/Settings.php');

<?php
define
('SMF'1);
include_once(
'public_html/Settings.php');
include_once(
$sourcedir '/Subs.php');
include_once(
$sourcedir '/Errors.php');
include_once(
$sourcedir '/Load.php');

// If $maintenance is set specifically to 2, then we're upgrading or something.
if ($maintenance == 2)
db_fatal_error();

// Connect to the MySQL database.
$db_connection = @mysql_connect($db_server$db_user$db_passwd);

// Show an error if the connection couldn't be made.
if (!$db_connection || !@mysql_select_db($db_name$db_connection))
db_fatal_error();

// Load the settings from the settings table, and perform operations like optimizing.
reloadSettings();

$request db_query("
SELECT t.ID_TOPIC
FROM 
{$db_prefix}topics AS t, {$db_prefix}messages AS m
WHERE m.ID_MSG = t.ID_LAST_MSG
AND m.posterTime < " 
. (time() - 3600 24 30) . (empty($modSettings['enableStickyTopics']) ? '' "
AND t.isSticky = 0"
) . "
AND t.ID_BOARD IN ('9', '10', '25', '34')"
,__FILE____LINE__);
$topics = array();
while ($row mysql_fetch_assoc($request))
$topics[] = $row['ID_TOPIC'];
mysql_free_result($request);

include_once(
$sourcedir '/RemoveTopic.php');
removeTopics($topicsfalsefalse);

// Log an action into the moderation log.

if (!empty($modSettings['modlog_enabled']))
{
$extra = array('days' => '30');
db_query("
INSERT INTO 
{$db_prefix}log_actions
(logTime, ID_MEMBER, IP, action, extra)
VALUES (" 
time() . ", '0', '127.0.0.1', 'Autoprune', '" addslashes(serialize($extra)) . "')"__FILE____LINE__);
}

echo'Pruning Successful';
?>


DeadMetal

Thanks, it works (allmost flawless)!

I get the following error message:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE b.ID_BOARD = 6' at line 3

But when I reload the page after that error, the pruning is succesful, and it is like that every time.

dschwab9

line 3 of what file?  There's nothing to that effect in line 3 of the query in the script I posted.

DeadMetal

I think something in the file that is included in line 3.
I didn't change anything apart from the three things you mentioned.

dschwab9

Hmmm.  I copied and pasted that EXACTLY from my server, and works flawlessly there.  Is board 6 one of the ones you're pruning?

Any idea where this line is?  WHERE b.ID_BOARD = 6'
If so, could you post that whole query?

dschwab9

Are you pruning all the boards, or just a few?

If all of them, you could change:

$request = db_query("
SELECT t.ID_TOPIC
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m
WHERE m.ID_MSG = t.ID_LAST_MSG
AND m.posterTime < " . (time() - 3600 * 24 * 30) . (empty($modSettings['enableStickyTopics']) ? '' : "
AND t.isSticky = 0") . "
AND t.ID_BOARD IN ('9', '10', '25', '34')",__FILE__, __LINE__);


To:

$request = db_query("
SELECT t.ID_TOPIC
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m
WHERE m.ID_MSG = t.ID_LAST_MSG
AND m.posterTime < " . (time() - 3600 * 24 * 30) . (empty($modSettings['enableStickyTopics']) ? '' : "
AND t.isSticky = 0") . ",__FILE__, __LINE__);

DeadMetal

#14
Board 6 is the board which acts as the recycle bin, so all the old topics are moved to that board. I don't prune that board (obviously), because then all the old topics in the recycle bin are moved to the recycle bin ;)
Remember that I recycle the topics, not remove them.

Unfortunately I didn't find what causes the error (the first time only).

dschwab9

That query is in RemoveTopic.php it looks like, but I don't understand why it's failing.  Is it successfully moving them to the recycle board on the first try?

DeadMetal

#16
Yes, it is succesful the first time, even though I get the error message.

I'm not sure, but it seems that it gives an error when there are messages to recycle and it doesn't when there is nothing to prune.

digit

I'm considering using this script...



<?php
define
('SMF'1);
include_once(
'Settings.php');
include_once(
$sourcedir '/Subs.php');
include_once(
$sourcedir '/Errors.php');
include_once(
$sourcedir '/Load.php');

// If $maintenance is set specifically to 2, then we're upgrading or something.
if ($maintenance == 2)
  
db_fatal_error();

// Connect to the MySQL database.
   
$db_connection = @mysql_connect($db_server$db_user$db_passwd);
    
// Show an error if the connection couldn't be made.
if (!$db_connection || !@mysql_select_db($db_name$db_connection))
   
db_fatal_error();
        
// Load the settings from the settings table, and perform operations like optimizing.
reloadSettings();

    
$request db_query("
              SELECT t.ID_TOPIC
               FROM 
{$db_prefix}topics AS t, {$db_prefix}messages AS m
          WHERE m.ID_MSG = t.ID_LAST_MSG
                     AND m.posterTime < " 
. (time() - 3600 24 38) . (empty($modSettings['enableStickyTopics']) ? '' "
                       AND t.isSticky = 0"
) . "
                   AND t.ID_BOARD IN ('12')"
,__FILE____LINE__);
 
$topics = array();
      while (
$row mysql_fetch_assoc($request))
             
$topics[] = $row['ID_TOPIC'];
      
mysql_free_result($request);

include_once(
$sourcedir '/RemoveTopic.php');
      
removeTopics($topicsfalsefalse);

      
// Log an action into the moderation log.

 
if (!empty($modSettings['modlog_enabled']))
       {
$extra = array('days' => '30');
            
db_query("
                        INSERT INTO 
{$db_prefix}log_actions
                              (logTime, ID_MEMBER, IP, action, extra)
                    VALUES (" 
time() . ", '0', '127.0.0.1', 'Autoprune', '" addslashes(serialize($extra)) . "')"__FILE____LINE__);
 }
        
        echo
'Pruning Successful';

?>





...  but I have a problem...

I don't want manually deleted (By clicking on Remove Topic in the message page) messages to go into my recycle forum.  I want them deleted.

I only want those messages deleted by the Maintenance area of the admin panel to go the the recycle forum. i.e., those messages removed that are older than x days.

I'm assuming this script will automatically detect the settings in the admin panel, right?

So, how do I do that?

Thx.
Happily using a heavily modified 1.1.16 version of SMF!

2748011 Posts in 320998 Topics by 50986 Members


SOLD my website - thanks it was a good run - they converted to vbadvanced. (and screwed it up good!)

.Martin.

Quote from: Kender on November 05, 2004, 06:37:38 AM
try this
  • go to admin
  • go to edit features and options
  • go to the bottom of basic forum features
  • check enable recycling of deleted topics
  • choose a board

it wont 'auto' take care of it in XX days but it will take deleted messages there

And where can I find this in SMF 1.1 RC3?

Oldiesmann

Michael Eshom
Christian Metal Fans

Advertisement: