You are here

function file_admin_mass_update in File admin 7

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

IMPORTANT NOTE: This function is intended to work when called from a form submit handler. Calling it outside of the form submission process may not work correctly.

Parameters

array $files: Array of file fids to update.

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

2 calls to file_admin_mass_update()
file_admin_publish_action in ./file_admin.module
Sets the published field of a file to 1 (published).
file_admin_unpublish_action in ./file_admin.module
Sets the published field of a file to 0 (unpublished).
1 string reference to 'file_admin_mass_update'
file_admin_file_operations in ./file_admin.module
Implement hook_file_operations().

File

./file_admin.module, line 459
Enhances file administration by adding published, promote, and sticky fields.

Code

function file_admin_mass_update($files, $updates) {

  // We use batch processing to prevent timeout when updating a large number
  // of files.
  if (count($files) > 10) {
    $batch = array(
      'operations' => array(
        array(
          '_file_mass_update_batch_process',
          array(
            $files,
            $updates,
          ),
        ),
      ),
      'finished' => '_file_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', 'file_admin') . '/file.admin.inc',
    );
    batch_set($batch);
  }
  else {
    foreach ($files as $fid) {
      _file_mass_update_helper($fid, $updates);
    }
    drupal_set_message(t('The update has been performed.'));
  }
}