How to use cron to delete nodes of a content type that does not allow deletion by anonymous users

by penname   Last Updated November 22, 2017 13:07 PM

The background for this question is here: Delete nodes using Rules and VBO

Summary: a VBO View selects various nodes of a particular content type. A Rules Action Set is instructed to load this VBO View, loop through the entity objects, and delete them. A Rule runs/is triggered on cron and has this Action Set for its action. So, when cron runs the selected nodes should be deleted.

However, the nodes are not deleted, because cron runs as the Anonymous User (0), and the content type is configured such that anonymous users are not allowed to delete nodes of this content type.

How can this be solved so that the nodes are deleted on cron?

Giving anonymous users permission to delete nodes of this content type is not a good solution on this site.

Presumably, cron runs as Anonymous User (0) for security reasons. Any acceptable solution should not undermine the site's security.

A programmatic solution (e.g. code in a custom module) is certainly acceptable if a "code-less" solution in Rules is not possible.

Thanks



Answers 1


My memory is a little hazy, but I'm pretty sure I did something similar a few years ago.

  • Give anonymous users permission to delete the node.
  • Use hook_form_alter() to remove the "delete" button from the node form.

This approach is slightly dangerous in that the user can modify the URL to delete the node by adding /delete on the end, but if your users aren't particularly sophisticated hiding the delete button may be enough.

Patrick Kenny
Patrick Kenny
November 22, 2017 13:06 PM

Related Questions


Bulk delete field collection items

Updated April 29, 2015 21:03 PM

Clone nodes and change fields with Rules and VBO

Updated May 20, 2015 20:03 PM

Copy filefield image to different filefield field

Updated April 21, 2015 21:03 PM

How does Rules integrate with VBO and vice versa?

Updated August 24, 2016 08:04 AM