1

I need to create an additional node for each authenticated active user on a Drupal 7 site.

The nodes will be populated with default content from taxonomies, and also with some field content based on content owned by each user.

Something like :

  1. create node with author=user1
  2. field 1= populated from a taxonomy
  3. field 2= Count of number of nodes of content type A authored by user1 that are published
  4. field 3= current date

And then loop through all active users creating a similar node for each one.

What's the best way to handle this? Ideally I'd like to do it in a way so that the batch node creation job could be triggered by a scheduled Rule in future.

The idea is to provide a report showing a snapshot of the account status at a fixed time.

5
  • 1
    Have you considered alternatives such as adding fields to the accounts? What made you decide to create new nodes? When you run the scheduled rule do you want it to create a new node each time or just update existing ones where applicable?
    – Darvanen
    Jan 12, 2015 at 4:08
  • I'll need to do this repeatedly, and I need to store the state of the account at a fixed date, if that makes sense. So I don't just want to say 'user 1 has 3 nodes of content type X' but 'on 1st feb, user 1 had 3 nodes. On 1st Sept, she had 5 nodes'. So I think really I do want to store each record as a node, rather than a field on the user profile?
    – Victoria
    Jan 12, 2015 at 14:17
  • Sorry, should have added, I want the rule to create new nodes each time it is run, rather than updating existing nodes. Not sure if that was clear from my previous comment!
    – Victoria
    Jan 12, 2015 at 14:30
  • You're right, account fields would not be the best solution here.
    – Darvanen
    Jan 12, 2015 at 22:34
  • Oh, and comments can be removed, so it's best to update your question with the extra information.
    – Darvanen
    Jan 12, 2015 at 22:49

1 Answer 1

1

Shouldn't be too difficult if you're ok with writing a custom module, I can't think of any other way to iterate through your user base.

  1. Create the node type for storing your statistics with:

  2. Write a custom module that does the following things:

See how you go and of course ask more, detailed questions about each step showing what you have tried if you really can't work it out through the documentation and existing questions/answers available here and elsewhere.

1
  • Thank you : I've not written a whole custom module before, but I'm giving it a go. It's helpful to have a confirmation that I'm not missing something obvious that would let me do that in a standard module.
    – Victoria
    Jan 14, 2015 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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