You are here

public function ServiceAuditFilesMergeFileReferences::auditfilesMergeFileReferencesBatchMergeCreateBatch in Audit Files 8.2

Same name and namespace in other branches
  1. 8.3 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 197

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\\AuditFilesBatchProcess::auditfilesMergeFileReferencesBatchFinishBatch';
  $batch['progress_message'] = $this->stringTranslation
    ->translate('Completed @current of @total operations.');
  $batch['title'] = $this->stringTranslation
    ->translate('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::auditfilesMergeFileReferencesBatchMergeProcessBatch',
        [
          $file_being_kept,
          $file_id,
        ],
      ];
    }
  }
  $batch['operations'] = $operations;
  return $batch;
}