You are here

public function AnonymizeRecords::anonymize in Library 8

Anonymize entry.

File

src/AnonymizeRecords.php, line 78

Class

AnonymizeRecords
Anonymize records helper.

Namespace

Drupal\library

Code

public function anonymize() : void {
  switch ($this->config
    ->get('anonymize_transactions')) {
    case 'daily':
      $interval = 86400;
      break;
    case 'weekly':
      $interval = 86400 * 7;
      break;
    case 'monthly':
      $interval = 86400 * 30;
      break;
    case 'never':
    default:
      $interval = 0;
      break;
  }
  $lastCheck = $this->state
    ->get('library_last_anonymization');
  if ($interval > 0 && strtotime('today') + $interval >= $lastCheck) {
    $items = \Drupal::entityQuery('library_item')
      ->condition('library_status', LibraryItemInterface::ITEM_AVAILABLE)
      ->execute();
    $this
      ->processBatch($items);
    $this->state
      ->set('library_last_anonymization', strtotime('today'));
  }
}