Created
July 17, 2017 20:46
-
-
Save mmenavas/21f2f084d6b307a510bb2ae4fdffaa76 to your computer and use it in GitHub Desktop.
Use this script to fill in the 'mail' field in the users table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'user', '='); | |
$query->propertyCondition('mail', NULL); | |
$query->propertyCondition('uid', 0, '>'); | |
$query_result = $query->execute(); | |
if (isset($query_result['user'])) { | |
// EFQ query results are keyed by entity ID | |
$user_ids = array_keys($query_result['user']); | |
$users = user_load_multiple($user_ids); | |
array_map(function($user) { | |
$user->mail = $user->name . "@asu.edu"; | |
user_save($user); | |
}, $users); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment