Discard upcoming stories that are not published after a certain amount of time

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-14-2007, 01:01 AM
Pligg Donor
Pligg Version: 9.8.2
Pligg Template: custom
 
Join Date: Sep 2007
Location: King of Prussia, PA
Posts: 62
Here is a way to automatically 'retire' (discard) upcoming stories that have not been published after x number of days.
The code is written to retire the upcoming stories older than 7 days.

Add the following code in your upcoming.php file right after "check_actions('index_top');"

Quote:
// Discard upcoming stories after 7 days if they are not published. Change the 7 below if you would like to specify a different number of days
$tsdt = date('Ymd000000', strtotime("-7 day"));
$sql = "UPDATE ".table_links." SET link_status='discard' WHERE link_status='queued' AND link_date <= $tsdt";
$db->query($sql);
In order to reduce the load on your server, you could create a separate file with all the include statements of the upcoming.php and add the code above and run a cron job once a day to invoke this file.
Reply With Quote
  #2 (permalink)  
Old 12-14-2007, 07:58 PM
TobiParrot's Avatar
Casual Pligger
Pligg Version: Pligg beta 9.8.2
Pligg Template: Default
 
Join Date: Dec 2007
Location: UK
Posts: 41
Works a treat
Reply With Quote
  #3 (permalink)  
Old 12-15-2007, 02:51 AM
Constant Pligger
Pligg Version: Pligg 9.9
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Ottawa, Ontario
Posts: 147
Thanks a lot for this mod. I went all the way and made a button in my admin panel that uses this, here's how if someone is interested, as it goes well with this modification also: http://forums.pligg.com/pligg-mods/1...d-stories.html

EDIT # 1: I have edited this post to reflect the changes Ablaye made to this mod just below. If it's bugged, please let me know.

STEP 1:

Open admin_links_center.tpl found in your templates admin_templates folder.

Find:
Code:
<a href="javascript:uncheck_all()">Uncheck All</a>
Add after it:
Code:
<br><a href="admin_links.php" onclick="javascript:window.open('admin_discard_upcoming.php', 'resultwindow', 'width=300, height=200')">Discard old Upcoming stories</a>
STEP 2:

Create a new file called admin_discard_upcoming.php in your root folder and add the following:

Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'ts.php');
include(mnminclude.'link.php');
include(mnminclude.'tags.php');
include(mnminclude.'search.php');
include(mnminclude.'smartyvariables.php');

// require user to log in
force_authentication();

// restrict access to god only
$canIhaveAccess = 0;
$canIhaveAccess = $canIhaveAccess + checklevel('god');

// module system hook
check_actions('upcoming_top');
check_actions('index_top');

// Discard upcoming stories after 7 days if they are not published. Change the 7 below if you would like to specify a different number of days
$tsdt = date('Ymd000000', strtotime("-7 day"));
$retire_cond = " WHERE link_status='queued' AND link_date <= $tsdt";

$sql1 = "SELECT count(*) FROM ".table_links.$retire_cond;
$retire_count = $db->get_var($sql1);

if ($retire_count > 0) {
	$sql2 = "SELECT total FROM ".table_totals." WHERE name='queued'";
	$old_count = $db->get_var($sql2);
	$update_count = $old_count - $retire_count;

	$sql3 = "UPDATE ".table_totals." SET total='".$update_count."' WHERE name='queued'";
	$db->query($sql3);

	$sql4 = "UPDATE ".table_links." SET link_status='discard'".$retire_cond;
	$db->query($sql4);
}
<p><center>All Old Upcoming Stories Have Been Discarded. <br>You Can Close This Window Now.</center></p>

That's it. Every time you go to your admin panel, under news management, you will find a new link that discards all old stories.

Last edited by Unknown; 01-21-2008 at 05:42 PM. Reason: See Edit # 1
Reply With Quote
  #4 (permalink)  
Old 12-18-2007, 12:54 AM
New Pligger
Pligg Version: 9.8
Pligg Template: yget
 
Join Date: Nov 2007
Posts: 25
just what i needed
Reply With Quote
  #5 (permalink)  
Old 01-21-2008, 02:10 AM
Pligg Donor
Pligg Version: 9.8.2
Pligg Template: custom
 
Join Date: Sep 2007
Location: King of Prussia, PA
Posts: 62
Just wanted to let you guys know the code that I posted above is incorrect.
I failed to take into account that the number of queued stories will NOT get properly updated in the pligg_totals table.

The correct code should be:
Code:
// Discard upcoming stories after 7 days if they are not published. Change the 7 below if you would like to specify a different number of days
$tsdt = date('Ymd000000', strtotime("-7 day"));
$retire_cond = " WHERE link_status='queued' AND link_date <= $tsdt";

$sql1 = "SELECT count(*) FROM ".table_links.$retire_cond;
$retire_count = $db->get_var($sql1);

if ($retire_count > 0) {
	$sql2 = "SELECT total FROM ".table_totals." WHERE name='queued'";
	$old_count = $db->get_var($sql2);
	$update_count = $old_count - $retire_count;

	$sql3 = "UPDATE ".table_totals." SET total='".$update_count."' WHERE name='queued'";
	$db->query($sql3);

	$sql4 = "UPDATE ".table_links." SET link_status='discard'".$retire_cond;
	$db->query($sql4);
}
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra fields not appearing johnfromberkeley Questions and Comments 5 10-21-2008 10:12 AM
Discard old upcoming stories ablaye Questions and Comments 2 12-14-2007 12:51 AM
Can I change the amount of time in top stories? kh1 Questions and Comments 5 08-27-2007 02:37 AM
[MOD] Showing # of Upcoming Stories in v9.6 abcdefgary Questions and Comments 9 08-01-2007 05: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