You are here

function imagecache_external_batch_flush in Imagecache External 8

The batch callback.

1 call to imagecache_external_batch_flush()
imagecache_external_flush_cache in ./imagecache_external.module
Helper function to flush caches.

File

./imagecache_external.module, line 365
Allows the usage of Image Styles on external images.

Code

function imagecache_external_batch_flush($path) {
  $files = scandir(imagecache_external_get_directory_path());
  $files = array_diff($files, [
    '..',
    '.',
  ]);
  if (!empty($files)) {
    foreach ($files as &$value) {
      $value = $path . '/' . $value;
    }
    unset($value);
    $config = imagecache_external_config();
    $chunks = array_chunk($files, $config
      ->get('imagecache_external_batch_flush_limit'), TRUE);
    $count_chunks = count($chunks);
    $i = '';
    foreach ($chunks as $chunk) {
      $i++;
      $operations[] = [
        'imagecache_external_batch_flush_process',
        [
          $chunk,
          'details' => t('(Deleting file batch @chunk of @count)', [
            '@chunk ' => $i,
            '@count' => $count_chunks,
          ]),
        ],
      ];
    }
    $batch = [
      'operations' => $operations,
      'finished' => 'imagecache_external_batch_flush_finished',
      'title' => t('Deleting Imagecache External files...'),
      'init_message' => t('Bulk delete is starting...'),
      'error_message' => t('Imagecache external batch flush has encountered an error.'),
    ];
    batch_set($batch);
    return TRUE;
  }
  elseif (empty($files)) {
    $directory = imagecache_external_get_directory_path();
    \Drupal::service('file_system')
      ->deleteRecursive($directory);
    return TRUE;
  }
  else {
    return FALSE;
  }
}