You are here

function contact_pathauto_bulkupdate in Pathauto 6

Bulk generate aliases for all users without aliases

File

./pathauto_user.inc, line 187
Hook implementations for user module integration.

Code

function contact_pathauto_bulkupdate() {
  $sql = "SELECT u.uid FROM {users} u LEFT JOIN {url_alias} ua ON CONCAT(CONCAT('user/', CAST(u.uid AS CHAR)), '/contact') = ua.src WHERE u.uid > 0 AND ua.src IS NULL";
  $query = db_query_range($sql, 0, variable_get('pathauto_max_bulk_update', 50));
  $count = 0;
  $placeholders = array();
  while ($uid = db_result($query)) {
    $account = user_load($uid);
    $placeholders = pathauto_get_placeholders('user', $account);
    $source = 'user/' . $account->uid . '/contact';
    if (pathauto_create_alias('contact', 'bulkupdate', $placeholders, $source, $account->uid)) {
      $count++;
    }
  }
  drupal_set_message(format_plural($count, 'Bulk generation of contact pages completed, one alias generated.', 'Bulk generation of contact pages completed, @count aliases generated.'));
}