how to delete nodes after the "to date" end in drupal?

623 views Asked by At

What I would like to do is remove (delete) a node after the "to date" which is selected manually at the creation of the node. I already tested solutions like node expire, schedule, and others, but I'm not able to simply use my already existing and variable date in the node.

It is an old drupal 6, and I'm using calendar which seems to have this option, but I'm not able to find why or how this stopped working. I can't even find the configuration page.

1

There are 1 answers

2
Anthony Leach On

Would you be willing to create a custom module for this? If so, I can supply a few code examples of some solutions to this. It would generally be a single cron hook which would remove or un-publish nodes that are past the 'to date'.

In your given link, take a look at this comment: https://www.drupal.org/node/28142#comment-48472 This gives an 'ok' code example that can delete the node when it is older that 30 days. All that you would need to do is change the db_query.

If you're using CCK to store the date field. Ensure that this is on multiple content types first, this is to ensure the CCK field is split out into a separate table right now, rather than this do this in the future and this fail.

What you'll then be looking at doing is a query like:

$query = "SELECT nid, uid FROM {node} n LEFT JOIN {content_field_date} d ON n.nid = d.nid WHERE d.field_date_value < '%s'"; Where 'content_field_date' is the name of the table the date is stored {content_{machine_name}} Where 'field_date_value' is the field the date in this table that the value is stored {{machine_name}_{field_type}}

Depending on how the content is stored within 'field_date_value' you may need to convert this to a Unix time stamp using the MySQL function: UNIX_TIMESTAMP, example UNIX_TIMESTAMP(d.field_date_value).