View source
<?php
namespace Drupal\auditfiles;
use Drupal\Component\Utility\Html;
use Drupal\Core\Messenger\MessengerTrait;
class AuditFilesBatchProcess {
use MessengerTrait;
public static function auditfilesNotInDatabaseBatchFinishBatch($success, $results, $operations) {
if ($success) {
}
else {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesNotInDatabaseBatchAddProcessBatch($filename, array &$context) {
\Drupal::service('auditfiles.not_in_database')
->auditfilesNotInDatabaseBatchAddProcessFile($filename);
$context['results'][] = $filename;
$context['message'] = t('Processed %filename.', [
'%filename' => $filename,
]);
}
public static function auditfilesNotInDatabaseBatchDeleteProcessBatch($filename, array &$context) {
\Drupal::service('auditfiles.not_in_database')
->auditfilesNotInDatabaseBatchDeleteProcessFile($filename);
$context['results'][] = Html::escape($filename);
$context['message'] = t('Processed %filename.', [
'%filename' => $filename,
]);
}
public static function auditfilesMakePreg(&$element, $key = '', $makefilepath = FALSE) {
if ($makefilepath) {
$realpath = \Drupal::service('file_system')
->realpath(file_build_uri($element));
if ($realpath) {
$element = $realpath;
}
}
$element = preg_quote($element);
}
public static function auditfilesNotOnServerBatchFinishBatch($success, $results, $operations) {
if ($success) {
}
else {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesNotOnServerBatchDeleteProcessBatch($file_id, array &$context) {
\Drupal::service('auditfiles.not_on_server')
->auditfilesNotOnServerBatchDeleteProcessFile($file_id);
$context['results'][] = $file_id;
$context['message'] = t('Processed file ID %file_id.', [
'%file_id' => $file_id,
]);
}
public static function auditfilesManagedNotUsedBatchDeleteProcessBatch($file_id, array &$context) {
\Drupal::service('auditfiles.managed_not_used')
->auditfilesManagedNotUsedBatchDeleteProcessFile($file_id);
$context['results'][] = $file_id;
$context['message'] = t('Processed file ID %file_id.', [
'%file_id' => $file_id,
]);
}
public static function auditfilesManagedNotUsedBatchFinishBatch($success, $results, $operations) {
if (!$success) {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesUsedNotManagedBatchDeleteProcessBatch($file_id, array &$context) {
\Drupal::service('auditfiles.used_not_managed')
->auditfilesUsedNotManagedBatchDeleteProcessFile($file_id);
$context['results'][] = $file_id;
$context['message'] = t('Processed file ID %file_id.', [
'%file_id' => $file_id,
]);
}
public static function auditfilesUsedNotManagedBatchFinishBatch($success, $results, $operations) {
if (!$success) {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesUsedNotReferencedBatchDeleteProcessBatch($file_id, array &$context) {
\Drupal::service('auditfiles.used_not_referenced')
->auditfilesUsedNotReferencedBatchDeleteProcessFile($file_id);
$context['results'][] = $file_id;
$context['message'] = t('Processed file ID %file_id.', [
'%file_id' => $file_id,
]);
}
public static function auditfilesUsedNotReferencedBatchFinishBatch($success, $results, $operations) {
if (!$success) {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesReferencedNotUsedBatchFinishBatch($success, $results, $operations) {
if (!$success) {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesReferencedNotUsedBatchAddProcessBatch($reference_id, array &$context) {
\Drupal::service('auditfiles.referenced_not_used')
->auditfilesReferencedNotUsedBatchAddProcessFile($reference_id);
$context['results'][] = $reference_id;
$context['message'] = t('Processed reference ID %file_id.', [
'%file_id' => $reference_id,
]);
}
public static function auditfilesReferencedNotUsedBatchDeleteProcessBatch($reference_id, array &$context) {
\Drupal::service('auditfiles.referenced_not_used')
->auditfilesReferencedNotUsedBatchDeleteProcessFile($reference_id);
$context['results'][] = $reference_id;
$context['message'] = t('Processed reference ID %file_id.', [
'%file_id' => $reference_id,
]);
}
public static function auditfilesMergeFileReferencesBatchFinishBatch($success, $results, $operations) {
if (!$success) {
$error_operation = reset($operations);
$self::messenger()
->addError(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}
public static function auditfilesMergeFileReferencesBatchMergeProcessBatch($file_being_kept, $file_being_merged, array &$context) {
\Drupal::service('auditfiles.merge_file_references')
->auditfilesMergeFileReferencesBatchMergeProcessFile($file_being_kept, $file_being_merged);
$context['results'][] = $file_being_merged;
$context['message'] = t('Merged file ID %file_being_merged into file ID %file_being_kept.', [
'%file_being_kept' => $file_being_kept,
'%file_being_merged' => $file_being_merged,
]);
}
}