You are here

class AuditFilesNotInDatabaseBatchProcess in Audit Files 4.x

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

Process batch files.

Hierarchy

Expanded class hierarchy of AuditFilesNotInDatabaseBatchProcess

File

src/Batch/AuditFilesNotInDatabaseBatchProcess.php, line 12

Namespace

Drupal\auditfiles\Batch
View source
class AuditFilesNotInDatabaseBatchProcess {

  /**
   * The file name to process.
   *
   * @var string
   */
  protected $fileName;

  /**
   * ReferencedNotUsed service.
   *
   * @var \Drupal\auditfiles\ServiceAuditFilesNotInDatabase
   */
  protected $notInDatabase;

  /**
   * Class constructor.
   *
   * @param \Drupal\auditfiles\ServiceAuditFilesNotInDatabase $not_in_database
   *   Injected ServiceAuditFilesUsedNotManaged service.
   * @param string $file_name
   *   File name to process.
   */
  public function __construct(ServiceAuditFilesNotInDatabase $not_in_database, $file_name) {
    $this->notInDatabase = $not_in_database;
    $this->fileName = $file_name;
  }

  /**
   * The batch process for adding the file.
   *
   * @param string $filename
   *   File name that to be process.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesNotInDatabaseBatchAddProcessBatch($filename, array &$context) {
    $notInDatabase = \Drupal::service('auditfiles.not_in_database');
    $worker = new static($notInDatabase, $filename);
    $worker
      ->addDispatch($context);
  }

  /**
   * Adds filenames referenced in content in file_managed but not in file_usage.
   *
   * @param array $context
   *   Batch context.
   */
  protected function addDispatch(array &$context) {
    $this->notInDatabase
      ->auditfilesNotInDatabaseBatchAddProcessFile($this->fileName);
    $context['results'][] = Html::escape($this->fileName);
    $context['message'] = new TranslatableMarkup('Processed %filename.', [
      '%filename' => $this->fileName,
    ]);
  }

  /**
   * The batch process for deleting the file.
   *
   * @param string $filename
   *   File name that needs to be processed.
   * @param array $context
   *   Batch context.
   */
  public static function auditfilesNotInDatabaseBatchDeleteProcessBatch($filename, array &$context) {
    $notInDatabase = \Drupal::service('auditfiles.not_in_database');
    $worker = new static($notInDatabase, $filename);
    $worker
      ->deleteDispatch($context);
  }

  /**
   * Deletes filenames referenced in content frm file_managed not in file_usage.
   *
   * @param array $context
   *   Batch context.
   */
  protected function deleteDispatch(array &$context) {
    $this->notInDatabase
      ->auditfilesNotInDatabaseBatchDeleteProcessFile($this->fileName);
    $context['results'][] = Html::escape($this->fileName);
    $context['message'] = new TranslatableMarkup('Processed %filename.', [
      '%filename' => $this->fileName,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuditFilesNotInDatabaseBatchProcess::$fileName protected property The file name to process.
AuditFilesNotInDatabaseBatchProcess::$notInDatabase protected property ReferencedNotUsed service.
AuditFilesNotInDatabaseBatchProcess::addDispatch protected function Adds filenames referenced in content in file_managed but not in file_usage.
AuditFilesNotInDatabaseBatchProcess::auditfilesNotInDatabaseBatchAddProcessBatch public static function The batch process for adding the file.
AuditFilesNotInDatabaseBatchProcess::auditfilesNotInDatabaseBatchDeleteProcessBatch public static function The batch process for deleting the file.
AuditFilesNotInDatabaseBatchProcess::deleteDispatch protected function Deletes filenames referenced in content frm file_managed not in file_usage.
AuditFilesNotInDatabaseBatchProcess::__construct public function Class constructor.