<commit_before><?php
/*
 * Sanitize mobile numbers on user accounts from ages ago.
 *
 *
 *
 * drush --script-path=../scripts php-script sanitize-mobile-numbers.php
 *
 */

$wild_typers = db_query("SELECT entity_id as uid, field_mobile_value as mobile
                        FROM field_data_field_mobile
                        WHERE field_mobile_value NOT REGEXP '^[0-9]+$';");


foreach($wild_typers as $wilder) {
  if ($wilder->mobile) {
    $fresh_and_clean_digits = dosomething_user_clean_mobile_number($wilder->mobile);
    if ($fresh_and_clean_digits) {
      $user = user_load($wilder->uid);
      $edit = ['field_mobile' => [ LANGUAGE_NONE => [ 0 => [ 'value' => $fresh_and_clean_digits ] ] ] ];
      user_save($user, $edit);
      print 'Updated user ' . $wilder->uid . "\n";
    }
    else {
      print 'something terrible with ' . $wilder->uid . "\n";
    }
  }
}

print 'done';
<commit_msg>More aggressively try to sanitize bad numbers, and delete any we can't fix.<commit_after><?php
/*
 * Sanitize mobile numbers on user accounts from ages ago.
 *
 *
 *
 * drush --script-path=../scripts php-script sanitize-mobile-numbers.php
 *
 */

$wild_typers = db_query("SELECT entity_id as uid, field_mobile_value as mobile
                        FROM field_data_field_mobile
                        WHERE field_mobile_value NOT REGEXP '^[0-9]+$';");


foreach($wild_typers as $wilder) {
  if ($wilder->mobile) {
    $mobile = preg_replace('[^0-9]+', '', $wilder->mobile);
    $fresh_and_clean_digits = dosomething_user_clean_mobile_number($mobile);
    if ($fresh_and_clean_digits) {
      print 'Updated user ' . $wilder->uid . "\n";
      $edit = ['field_mobile' => [ LANGUAGE_NONE => [ 0 => [ 'value' => $fresh_and_clean_digits ] ] ] ];
    }
    else {
      print 'Couldn\'t salvage ' . $wilder->uid . ' (' . $wilder->mobile . ')' . PHP_EOL;
      $edit = ['field_mobile' => [ LANGUAGE_NONE => [] ] ];
    }

    $user = user_load($wilder->uid);
    user_save($user, $edit);
  }
}

print 'done';

{'fraction_non_alphanumeric': 0.15713575335653904, 'fraction_numerical': 0.003978120338140228, 'mean_word_length': 2.8618042226487526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5983358', 'n_tokens_mistral': 717, 'n_tokens_neox': 676, 'n_words': 142}