You are here

public function OrderAnonymize::anonymizeData in Commerce Bulk 8

1 call to OrderAnonymize::anonymizeData()
OrderAnonymize::anonymizeEntities in src/Plugin/Action/OrderAnonymize.php

File

src/Plugin/Action/OrderAnonymize.php, line 141

Class

OrderAnonymize
Delete terms.

Namespace

Drupal\commerce_bulk\Plugin\Action

Code

public function anonymizeData(&$data) {
  foreach ($data as $index => &$value) {
    if ($value === NULL || is_bool($value)) {
      continue;
    }
    if (is_array($value)) {
      $this
        ->anonymizeData($value);
    }
    elseif ($index == 'target_id' || $index == 'target_revision_id') {
      $value = NULL;
    }
    elseif (is_numeric($value)) {
      $str = $value[0] != 1 ? '1' : '2';
      $value = str_pad($str, strlen($value), "0");
    }
    elseif (is_string($value)) {
      $vals = array_merge(range(65, 90), range(97, 122), range(48, 57));
      $max = count($vals) - 1;
      $str = chr(mt_rand(97, 122));
      for ($i = 1; $i < strlen($value); $i++) {
        $str .= chr($vals[mt_rand(0, $max)]);
      }
      $value = $str;
    }
  }
}