Updates all nodes in the passed-in array with the passed-in field values.
IMPORTANT NOTE: This function is intended to work when called from a form submission handler. Calling it outside of the form submission process may not work correctly.
array $nodes: Array of node nids or nodes to update.
array $updates: Array of key/value pairs with node field names and the value to update that field to.
string $langcode: (optional) The language updates should be applied to. If none is specified all available languages are processed.
bool $load: (optional) TRUE if $nodes contains an array of node IDs to be loaded, FALSE if it contains fully loaded nodes. Defaults to FALSE.
function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load = FALSE) {
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if (count($nodes) > 10) {
$batch = array(
'operations' => array(
array(
'_node_mass_update_batch_process',
array(
$nodes,
$updates,
$langcode,
$load,
),
),
),
'finished' => '_node_mass_update_batch_finished',
'title' => t('Processing'),
// We use a single multi-pass operation, so the default
// 'Remaining x of y operations' message will be confusing here.
'progress_message' => '',
'error_message' => t('The update has encountered an error.'),
// The operations do not live in the .module file, so we need to
// tell the batch engine which file to load before calling them.
'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
);
batch_set($batch);
}
else {
if ($load) {
$nodes = entity_load_multiple('node', $nodes);
}
foreach ($nodes as $node) {
_node_mass_update_helper($node, $updates, $langcode);
}
drupal_set_message(t('The update has been performed.'));
}
}