You are here

public function ServiceAuditFilesMergeFileReferences::auditfilesMergeFileReferencesBatchMergeCreateBatch in Audit Files 8.3

Same name and namespace in other branches
  1. 8.2 src/ServiceAuditFilesMergeFileReferences.php \Drupal\auditfiles\ServiceAuditFilesMergeFileReferences::auditfilesMergeFileReferencesBatchMergeCreateBatch()

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 195

Class

ServiceAuditFilesMergeFileReferences
Define all methods that used in merge file references functionality.

Namespace

Drupal\auditfiles

Code

public function auditfilesMergeFileReferencesBatchMergeCreateBatch($file_being_kept, array $files_being_merged) {
  $batch['error_message'] = $this->stringTranslation
    ->translate('One or more errors were encountered processing the files.');
  $batch['finished'] = '\\Drupal\\auditfiles\\Batch\\AuditFilesBatchProcess::finishBatch';
  $batch['progress_message'] = $this->stringTranslation
    ->translate('Completed @current of @total operations.');
  $batch['title'] = $this->stringTranslation
    ->translate('Merging files');
  $operations = [];
  foreach ($files_being_merged as $file_id => $file_info) {
    if ($file_id != 0 && $file_id != $file_being_kept) {
      $operations[] = [
        '\\Drupal\\auditfiles\\Batch\\AuditFilesMergeFileReferencesBatchProcess::auditfilesMergeFileReferencesBatchMergeProcessBatch',
        [
          $file_being_kept,
          $file_id,
        ],
      ];
    }
  }
  $batch['operations'] = $operations;
  return $batch;
}