Autonode title only runs when creating or updating nodes, therefore existing nodes will not be upgraded. Here's some background:

I have a content type with 25 CCK fields that did NOT have auto_nodetitle installed, but after assessing our existing nodes (all 13000), we decided to use auto_nodetitle to pull from a few of those fields so titles would be standardized. I have tested creating a new node, and auto_nodetitle works perfectly. However, does anyone know how to update ALL our existing nodes to implement this module?

Would this involve running a nodeapi hook for auto_nodetitle on every node? Hmmmm...

Comments

Anonymous’s picture

Title: Refresh Existing Nodes to run Auto NodeTitle » Fixed this with SQL

Ok, I just updated all my nodes using a simple SQL script, but this might be a great feature in the future... perhaps running a lot of invoke_nodeapi calls? PHP timeout anyone?

deekayen’s picture

@kevee it would be nice if you attached your script so it could be added to a contrib subdirectory to the distrib tarball, or at least be found when this page turns up in search results.

fago’s picture

Title: Fixed this with SQL » Refresh Existing Nodes to run Auto NodeTitle
Version: 5.x-1.0 » 5.x-1.x-dev
Status: Active » Postponed

There won't be any new features for 5.x any more.

smcguinness’s picture

kevee - How did you ultimately accomplish your task? We definitely don't have the 13000 nodes you have, but we have around 500, and I think 10 is too many to have to do by hand. Thanks.

doc2@drupalfr.org’s picture

Interested too in the feature.

Fago #3:There won't be any new features for 5.x any more.

> Even if someone else helps maitnaining/developping? Or do you prefer that the module be a new one?

deekayen’s picture

I'm not sure what #5 means, but please, please don't fork to another module. There are already too many duplicated functionalities in the modules pool now. I'm sure with a quality patch, fago can be swayed. He's an active developer and your patch certainly wouldn't go un-noticed.

doc2@drupalfr.org’s picture

please don't fork to another module. There are already too many duplicated functionalities in the modules pool now

I share your point. I would prefer to keep one module. I just said that because sometimes developpers/authors have a certains idea of what their module will do and thus they often restrict/don't want new features (ex. with http://drupal.org/project/CCK_taxonomy)

I understand this but, on the other hand, patching on and on lower the reliability of the modules. Having no clues yet on the "roadmap" the Automatic Nodetitles module took and reading moreover the "postponed" status, I asked the question of a new module in case I find someone who agrees to (1) release stable versions (even if they still have a -dev version name, this doesn't matter) with all contributions commited by, say, the end of March from the drupal community, or by the end of June if we get internal resources to do so. Because unfornutenately, we don't have the competence yet. And of course, I don't want to impose my needs to developpers unless they enjoy those little challenges :)

(2) For infos as well, I reopened this feature request: #173614: Node Title Optional

(3) And I wonder about the compatibility with http://drupal.org/project/pathauto

Links to (i) related topics would be greatly welcome if you know well the issues around this great module! Greetings,

Arsène

fago’s picture

of course - If you provide a well written, clean patch for 5.x *and* an also well written port to 6.x, then I'd love to commit your work!

nruest’s picture

soooo.....

did anybody figure out what the illusive sql script is?

nruest’s picture

here is a solution:

function rename_titles_submit() {

$result = db_query("SELECT nid FROM {node} where type=''query");

while($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
auto_nodetitle_set_title($node);
node_save($node);
}

Anonymous’s picture

Where do you run the above code at?

txcrew

nruest’s picture

i just created a module. that is the function you can call for the module.

doc2@drupalfr.org’s picture

Dear Nick, where to find your module or what's its name? Thanks in advance, Arsène

doc2@drupalfr.org’s picture

Is this code all what a new module needs? please just tell us some few more things to get started... how do you call this function?...

doc2@drupalfr.org’s picture

I tried to set up a new module:

<?php
// $Id: image_title.module,v 1.0 2008/05/16 17:27:00 drumm Exp $

/**
 * @file
 * Helps to batch rename nodes per imagenode.
 * Ref.: drupal.org/node/161760#comment-755384
 */

/**
 * Implementation of rename_titles_submit().
 */

function rename_titles_submit() {

$result = db_query("SELECT n.nid FROM {node} n where type=''query");

while($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
auto_nodetitle_set_title($node);
node_save($node);
}
?>

But I got an error message on its last line (the one of the while closing bracket):
Parse error: syntax error, unexpected $end in /Shared Items/iDoc/drupal/modules/image_title/image_title.module on line 22

PleeeeeaZe HeLp .!:

ali27’s picture

i modified the module name look to the next comment

ali27’s picture

Assigned: Unassigned » ali27
Status: Postponed » Needs review

it's a module autotitle for the automatic nodetitle
don't forget to create a module.info

// $Id: autotitle.module,v 1.9.8.2 2008/05/20 15:30:14 ali27 Exp $

/**
 * Implementation of hook_help().
 */
function autotitle_help($section = '') {
  switch ($section) {
    case 'admin/content/autotitle':
      $output = '<p>'. t("automatic node title").'</p>';
      return $output;
    default:
      return null;
  }
}

/**
 * Implementation of hook_perm().
 */
function autotitle_perm() {
  return array('automatic node title');
}

/**
 * Implementation of hook_menu().
 */
function autotitle_menu($may_cache) {
 $items = array();
  if ($may_cache) {
      $items[] = array(
      'path' => 'admin/content/autotitle',
      'title' => t('automatic node title'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('autotitle_form'),
      'access' => user_access('automatic node title form'),
      'type' => MENU_NORMAL_ITEM,
      'description' => t('automatic node title by node type')
    );
 }
  return $items;
}

/**
 * Implementation of hook_form().
 */
 
function autotitle_form() {

$form['autotitle']=array();

  $form['autotitle']['type']=array(
    '#type' => 'select',
	'#title' => t('list of nodes type'),
	'#options' => _autotitle_get_types(),
    '#required' =>TRUE,
	'#size'=> 10,
      );
 
    $form['autotitle']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Rename'),
    );

return $form;
}

/**
* Implementation of autotitle_form_submit().
*/

function autotitle_form_submit($node, $form_values) {
	if (t('Rename') == $form_values['op']) 
	{
	$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n where type='%s'"),$form_values['type']);
		while($nid = db_fetch_object($result)) {
		$node = node_load($nid->nid);
		auto_nodetitle_set_title(&$node);
		node_save($node);  
		}
	}
}

/**
 * function to get all node types 
 */

function _autotitle_get_types()
{
  	$result = db_query(db_rewrite_sql("SELECT DISTINCT n.type,t.name  FROM {node} n,{node_type} t WHERE n.type=t.type ORDER BY type ASC"));
  
 	while ($node = db_fetch_object($result)) {
   	$rows[$node->type] = $node->name;
 			 }
 return $rows;
}
fago’s picture

Category: feature » task
Status: Needs review » Needs work

please just create a patch for auto node title, which adds in this feature directly into the module. Be sure to follow drupal's code style (tabs!).

Miszel’s picture

nruest,

You can update all the titles with a MySql query. Say, you have a content type called 'author' and you want to set the title to the author's first name and last name. If the first name and last name fields are in a table called 'node_author' (please check it!), you can run the following query in phpMyAdmin:

UPDATE node_author na
JOIN node n
ON n.nid = na.nid
SET n.title = CONCAT(na.field_first_name_value,' ',na.field_last_name_value)
WHERE n.type = 'author'

Gerald Mengisen’s picture

This issue here could be probably closed due to the the patch in issue #321611: Batch update node titles ?

fago’s picture

Status: Needs work » Fixed

yep.. :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.