You are here

class AuditFilesUsedNotReferencedBatchProcess in Audit Files 8.3

Process batch files.

Hierarchy

Expanded class hierarchy of AuditFilesUsedNotReferencedBatchProcess

File

src/Batch/AuditFilesUsedNotReferencedBatchProcess.php, line 12

Namespace

Drupal\auditfiles\Batch
View source
class AuditFilesUsedNotReferencedBatchProcess {

  /**
   * The File entity ID to delete.
   *
   * @var int
   */
  protected $fileId;

  /**
   * ManagedNotUsed service.
   *
   * @var \Drupal\auditfiles\ServiceAuditFilesusedNotReferenced
   */
  protected $usedNotReferenced;

  /**
   * Class constructor.
   *
   * @param \Drupal\auditfiles\ServiceAuditFilesUsedNotReferenced $used_not_referenced
   *   Injected ServiceAuditFilesUsedNotManaged service.
   * @param int $file_id
   *   File entity ID to delete.
   */
  public function __construct(ServiceAuditFilesUsedNotReferenced $used_not_referenced, $file_id) {
    $this->usedNotReferenced = $used_not_referenced;
    $this->fileId = $file_id;
  }

  /**
   * The batch process for process the file ID(s).
   *
   * @param int $file_id
   *   File entity ID to delete.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesUsedNotReferencedBatchDeleteProcessBatch($file_id, array &$context) {
    $usedNotReferenced = \Drupal::service('auditfiles.used_not_referenced');
    $worker = new static($usedNotReferenced, $file_id);
    $worker
      ->dispatch($context);
  }

  /**
   * Processes file removal from file_usage that are not referenced in content.
   *
   * @param array $context
   *   Batch context.
   */
  protected function dispatch(array &$context) {
    $this->usedNotReferenced
      ->auditfilesUsedNotReferencedBatchDeleteProcessFile($this->fileId);
    $context['results'][] = Html::escape($this->fileId);
    $context['message'] = new TranslatableMarkup('Processed file ID %file_id.', [
      '%file_id' => $this->fileId,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuditFilesUsedNotReferencedBatchProcess::$fileId protected property The File entity ID to delete.
AuditFilesUsedNotReferencedBatchProcess::$usedNotReferenced protected property ManagedNotUsed service.
AuditFilesUsedNotReferencedBatchProcess::auditfilesUsedNotReferencedBatchDeleteProcessBatch public static function The batch process for process the file ID(s).
AuditFilesUsedNotReferencedBatchProcess::dispatch protected function Processes file removal from file_usage that are not referenced in content.
AuditFilesUsedNotReferencedBatchProcess::__construct public function Class constructor.