You are here

function ServiceAuditFilesMergeFileReferences::_auditfiles_merge_file_references_batch_merge_create_batch in Audit Files 8

Creates the batch for merging files.

Parameters

int $file_being_kept: The file ID of the file to merge the others into.

array $files_being_merged: The list of file IDs to be processed.

Return value

array The definition of the batch.

File

src/ServiceAuditFilesMergeFileReferences.php, line 129
providing the service that used in 'managed not used' functionality.

Class

ServiceAuditFilesMergeFileReferences

Namespace

Drupal\auditfiles

Code

function _auditfiles_merge_file_references_batch_merge_create_batch($file_being_kept, array $files_being_merged) {
  $batch['error_message'] = t('One or more errors were encountered processing the files.');
  $batch['finished'] = '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_merge_file_references_batch_finish_batch';
  $batch['progress_message'] = t('Completed @current of @total operations.');
  $batch['title'] = t('Merging files');
  $operations = $file_ids = [];
  foreach ($files_being_merged as $file_id => $file_info) {
    if ($file_id != 0) {
      $file_ids[] = $file_id;
    }
  }
  foreach ($file_ids as $file_id) {
    if ($file_id != $file_being_kept) {
      $operations[] = [
        '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_merge_file_references_batch_merge_process_batch',
        [
          $file_being_kept,
          $file_id,
        ],
      ];
    }
  }
  $batch['operations'] = $operations;
  return $batch;
}