Delete All Upcoming Stories Except The Last 50

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2008, 04:10 PM
rossoonline's Avatar
New Pligger
 
Join Date: May 2007
Posts: 25
Using the post by fingerprn here: http://forums.pligg.com/pligg-mods/1...d-stories.html

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; */

?>
PS. Where it says "site-dbname-here" replace it with the name you used for your sites db tables.

Last edited by rossoonline; 04-13-2008 at 04:16 PM.
Reply With Quote
  #2 (permalink)  
Old 04-13-2008, 04:30 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Excellent coding work! I would suggest to link to this file in the same way as fingerprn suggest at his step 1.


P.S.: Could you help to solve a small variable visibility problem? (http://forums.pligg.com/bug-report/1...published.html)
Reply With Quote
  #3 (permalink)  
Old 08-06-2008, 05:27 AM
Donor
 
Join Date: Jan 2007
Posts: 377
Will this still work with latest pligg version 9.9.5? If this is working fine with latest pligg version 9.9.5, anyone know how to modify this to have it deletes published stories within certain time frame? Thanks...
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't sort upcoming stories by popularity behoppe Questions and Comments 1 05-29-2009 03:32 PM
Discard upcoming stories that are not published after a certain amount of time ablaye Questions and Comments 4 01-21-2008 03:10 AM
Discard old upcoming stories ablaye Questions and Comments 2 12-14-2007 01:51 AM
Special message if no stories on upcoming page? tangmonkey Questions and Comments 1 11-15-2007 01:59 PM
[MOD] Showing # of Upcoming Stories in v9.6 abcdefgary Questions and Comments 9 08-01-2007 06:13 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development