I've modified it to delete all the upcoming stories bar the last 50 that were submitted, really good for trimming down the size of your database especially if you get a lot of submissions that aren't worth making to the frontpage.
Also, I've put commented code in there that let's you delete all the upcoming stories bar the ones submitted in the last month, if you prefer it that way.
It's nothing technically amazing, thanks for fingerprn for doing all the hard work of figuring out how to physically remove stories and everything related to them cleanly from the database.
To run the script, just put it into your root on the server, log in, and go the files URL. Or do as fingerprn has stated and create a link to it on the admins news management page.
Hope this helps anyone out there and encourages Pligg to put it in as a standard mod as it's really a small hack and won't take 5 mins to put in.
PHP Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'user.php');
include(mnminclude.'smartyvariables.php');
// require user to log in
force_authentication();
// restrict access to god only
$amIgod = 0;
$amIgod = $amIgod + checklevel('god');
$main_smarty->assign('amIgod', $amIgod);
$canIhaveAccess = 0;
$canIhaveAccess = $canIhaveAccess + checklevel('god');
$canIhaveAccess = $canIhaveAccess + checklevel('admin');
if($canIhaveAccess == 0){
$main_smarty->assign('tpl_center', $the_template . '/admin_templates/admin_access_denied');
$main_smarty->display($the_template . '/pligg.tpl');
die();
}
function delete_storylink($linkid) {
$query="SELECT * FROM " . table_links . " WHERE link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
else {$sql_array = mysql_fetch_object($result); }
# delete the story link
$query="DELETE FROM " . table_links . " WHERE link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the story comments
$query="DELETE FROM " . table_comments . " WHERE comment_link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the story pageviews
$query="DELETE FROM " . table_pageviews . " WHERE (pv_type = 'story' OR pv_type = 'out') AND pv_page_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the saved links
$query="DELETE FROM " . table_saved_links . " WHERE saved_link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the story tags
$query="DELETE FROM " . table_tags . " WHERE tag_link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the story trackbacks
$query="DELETE FROM " . table_trackbacks . " WHERE trackback_link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
# delete the story votes
$query="DELETE FROM " . table_votes . " WHERE vote_link_id = '$linkid'";
if (! $result=mysql_query($query)) {error_page(mysql_error());}
}
$queuedAmount = mysql_query("SELECT COUNT(*) FROM `site-dbname-here_links` WHERE `link_status` = 'queued'");
$queuedAmount = mysql_fetch_array($queuedAmount);
$amountToDelete = $queuedAmount['COUNT(*)'] - 50; // amount of stories away from total amount found in upcoming, made ready for deletion
$sql_query = " SELECT *
FROM `site-dbname-here_links`
WHERE `link_status` = 'queued'
ORDER BY `site-dbname-here_links`.`link_date` ASC
LIMIT 0, ".$amountToDelete."";
$result_storylinks = mysql_query($sql_query);
$num_rows = mysql_num_rows($result_storylinks); // for echoing out total that have been deleted
while($storylink = mysql_fetch_object($result_storylinks))
{
delete_storylink($storylink->link_id);
}
# set queued total to 50 in totals
$query="UPDATE " . table_totals . " SET total = '50' WHERE name = 'queued'";
if (!mysql_query($query)) error_page(mysql_error());
echo $num_rows. " queued stories deleted. 50 upcoming stories left.";
// use code below to delete upcoming stories older than 30 days instead
/*$oneMonthAgo = strtotime ( '-1 month' );
$dateToUse = date( "Y-m-d H:i:s", (date( "U", $oneMonthAgo)) );
echo $dateToUse."<br /><br />";
$sql_query = "SELECT * FROM " . table_links . " WHERE link_status = 'queued' && link_date < '".$dateToUse."'";
echo $sql_query; */
?> 



Linear Mode




