Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: tesser on August 06, 2010, 12:53:12 AM

Title: remove old topics by date
Post by: tesser on August 06, 2010, 12:53:12 AM
Is there any way to remove old posts by date and not by  how many days it has not been posted in ?

RC3
Title: Re: remove old topics by date
Post by: Kill Em All on August 06, 2010, 01:26:07 AM
Well there is a problem with that, what if you have a topic that hasn't been posted in awhile but then it is bumped and brought back to life.

You would be getting rid of posts that you don't want to be getting rid of, and possibly entire topics.
Title: Re: remove old topics by date
Post by: Oranos on August 06, 2010, 01:26:34 AM
you can run this code, it should do what you want:


<?php
require_once(dirname(__FILE__) . '/SSI.php');
global
$smcFunc, $user_info;

if(isset(
$_POST['submit']) && $user_info['is_admin']){
$delete_time = $_POST['delete_time'];
$operation = $smcFunc['db_query']('', '
DELETE FROM {db_prefix}messages
WHERE poster_time < {int:time}'
,
array(
'time' => strtotime($delete_time),
)
);
echo $operation ? '<div style="text-align: center; color: green;">Operation completed successfully</div>' : '<div style="text-align: center; color: red;">There was an error...</div>';
}else if(
$user_info['is_admin'])
echo '
<form action="delete_post.php" method="post">
<div style="text-align: center;">Enter Date (mm/dd/yyyy): <input type="text" name="delete_time" /> <input type="submit" name="submit" value="Submit" /></div>
</form>'
;
else
echo '<div style="text-align: center;">Go Away...</div>';
?>


You should be able to just put that in a php file named "delete_post" in your smf install dir and run it from your web browser. Just put in the date you want in the text box and click submit. The format should be mm/dd/yyyy, but the script will tell you that anyway. All post before that day will be deleted. Also, only logged on administrators can run that script, as a security precaution.

EDIT:

Remember to recount totals and statistics after running this.
Title: Re: remove old topics by date
Post by: tesser on August 06, 2010, 05:57:29 AM
thank you il give it a go  once my back up is done

the reason i need to delete posts from a certain date is they contain links from  a 2 nd site i once had and that site is now gone so hence dead links there is about 2000 posts and thats alot to move one by one
Title: Re: remove old topics by date
Post by: tesser on August 06, 2010, 09:21:57 AM
The code above works in every way but  the posts are still in place  i installed to where my smf is  then run it from my browser  entered the date wanted hit submit and got a green Operation completed successfully but there still there ??

any ideas ?
Title: Re: remove old topics by date
Post by: Deaks on August 30, 2010, 12:45:01 PM
tesser did yuo get this working?