function _filefield_paths_batch_update_process in File (Field) Paths 8
Same name and namespace in other branches
- 6 filefield_paths.module \_filefield_paths_batch_update_process()
 - 7 filefield_paths.module \_filefield_paths_batch_update_process()
 
Batch callback for File (Field) Paths retroactive updates.
Parameters
array $objects: TODO.
FieldConfig $field_config: TODO.
array $context: TODO.
1 string reference to '_filefield_paths_batch_update_process'
- filefield_paths_batch_update in ./
filefield_paths.module  - Set batch process to update File (Field) Paths.
 
File
- ./
filefield_paths.module, line 294  - Contains core functions for the File (Field) Paths module.
 
Code
function _filefield_paths_batch_update_process($objects, FieldConfig $field_config, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($objects);
    $context['sandbox']['objects'] = $objects;
  }
  /** @var Drupal\Core\Entity\ContentEntityStorageBase $entity_storage */
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage($field_config
    ->getTargetEntityTypeId());
  // 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']);
    $entity = $entity_storage
      ->load($oid);
    // Enable active updating if it isn't already enabled.
    $active_updating = $field_config
      ->getThirdPartySetting('filefield_paths', 'active_updating');
    if (!$active_updating) {
      $field_config
        ->setThirdPartySetting('filefield_paths', 'active_updating', TRUE);
      $field_config
        ->save();
    }
    $entity->original = $entity;
    filefield_paths_entity_update($entity);
    // Restore active updating to it's previous state if necessary.
    if (!$active_updating) {
      $field_config
        ->setThirdPartySetting('filefield_paths', 'active_updating', $active_updating);
      $field_config
        ->save();
    }
    // 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'];
  }
}