You are here

function node_pathauto_bulkupdate in Pathauto 5.2

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

Generate aliases for all nodes without aliases.

File

./pathauto_node.inc, line 47
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();
  $type_where = '';
  foreach (node_get_types() as $type => $info) {
    $pattern = '';
    $pattern = variable_get('pathauto_node_' . $type . '_pattern', '');

    // If it's not set, check the default
    if (!trim($pattern)) {
      $pattern = variable_get('pathauto_node_pattern', '');
    }
    if (trim($pattern)) {
      $pattern_types[] = $type;
      if (!trim($type_where)) {
        $type_where = " AND (type = '%s' ";
      }
      else {
        $type_where .= " OR type = '%s'";
      }
    }
  }
  $type_where .= ')';
  $query = "SELECT nid, type, title, uid, created, src, dst, vid FROM {node} LEFT JOIN {url_alias} ON CONCAT('node/', CAST(nid AS CHAR)) = src WHERE src IS NULL " . $type_where;
  $result = db_query_range($query, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50));
  $count = 0;
  $placeholders = array();
  while ($node_ref = db_fetch_object($result)) {
    $node = node_load($node_ref->nid, NULL, TRUE);
    $node->src = $node_ref->src;
    $node->dst = $node_ref->dst;
    if (module_exists('taxonomy')) {

      // Must populate the terms for the node here for the category
      // placeholders to work
      $node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
    }
    $placeholders = pathauto_get_placeholders('node', $node);
    $src = "node/{$node->nid}";
    if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $src, $node->nid, $node->type)) {
      $count++;
    }
  }
  drupal_set_message(format_plural($count, 'Bulk generation of nodes completed, one alias generated.', 'Bulk generation of nodes completed, @count aliases generated.'));
}