You are here

private function Anonymizer::writeLogToFile in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_tasks/src/Anonymizer.php \Drupal\gdpr_tasks\Anonymizer::writeLogToFile()
  2. 3.0.x modules/gdpr_tasks/src/Anonymizer.php \Drupal\gdpr_tasks\Anonymizer::writeLogToFile()

Stores the task log to the configured directory as JSON.

Parameters

\Drupal\gdpr_tasks\Entity\TaskInterface $task: The task in progress.

array $log: Log of processed fields.

1 call to Anonymizer::writeLogToFile()
Anonymizer::run in modules/gdpr_tasks/src/Anonymizer.php
Runs anonymization routines against a user.

File

modules/gdpr_tasks/src/Anonymizer.php, line 204

Class

Anonymizer
Anonymizes or removes field values for GDPR.

Namespace

Drupal\gdpr_tasks

Code

private function writeLogToFile(TaskInterface $task, array $log) {
  $filename = 'GDPR_RTF_' . date('Y-m-d H-i-s') . '_' . $task
    ->uuid() . '.json';
  $dir = $this->configFactory
    ->get(RemovalSettingsForm::CONFIG_KEY)
    ->get(RemovalSettingsForm::EXPORT_DIRECTORY);
  $filename = $dir . '/' . $filename;

  // Don't serialize the whole entity as we don't need all fields.
  $output = [
    'task_id' => $task
      ->id(),
    'task_uuid' => $task
      ->uuid(),
    'owner_id' => $task
      ->getOwnerId(),
    'created' => $task
      ->getCreatedTime(),
    'processed_by' => $this->currentUser
      ->id(),
    'log' => $log,
  ];
  file_put_contents($filename, json_encode($output));
}