Go Back   Pligg CMS Forum > Pligg Development > Pligg Mods

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2007, 04:40 PM
Pligg Donor
Pligg Version: 9.8.2 +
Pligg Template: yget
 
Join Date: Jul 2007
Posts: 117
Thanks: 9
Thanked 35 Times in 8 Posts
Method for deleting discarded stories

So far, I haven't found a modification on here for completely deleting a story from the database. For example, even though the link may be removed, the votes, comments, etc. remain. Therefore, I've decided to create my own solution and thought I'd share it with you.

I'll warn you upfront that I'm not a developer and I don't know a thing about object oriented programming. Therefore, I'm sure there's a better way to do this other than my little hack. Still, the result is the same so I'm sticking with this until somebody comes up with something better.

Version: 1.2

STEP 1:

Open admin_links_center.tpl (filename corrected from initial post) and find "<a href="javascript:uncheck_all()">Uncheck All</a>". Add the following:

Code:
<br><a href="admin_links.php" onclick="javascript:window.open('admin_delete_stories.php', 'resultwindow', 'width=300, height=200')">Delete discarded stories</a>

STEP 2:

Create a file called "admin_delete_stories.php" and add the following:


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)) {die (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)) {die (mysql_error());}
    
    # delete the story comments
    $query="DELETE FROM " . table_comments . " WHERE comment_link_id = '$linkid'";
    if (! $result=mysql_query($query)) {die (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)) {die (mysql_error());}
	
    # delete the saved links
    $query="DELETE FROM " . table_saved_links . " WHERE saved_link_id = '$linkid'";
    if (! $result=mysql_query($query)) {die (mysql_error());}	
	
    # delete the story tags
    $query="DELETE FROM " . table_tags . " WHERE tag_link_id = '$linkid'";
    if (! $result=mysql_query($query)) {die (mysql_error());}	 		 

    # delete the story trackbacks
    $query="DELETE FROM " . table_trackbacks . " WHERE trackback_link_id = '$linkid'";
    if (! $result=mysql_query($query)) {die (mysql_error());}    

    # delete the story votes
    $query="DELETE FROM " . table_votes . " WHERE vote_link_id = '$linkid'";
    if (! $result=mysql_query($query)) {die (mysql_error());}   
  
	}

	
$sql_query = "SELECT * FROM " . table_links . " WHERE link_status = 'discard'";
			
$result_storylinks = mysql_query($sql_query);
$num_rows = mysql_num_rows($result_storylinks);
		while($storylink = mysql_fetch_object($result_storylinks))
		{
			delete_storylink($storylink->link_id);
		}
	
# set discards total to zero
$query="UPDATE " . table_totals . " SET total = '0' WHERE name = 'discard'";
if (!mysql_query($query)) {die (mysql_error());}

	
echo $num_rows. " discarded stories deleted";

?>
<p><a href="admin_optimize_database.php">Click here</a> to optimize database</p>

STEP 3 (OPTIONAL):

This next file allows you to optimize your database after deleting your stories. This isn't necessary, but it's a good idea because the deleted stories will create overhead in your MySQL database.

Create a file called "admin_optimize_database.php" and add the following:


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();
}

// $message = "";

    $query = "SHOW TABLE STATUS";
    $result=mysql_query($query);
    $table_list = "";
    while ($cur_table = mysql_fetch_object($result)) {
        $table_list .= $cur_table->Name.", ";
    }

    if (!empty($table_list)) {
        $table_list = substr($table_list, 0, -2);
        $query = "OPTIMIZE TABLE ".$table_list;
        mysql_query($query);
        $message = "Database optimized";
    }

echo $message

?>

Version changes:
Version 1.1 (12-31-2007): Made accessible to administrators only.
Version 1.2 (5-4-2008): Removed need for custom error page.

Last edited by fingerprn; 05-04-2008 at 12:38 PM. Reason: Removed need for custom error page.
Reply With Quote
  #2 (permalink)  
Old 11-04-2007, 06:01 PM
chuckroast's Avatar
Pligg Developer
Pligg Version: 1.0
Pligg Template: ExpertVision
 
