You are here

class AuditFilesUsedNotManagedBatchProcess in Audit Files 4.x

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

Batch Worker to remove files from file_usage not in file_managed table.

Hierarchy

Expanded class hierarchy of AuditFilesUsedNotManagedBatchProcess

File

src/Batch/AuditFilesUsedNotManagedBatchProcess.php, line 12

Namespace

Drupal\auditfiles\Batch
View source
class AuditFilesUsedNotManagedBatchProcess {

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

  /**
   * ManagedNotUsed service.
   *
   * @var \Drupal\auditfiles\ServiceAuditFilesusedNotManaged
   */
  protected $usedNotManaged;

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

  /**
   * The batch process for deleting the file feature 'used not managed'.
   *
   * @param int $file_id
   *   File entity ID to delete.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesUsedNotManagedBatchDeleteProcessBatch($file_id, array &$context) {
    $usedNotManaged = \Drupal::service('auditfiles.used_not_managed');
    $worker = new static($usedNotManaged, $file_id);
    $worker
      ->dispatch($context);
  }

  /**
   * Processes removal of files from file_managed that are not in file_usage.
   *
   * @param array $context
   *   Batch context.
   */
  protected function dispatch(array &$context) {
    $this->usedNotManaged
      ->auditfilesUsedNotManagedBatchDeleteProcessFile($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
AuditFilesUsedNotManagedBatchProcess::$fileId protected property The File entity ID to delete.
AuditFilesUsedNotManagedBatchProcess::$usedNotManaged protected property ManagedNotUsed service.
AuditFilesUsedNotManagedBatchProcess::auditfilesUsedNotManagedBatchDeleteProcessBatch public static function The batch process for deleting the file feature 'used not managed'.
AuditFilesUsedNotManagedBatchProcess::dispatch protected function Processes removal of files from file_managed that are not in file_usage.
AuditFilesUsedNotManagedBatchProcess::__construct public function Class constructor.