Skip to content

Instantly share code, notes, and snippets.

@jessehs
Created March 19, 2014 17:00
Show Gist options
  • Save jessehs/9646202 to your computer and use it in GitHub Desktop.
Save jessehs/9646202 to your computer and use it in GitHub Desktop.
Rather than using `drush geocoder-backfill`, I'm running `drush scr /path/to/this/file` on cron to update profiles.
<?php
$range = 50;
$offset = variable_get('my_custom_profiles_update_offset', 0);
$query = db_select('users', 'u')
->fields('u', array('uid'));
$query->join('users_roles', 'ur', 'u.uid = ur.uid');
$or = db_or();
$or->condition('ur.rid', '9', '=');
$or->condition('ur.rid', '15', '=');
$query->condition($or);
$query->range($offset, $range);
$results = $query->execute();
while ($uid = $results->fetchField()) {
if ($profile = profile2_load_by_user($uid, 'my_custom_profile')) {
$profile->save();
print ("\n updated " . $uid);
}
}
variable_set('my_custom_profiles_update_offset', $offset + $range);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment