You are here

class AuditFilesManagedNotUsedBatchProcess in Audit Files 4.x

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

Batch Worker to handle Deleting entity records from file_managed table.

Hierarchy

Expanded class hierarchy of AuditFilesManagedNotUsedBatchProcess

File

src/Batch/AuditFilesManagedNotUsedBatchProcess.php, line 12

Namespace

Drupal\auditfiles\Batch
View source
class AuditFilesManagedNotUsedBatchProcess {

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

  /**
   * ManagedNotUsed service.
   *
   * @var \Drupal\auditfiles\ServiceAuditFilesManagedNotUsed
   */
  protected $managedNotUsed;

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

  /**
   * Batch process to delete file entities from file_managed not in file_usage.
   *
   * @param int $file_id
   *   File entity ID to delete.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesManagedNotUsedBatchDeleteProcessBatch($file_id, array &$context) {
    $managedNotUsed = \Drupal::service('auditfiles.managed_not_used');
    $worker = new static($managedNotUsed, $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->managedNotUsed
      ->auditfilesManagedNotUsedBatchDeleteProcessFile($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
AuditFilesManagedNotUsedBatchProcess::$fileId protected property The File entity ID to delete.
AuditFilesManagedNotUsedBatchProcess::$managedNotUsed protected property ManagedNotUsed service.
AuditFilesManagedNotUsedBatchProcess::auditfilesManagedNotUsedBatchDeleteProcessBatch public static function Batch process to delete file entities from file_managed not in file_usage.
AuditFilesManagedNotUsedBatchProcess::dispatch protected function Processes removal of files from file_managed that are not in file_usage.
AuditFilesManagedNotUsedBatchProcess::__construct public function Class constructor.