Join Date: Jun 2006
Location: PA
Posts: 2,219
Thanks: 163
Thanked 425 Times in 264 Posts
Nice work, and thank you for sharing.
__________________
Visit PliggPro the official Pligg Mods & Template Shop!

Reply With Quote
  #3 (permalink)  
Old 11-04-2007, 09:33 PM
New Pligger
Pligg Version: 9.8.2
Pligg Template: Default
 
Join Date: Oct 2007
Posts: 29
Thanks: 2
Thanked 17 Times in 3 Posts
Thanks for this. I had just posted the other day asking if there was any reason partially submitted stories are logged to the database with a status of discard. This will also help take care of these. Thanks!
Reply With Quote
  #4 (permalink)  
Old 11-04-2007, 10:06 PM
crakez's Avatar
Constant Pligger
Pligg Version: 9.8.2
Pligg Template: Fresh Template
 
Join Date: Jul 2007
Location: Australia
Posts: 143
Thanks: 14
Thanked 8 Times in 6 Posts
Send a message via MSN to crakez Send a message via Skype™ to crakez
Thanks a lot for sharing.
Reply With Quote
  #5 (permalink)  
Old 11-10-2007, 06:45 AM
New Pligger
 
Join Date: Sep 2007
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
Wow.. Thanks.

I used to delete the data directly in phpmyadmin.

This works great.
Reply With Quote
  #6 (permalink)  
Old 11-10-2007, 11:20 AM
Pligg Donor
 
Join Date: Sep 2007
Posts: 188
Thanks: 7
Thanked 37 Times in 26 Posts
In your STEP 1, are you actually referring to admin_links_center.tpl instead of admin_links_center.php? Because there isn't a admin_links_center.php file in my version (v. 9.8.2).
Reply With Quote
  #7 (permalink)  
Old 11-10-2007, 11:36 AM
Constant Pligger
 
Join Date: Jun 2006
Posts: 109
Thanks: 75
Thanked 1 Time in 1 Post
nice work

cool!

noyP
Reply With Quote
  #8 (permalink)  
Old 11-10-2007, 12:55 PM
Constant Pligger
 
Join Date: Jan 2007
Posts: 309
Thanks: 0
Thanked 7 Times in 5 Posts
this method rocks, and you're good with database stuffs!
__________________
http://www.blogmyway.org
Reply With Quote
  #9 (permalink)  
Old 11-10-2007, 02:36 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 60
Thanks: 22
Thanked 7 Times in 6 Posts
Thanks so much!
Reply With Quote
  #10 (permalink)  
Old 11-10-2007, 03:02 PM
nzbullet's Avatar
Constant Pligger
Pligg Version: 9.9.
Pligg Template: Very Custom
 
Join Date: Jun 2007
Location: New Zealand
Posts: 133
Thanks: 17
Thanked 19 Times in 14 Posts
Send a message via MSN to nzbullet
Thumbs up

Quote:
Originally Posted by blaze View Post
In your STEP 1, are you actually referring to admin_links_center.tpl instead of admin_links_center.php? Because there isn't a admin_links_center.php file in my version (v. 9.8.2).
Yes - The file is actually admin_links_center.tpl - well at least it is in 9.8.2

fingerprn - Awesome mod. Nice and easy to add to site, following instructions you posted. Also easy to use.

One comment the file, incase anyone can't find it, is located as follows:

/pligg/templates/yget/admin_templates/admin_links_center.tpl

The new files should just be added to the root directory of your site along with the other "admin_.......php" files.
__________________
Cheers

Dan


Buzzdup.com
*Your* Local News

Pligg iPhone/iPod Touch RSS Reader For Pligg - FREE
Reply With Quote
The Following User Says Thank You to nzbullet For This Useful Post:
Reply

Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
Voting method 2, displaying stories in order of rating radaro Pligg Mods 4 02-03-2008 12:44 AM
v9.5: Comments to discarded stories tbones Bug Report 6 01-28-2008 05:49 AM
Clicking on a tag reveals stories that have been discarded kbeeveer46 Bug Report 0 08-06-2006 11:36 PM
User vote count shouldn't include discarded stories gragland Bug Report 0 07-26-2006 07:14 PM


Search Engine Friendly URLs by vBSEO 3.2.0