You are here

class AuditFilesReferencedNotUsedBatchProcess in Audit Files 4.x

Same name and namespace in other branches
  1. 8.3 src/Batch/AuditFilesReferencedNotUsedBatchProcess.php \Drupal\auditfiles\Batch\AuditFilesReferencedNotUsedBatchProcess

Process batch files.

Hierarchy

Expanded class hierarchy of AuditFilesReferencedNotUsedBatchProcess

File

src/Batch/AuditFilesReferencedNotUsedBatchProcess.php, line 12

Namespace

Drupal\auditfiles\Batch
View source
class AuditFilesReferencedNotUsedBatchProcess {

  /**
   * The entity reference ID to delete.
   *
   * @var int
   */
  protected $referenceId;

  /**
   * ReferencedNotUsed service.
   *
   * @var \Drupal\auditfiles\ServiceAuditFilesReferencedNotUsed
   */
  protected $referencedNotUsed;

  /**
   * Class constructor.
   *
   * @param \Drupal\auditfiles\ServiceAuditFilesReferencedNotUsed $referenced_not_used
   *   Injected ServiceAuditFilesUsedNotManaged service.
   * @param int $reference_id
   *   File entity ID to delete.
   */
  public function __construct(ServiceAuditFilesReferencedNotUsed $referenced_not_used, $reference_id) {
    $this->referencedNotUsed = $referenced_not_used;
    $this->referenceId = $reference_id;
  }

  /**
   * Batch Process for Adding a file reference.
   *
   * @param int $reference_id
   *   File entity reference ID to add.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesReferencedNotUsedBatchAddProcessBatch($reference_id, array &$context) {
    $referencedNotUsed = \Drupal::service('auditfiles.referenced_not_used');
    $worker = new static($referencedNotUsed, $reference_id);
    $worker
      ->addDispatch($context);
  }

  /**
   * Processes entity reference additions from content entities to file_managed.
   *
   * @param array $context
   *   Batch context.
   */
  protected function addDispatch(array &$context) {
    $this->referencedNotUsed
      ->auditfilesReferencedNotUsedBatchAddProcessFile($this->reference_id);
    $context['results'][] = Html::escape($this->reference_id);
    $context['message'] = new TranslatableMarkup('Processed file ID %file_id.', [
      '%file_id' => $this->reference_id,
    ]);
  }

  /**
   * Batch Process for Deleting a file reference.
   *
   * @param int $reference_id
   *   File entity reference ID to delete.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesReferencedNotUsedBatchDeleteProcessBatch($reference_id, array &$context) {
    $referencedNotUsed = \Drupal::service('auditfiles.referenced_not_used');
    $worker = new static($referencedNotUsed, $reference_id);
    $worker
      ->deleteDispatch($context);
  }

  /**
   * Processes entity reference deletions from content entities to file_managed.
   *
   * @param array $context
   *   Batch context.
   */
  protected function deleteDispatch(array &$context) {
    $this->referencedNotUsed
      ->auditfilesReferencedNotUsedBatchDeleteProcessFile($this->reference_id);
    $context['results'][] = Html::escape($this->reference_id);
    $context['message'] = new TranslatableMarkup('Processed file ID %file_id.', [
      '%file_id' => $this->reference_id,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuditFilesReferencedNotUsedBatchProcess::$referencedNotUsed protected property ReferencedNotUsed service.
AuditFilesReferencedNotUsedBatchProcess::$referenceId protected property The entity reference ID to delete.
AuditFilesReferencedNotUsedBatchProcess::addDispatch protected function Processes entity reference additions from content entities to file_managed.
AuditFilesReferencedNotUsedBatchProcess::auditfilesReferencedNotUsedBatchAddProcessBatch public static function Batch Process for Adding a file reference.
AuditFilesReferencedNotUsedBatchProcess::auditfilesReferencedNotUsedBatchDeleteProcessBatch public static function Batch Process for Deleting a file reference.
AuditFilesReferencedNotUsedBatchProcess::deleteDispatch protected function Processes entity reference deletions from content entities to file_managed.
AuditFilesReferencedNotUsedBatchProcess::__construct public function Class constructor.