1

I have a user role that is meant for pseudo-anonymous usage and each account of this role-type will be shared in a pool of users. Whenever a user of this role logs out, I'd like to delete all their associated content to prepare for the next possible user using this account. This sounds like a job for hook_logout, but it also seems like there should be a module for this already, right? I searched but maybe I'm not using the right keywords.

2
  • Have you checked your options in rules ?
    – RajeevK
    Oct 12 '13 at 6:37
  • I'm not sure that there would be a module for such a very specific purpuse. Oct 12 '13 at 8:31
2

I'd suggest to try out Rules module for this, you've got an event: "User has logout", grab the entities from that user, loop them and delete them.

Here's a exported rule that would do it (change the number of entities to suit your needs)

{ "rules_test_logout" : {
"LABEL" : "test_logout",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_logout" ],
"DO" : [
  { "entity_query" : {
      "USING" : { "type" : "node", "property" : "author", "value" : [ "account" ] },
      "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
    }
  },
  { "LOOP" : {
      "USING" : { "list" : [ "entity-fetched" ] },
      "ITEM" : { "list_item" : "Current list item" },
      "DO" : [ { "entity_delete" : { "data" : [ "list-item" ] } } ]
    }
  }
]

} }

1
  • Rules module is a good idea, though I'm not sure it's necessarily the right fit as I'd like to try to keep as much of my business logic in code. But as far as you know there's no discovery service for removing all content that where author_id == user id, regardless of content type? Oct 13 '13 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.