You are here

public static function GenerateBatch::process in File Hash 8

Batch process callback.

File

src/Batch/GenerateBatch.php, line 42

Class

GenerateBatch
Generates file hashes in bulk.

Namespace

Drupal\filehash\Batch

Code

public static function process(&$context) {
  if (!isset($context['results']['processed'])) {
    $context['results']['processed'] = 0;
    $context['results']['updated'] = 0;
    $context['sandbox']['count'] = self::count();
  }
  $files = \Drupal::database()
    ->select('file_managed')
    ->fields('file_managed', [
    'fid',
  ])
    ->range($context['results']['processed'], 1)
    ->execute();
  foreach ($files as $file) {

    // Fully load file object.
    $file = File::load($file->fid);
    $variables = [
      '%url' => $file
        ->getFileUri(),
    ];
    $context['message'] = t('Generated file hash for %url.', $variables);
  }
  $context['results']['processed']++;
  $context['finished'] = $context['sandbox']['count'] ? $context['results']['processed'] / $context['sandbox']['count'] : 1;
}