You are here

function _filefield_paths_batch_update_process in File (Field) Paths 6

Same name and namespace in other branches
  1. 8 filefield_paths.module \_filefield_paths_batch_update_process()
  2. 7 filefield_paths.module \_filefield_paths_batch_update_process()
1 string reference to '_filefield_paths_batch_update_process'
filefield_paths_batch_update in ./filefield_paths.module
Set batch process to update FileField Paths.

File

./filefield_paths.module, line 308
Contains core functions for the FileField Paths module.

Code

function _filefield_paths_batch_update_process($objects, $module, $field, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($objects);
    $context['sandbox']['objects'] = $objects;
  }

  // Process nodes by groups of 5.
  $count = min(5, count($context['sandbox']['objects']));
  for ($i = 1; $i <= $count; $i++) {

    // For each oid, load the object, update the files and save it.
    $oid = array_shift($context['sandbox']['objects']);

    // Invoke hook_filefield_paths_update().
    if (function_exists($function = "{$module}_filefield_paths_update")) {
      $function($oid, $field);
    }

    // Update our progress information.
    $context['sandbox']['progress']++;
  }

  // Inform the batch engine that we are not finished,
  // and provide an estimation of the completion level we reached.
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}