Is this possible?: After creating a node -> no active comments for 30 days -> node gets unpublished?

danthalian - November 25, 2007 - 23:35

Hi there,

Can anyone figure a way to solve this issue?:

Create a node and it gets published.
Issue: If there hasnt been a comment for 30 days, node becomes unpublished

Why do I need that?:
If I create, lets say a sales note trying to sell a bike (a node which is published to the public). People can use comments to reply on my bike-ad to say if they want to buy it or not.
And after 30 days of inactivity (no one commenting on the bike-ad) it would become unpublished (so the public would not see it anymore).

I could then have 2 views, one showing my own published bike-ads and my unpublished ones.

That way i would make sure that my published notes (the inactive ones) would be removed from the sight of the public automatically.

Is there any way to achieve the above??

PLEASE HELP me on the right way, it would mean alot!

Thanks in advance,
Camron

Have you looked the

canen - November 26, 2007 - 00:44

Have you looked the workflow-ng module?

Yeah - problem is with

danthalian - November 26, 2007 - 00:45

Yeah - problem is with workflow you need a link to be clicked for the schedule/event to occur..

your own module + cron

scrypter - November 26, 2007 - 02:37

and some sql select(s) where count is zero for checking comment date > 30 days ago and comment.nid = node.nid etc then set node.status to unpublished.

www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy

Thanks for trying to help

danthalian - November 26, 2007 - 11:34

Thanks for trying to help me!

I know how cron works, but im abit of a newbie in these matters.. could you please explain it abit more detailed? Ill see if I understand how to do it myself, just need abit more detail:)

Thanks in advance!

cron hook

scrypter - November 26, 2007 - 21:23

OK, you will need to read in the handbooks about creating a module. I assume you know php and sql.
In your new module (inactivenode) near the beginning put this:

<?php
define
(SECSINDAY, 60*60*24);
?>

Then you can put a hook like this:
<?php
/**
*  cron hook
*  changes node status to unpublished if node has no comments in the last 30 days

*/

function inactivenode_cron() {
 
$delta = time() - 30 * SECSINDAY;
 
$sql = "SELECT count(c.cid) AS comm_count, n.nid FROM {comments} c JOIN {node} n WHERE c.nid = n.nid AND c.timestamp > %d GROUP BY c.nid";
 
$result = db_query($sql, $delta);
  while (
$comment = db_fetch_object($result)) {
    if (
$comment->comm_count == 0) {
     
db_query("UPDATE {node} SET status = %d WHERE nid = %d", 0$comment->nid);
    }
  }
}
?>

This is UNTESTED, just off the top of my head so tread carefully. It may not be the most efficient, but it might get you started. I am assuming unpublished status is 0, so please check.

www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy

 
 

Drupal is a registered trademark of Dries Buytaert.