Im using Computed Fields to get a node's menu weight as a CCK field available for View's sorting. Im using the method from post 28 here:

The only problem is that if the menu changes then I need to update all the node's CCK field. One solution is to manually edit and save each node, but this is impractical for a large site. So how can I update my computed field for all nodes of a certain content type?

Ive done some reading and it seems this can be done with php code, views bulk operation or rules. Ive no idea which method to follow. Im making this site for a client so either the updating needs to be automatic or their could be a 'button' they click.

Assuming I used rules to edit and save all nodes of a certain content type whenever a new node is created or a menu is edited. Would that be OK? How many nodes can you edit in this way without overloading the server?


jdln’s picture

Status:Active» Fixed

Having this on a page and viewing the page works:

print "start ";
$result = db_query("SELECT nid FROM {node}");
$nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
"end, the menu has been updated ";

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

1kenthomas’s picture

Version:6.x-1.x-dev» 7.x-1.x-dev
Status:Closed (fixed)» Active

The node_save & other methods do not seem to work with entities on D7.

Summary: I'm using a computed field with Commerce Orders. All methods that I've tried (entity_save, commerce_order_save, field_*) do not result in update of the computed field.

commerce_order_save does add the computed field, but it displays as black even if I set & save the field manually.

Editing & saving the entity manually (via GUI) does work.


NOTE: this issue has been duplicated and several parallel issues seem to exist; // limiting 7.x report to here.

1kenthomas’s picture

Title:Update computed fields for all nodes of a content type? » Update computed fields for all entities of a content/bundle type?

Changing to D7 terminology.

1kenthomas’s picture

(&& further NOTE: computed fields tools does not work in this case ... only works on nodes & users).

liquidcms’s picture

i think this is the issue i have as well: computed fields are not updated during node_save

or alternatively: how do i programmatically update a node and have the computed fields recalculated?

mstrelan’s picture

I'm using this to update all field collection items for the field "field_media_collection".

= new EntityFieldQuery();
$query->entityCondition('entity_type', 'field_collection_item', '=')
entityCondition('bundle', 'field_media_collection', '=');
$result = $query->execute();
$fcs = $result['field_collection_item'];
foreach (
$fcs as $fc) {
$fc = field_collection_item_load($fc->item_id);

For most entity types you could replace this:

  $fc = field_collection_item_load($fc->item_id);

with something like this

  $entity_type = 'my_entity_type';
  entity_save($entity_type, $entity);

but field collections are a little trickier.

kharbat’s picture

Using views bulk operations module, selecting all nodes and applying "Save content" action worked for me.

ssoulless’s picture

Issue summary:View changes
Status:Active» Closed (fixed)

You can use a module that does what you need

King Regards

gusantor’s picture

hello, this is not fixed

using Drupal 7.37, computed field 7.x-1.0 , can't programmatically update a computed field in a node

field won't update when using

= node_load($nodeId);

the field is updated when I save the node through UI, 'Save' button at content type Form

I need to do it programmatically, not through UI or views bulk operations

please any help on getting this is very welcome