function node_mass_update

Same name in other branches
  1. 9 core/modules/node/node.admin.inc \node_mass_update()
  2. 8.9.x core/modules/node/node.admin.inc \node_mass_update()
  3. 10 core/modules/node/node.admin.inc \node_mass_update()
  4. 11.x core/modules/node/node.admin.inc \node_mass_update()

Make mass update of nodes, changing all nodes in the $nodes array to update them with the field values in $updates.

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.

Parameters

array $nodes: Array of node nids to update.

array $updates: Array of key/value pairs with node field names and the value to update that field to.

2 calls to node_mass_update()
hook_user_cancel in modules/user/user.api.php
Act on user account cancellations.
node_user_cancel in modules/node/node.module
Implements hook_user_cancel().
2 string references to 'node_mass_update'
hook_node_operations in modules/node/node.api.php
Add mass node operations.
node_node_operations in modules/node/node.admin.inc
Implements hook_node_operations().

File

modules/node/node.admin.inc, line 274

Code

function node_mass_update($nodes, $updates) {
    // 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,
                    ),
                ),
            ),
            '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 {
        foreach ($nodes as $nid) {
            _node_mass_update_helper($nid, $updates);
        }
        drupal_set_message(t('The update has been performed.'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.