You are here

function node_pathauto_bulkupdate in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto_node.inc \node_pathauto_bulkupdate()
  2. 5 pathauto_node.inc \node_pathauto_bulkupdate()

Generate aliases for all nodes without aliases.

File

./pathauto_node.inc, line 66
Hook implementations for node module integration.

Code

function node_pathauto_bulkupdate() {

  // From all node types, only attempt to update those with patterns
  $pattern_types = array();

  // If there's a default pattern we assume all types might be updated.
  if (trim(variable_get('pathauto_node_pattern', ''))) {
    $pattern_types = array_keys(node_get_types('names'));
  }
  else {

    // Check first for a node specific pattern...
    $languages = array();
    if (module_exists('locale')) {
      $languages = array(
        '' => t('Language neutral'),
      ) + locale_language_list('name');
    }
    foreach (array_keys(node_get_types('names')) as $type) {
      if (trim(variable_get('pathauto_node_' . $type . '_pattern', ''))) {
        $pattern_types[$type] = $type;
        continue;
      }

      // ...then for a node-language pattern.
      if (variable_get('language_content_type_' . $type, 0) && $languages) {
        foreach ($languages as $lang_code => $lang_name) {
          if (trim(variable_get('pathauto_node_' . $type . '_' . $lang_code . '_pattern', ''))) {
            $pattern_types[$type] = $type;
            continue 2;
          }
        }
      }
    }
  }
  $count = 0;
  if (count($pattern_types)) {
    $concat = _pathauto_sql_concat("'node/'", 'n.nid');
    $sql = "SELECT n.nid FROM {node} n LEFT JOIN {url_alias} ua ON {$concat} = ua.src WHERE ua.src IS NULL AND n.type IN (" . db_placeholders($pattern_types, 'varchar') . ')';
    $query = db_query_range($sql, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50));
    $placeholders = array();
    while ($nid = db_result($query)) {
      $node = node_load($nid, NULL, TRUE);
      $placeholders = pathauto_get_placeholders('node', $node);
      $source = "node/{$node->nid}";
      if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $source, $node->nid, $node->type, $node->language)) {
        $count++;
      }
    }
  }
  drupal_set_message(format_plural($count, 'Bulk generation of nodes completed, one alias generated.', 'Bulk generation of nodes completed, @count aliases generated.'));
}