0

I have a large number of nodes created with a large subset for a specific term that I would like to add one file to all of these nodes at one time.

For a single case, I have a CCK field for uploading a file. If I had to do this one by one for every node, it would take a long time.

At this time, I am planning on writing code to do this work using code to query the db for all nodes for the term, and loop over each of those attaching the file to the CCK field of each node.

There's one file on the server, I want to attach it to many nodes as a bulk operation, rather than attach the file to each node, one by one. This seems like a problem that would have been run into before. Is there any suggestions on modules that might already do what I want?

2 Answers 2

1

If you want to do it a little easier, Views Bulk Operations might be helpful. But otherwise, adding the file to one node, then adding a reference to the file from all the other nodes is the best solution (this way the file isn't independently added to hundreds of nodes, creating hundreds of duplicate files).

You should also check out how FileField Sources adds references to existing files for inspiration.

1
  • Yes, you definitely need VBO. If you don't want to write your own code, drupal.org/node/1057158 should make this possible out of the box. I already have it half-working and hoping to have it in VBO 7.x-3.0-RC1 before DrupalCon London. Aug 3, 2011 at 23:30
0

If I should do that without thinking to a better solution, I would create a batch in a module and add the file to the node. Creating batches is really simple, you'll find tutorial.

Another solution, would be, if you have to copy the SAME file to every node, is to make a node reference to the node containing the file.

This way, you can easily create a batch and set the nid to the right field

$node->field_file_reference[0]['nid'] = THE_NID_OF_THE_NODE_CONTAINING_THE_FILE;

I hope this helps...

Your Answer

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

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