Created
May 11, 2012 17:52
-
-
Save pdxmph/2661340 to your computer and use it in GitHub Desktop.
Cull FeedAPI feed nodes of inactive contributors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// some counters | |
$c = 0; | |
$kept_feeds = 0; | |
$discarded_feeds = 0; | |
$too_new_feeds = 0; | |
// maximum inactive period in days | |
$last_published_cutoff = 180; | |
// minimum age of a feed before we'll consider it for deletion | |
$minimum_age = 60; | |
$feeds = db_query('SELECT nid,uid,created,title FROM {node} WHERE (type = "feed")'); | |
while($row = db_fetch_array($feeds)) { | |
++$c; | |
$created = $row['created']; | |
$feed_title = $row['title']; | |
if (strtotime("-$minimum_age day") <= $created) { | |
++$too_new_feeds; | |
continue; | |
} | |
$feed_nid = $row['nid']; | |
$pub_status = user_last_published($row['uid']); | |
$last_pub = $pub_status ? date("F j, Y",$pub_status) : "never published"; | |
if (strtotime("-$last_published_cutoff day") <= $pub_status) { | |
++$kept_feeds; | |
} else { | |
echo "dropping $feed_title. Last pub: $last_pub\n"; | |
node_delete($feed_nid); | |
++$discarded_feeds; | |
} | |
} | |
echo " | |
For authors published in last $last_published_cutoff days: | |
Total Feeds: $c | |
Discarded Feeds: $discarded_feeds | |
Kept Feeds: $kept_feeds | |
$too_new_feeds feeds were created in the last $minimum_age days and will not be deleted. | |
"; | |
function user_last_published($uid) { | |
$last_post = db_result(db_query("SELECT node.created AS node_created FROM node node WHERE (node.status <> 0) AND (node.type in ('post')) AND (uid = %d ) ORDER BY node_created DESC LIMIT 1", $uid)); | |
if ($last_post) { | |
return $last_post; | |
} else { | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment