When using the serial field token with the auto node title module, the node must be saved twice to pickup the serial value. Presumably this is because the serial field is the last thing that gets run so the token isn't populated for auto node title on the first save.

Others have tried to do this same thing using NID as discussed and patched here: http://drupal.org/node/194197

Can you have a look at that code to see if it will work with the serial field module like it does with NID?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druplicate’s picture

I solved the problem in a roundabout way as explained here in comment 63, using the rules module:

http://drupal.org/node/194197

Be careful using this technique if you have large numbers of existing nodes as this module adds a unique serial to all of them and adding the rule based technique to populate the autonodetitle eats up a lot of memory. I tried it with 1,500 nodes and it barfed after a few minutes even with a huge amount of allocated PHP memory.

I've added a bug report related to this as well: http://drupal.org/node/615470

kirsh’s picture

Assigned: Unassigned » kirsh

Using rules, as you did, is probably the right solution.

ISPTraderChris’s picture

This is clearly a bug, not a feature request. All other CCK fields I employ (even computed fields) are available in token form to be used in the Node Title on node creation. The rules approach is not the right solution, but an alternative solution given the serial CCK field is not functioning consistent with other CCK fields.

druplicate’s picture

NID as well as serial field are not available as tokens because they don't exist until the form is saved. Same issue as referenced above. The problem lies in the node auto title module and the patch applies to it, not how and when NID is assigned by core.

I just want to know if the patch applied to node-auto-title will work with this field as well. As noted in that discussion it's apparently not quite ready for prime time, however.

ISPTraderChris’s picture

After investigating this issue further, I have determined that this is in fact an issue with the Automatic Nodetitles module. It was actually a pretty simple fix, and I have posted my patch to that module here:

http://drupal.org/node/194197

druplicate’s picture

I hope that works, but the Serial module is almost unusable if you have large numbers of existing nodes because of this issue: http://drupal.org/node/615470

EDIT: Errant copy and paste. The link was wrong - now fixed.

EHA’s picture

suscribing here. i need this functionality.

rakeshakurathi’s picture

You can get this working by following druplicate's (#1 in this thread) advice. If you don't want to read the post that he links to (specifically #63 in that thread), this is how to output a serial (from the Serial Field module) in automatically generated node titles.

0. Obviously you have to have the Serial Field module installed. You will also need to add a field for your content type that is of the type serial. Furthermore, you will need to install the Rules module.

1. On the list of content types, click Edit next to the content type in question. In the section Automatic title generation, write the pattern for your title. To get the serial field value, look at the Replacement patterns help box for a section called CCK serial tokens for a token with the help text "Serial field value (unique per node type)". Save the settings.

2. Go to admin/rules and create a rule with the following details:
- Event type: After saving new content
- Add Condition: Created content is SelectYourContentType
- Add Action: Execute custom PHP code (the PHP Filter module must be activated or else you won't see this option) and enter the following code in the text area:
auto_nodetitle_operations_update(array($node->nid));
Basically, the node will run Automatic Nodetitles' method auto_nodetitle_operations_update which updated the title of a certain node.

That should be it. Now, each time you create a new node of the type SelectYourContentType, the rule you just added will make sure that the Automatic Nodetitles module will update the title for the node so that your serial is actually added to the title.

NOTE. If you create a new node that has a serial field and get a warning that the table doesn't exist (which won't output the serial in the title, obviously), just re-install the Serial Field module. Make sure you first inactivate it, then the uninstall it and finally remove the serial directory on the server. Then install the module again.

dapperry’s picture

Thanks rakeshakurathi - You were a life saver!

:) David

Jadea’s picture

For me it works to make serial field part of Auto-Node-Title on my local windows server (xampp), but when i tried to make it work at the internet server, it doesn't save the serial to the title, only when I edit and save the node again. How can it be, that it works local but not on the server? Do I have to mind something else?

Steel Rat’s picture

The issue with the Serial field is also affecting the Computed field's ability to grab the serial value, until the node is saved for a second time. An elaborate workaround using Rules isn't an option, IMHO. Can't Serial be modified to provide the value sooner so that it is available to other fields? We're pretty much just talking about an auto0incrementing field in a table, but maybe that's where the problem lies...

kirsh’s picture

Version: 6.x-1.0-rc1 » 6.x-1.0
Status: Active » Needs review
FileSize
11.78 KB

Please review the attached fix that should solve the issues with both the auto node title and the computed field.

Note: update.php has to be run because this new version changes the schema.

Steel Rat’s picture

Thanks for the update.

I got the following error when running update.php on this:

user warning: Unknown column 'i.type' in 'where clause' query: SELECT f.field_name FROM content_node_field f, content_node_field_instance i WHERE f.field_name = i.field_name AND f.type = 'serial' AND i.type = 'panel' in /home/holland/public_html/sites/all/modules/serial/serial.inc on line 49.

kirsh’s picture

FileSize
11.94 KB

Attached an attempt to fix the update warning.

christiaan_’s picture

#14 worked perfectly for me. Thank you very much.

Clint Eagar’s picture

I concur #14 worked for me, much thanks!

mautumn’s picture

#14 worked for me also. Thanks very much @kirsh. Any chance of releasing a new version of serial - to save others spending time unnecessarily on this issue? Cheers.

jaspher’s picture

Confirming that #14 worked for me too, Thanks!

parasolx’s picture

Status: Needs review » Reviewed & tested by the community

number #14 also work for me. seems it need to patch into new release.

change it to RTBC.

colan’s picture

Version: 6.x-1.0 » 7.x-1.x-dev
Assigned: kirsh » Unassigned
Category: feature » bug
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Sorry folks. I don't have time to sort through zip files. I need a patch file for this, and we'll need one for D7 first, before we can apply one for D6.

Is it even a problem in D7? If not, we can set it back to D6.

kirsh’s picture

Version: 7.x-1.x-dev » 6.x-1.0

I think that the zip from #14 can be published as is as version 6.x-1.1 and it would be better to do that before any other change.

I use it successfully for several months and apparently other users as well.

Actually the solution (of allocating the id earlier) is also applied in 7.x-1.1 (I fixed it in both D6 and D7).

colan’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
11.3 KB

None of this needs to go into the D7 branch? Really? It looks like there are some things that could apply to both.

Here's the patch I came up with after diffing from the zip file. As I no longer have a D6 site for testing, I'll leave it to all of you to apply this to the latest D6 dev branch and test it. (I already synced it with 1.0 before making some minor changes.) If everyone's happy, I can commit it.

hitfactory’s picture

This is an issue in D7, too.

colan’s picture

Version: 6.x-1.0 » 7.x-1.x-dev
Status: Needs review » Active

In that case, we'll need a D7 patch as well. I'll commit the D6 patch as soon as someone RTBCs it.

hitfactory’s picture

Attached patch for D7 includes the stuff from the D6 one that makes the serial value available earlier in hook_node_presave().

This means you can get around Auto Nodetitle's flaws and just call auto_nodetitle_set_title() from within your own module or build out the title yourself.

/**
 * Implements hook_node_presave().
 */
function my_module_node_presave($node) {
  auto_nodetitle_set_title($node);
}

Note that the D7 patch doesn't include the code for updating the serials for existing nodes using the batch API as I don't have time to go through that properly now.

After applying the patch, you need to run update.php to update the schema.

hitfactory’s picture

Dang. Botched the update. Here's another stab which also generates the serial in hook_node_presave if Auto Nodetitle module is enabled.

colan’s picture

Status: Active » Needs review

Great, thanks. Not sure I'll have time to review this in the next little but, but hopefully someone will.

We should split this into several tasks anyway to keep things manageable and understandable. Don't worry about the batch API stuff; we can tackle that in a separate issue.

kmare’s picture

Hello, I just wanted to report that the patch from #26 works great for me!
Thanks!

kmare’s picture

sorry to hijack the thread again, but I found a problem with the patch at #26. Each time I restarted the mysql service on my server, new nodes for each content type would get reset to 1, having this way multiple nodes with the same serial for the very same content type.
I fixed it (at least I think/hope so) by restoring an if statement that was removed by the patch. Specifically in the serial.inc file around line 160 it should look like this:

if ($delete && ($sid % 10) == 0) {
   db_delete($table)
     ->condition('nid', $nid, '<')
     ->execute();
}

Is there a reason why if ($delete && ($sid % 10) == 0) was remove? Cause now it looks like it's working fine (I'll have to test a little bit more of course).

Thank you in advance,
Ioannis Panteleakis

colan’s picture

Status: Needs review » Needs work

Fixing status.

hitfactory’s picture

Good catch, kmare!

The patch for D7 just apes the approach taken for D6 in serial.zip in #14 but restarting the database server also breaks that too so this definitely needs some work. Especially as the new approach dropped the node ID from the serial field tables. Sounds like this is still needed. I'll try to have another look at this soon.

hitfactory’s picture

Status: Needs work » Needs review
FileSize
9.7 KB

Only just had a chance to revisit this now. New patch restores the if statement. Also has some minor comment tweaks.

kmare’s picture

cool, thanx! I'll test as soon as I can and hopefully it'll get commited soon :)

kmare’s picture

Status: Needs review » Reviewed & tested by the community

kidrobot,
sorry for not reporting back earlier. I just tested to the patch and it looks like it's working properly. Thanks for your patch!

manuelBS’s picture

Applied this patch, works for me, too. Good work!

tvn’s picture

Patch in #32 works for me also. Thanks for it!

ulrichk’s picture

I applied the patch in #32.
Works fine when creating a new node from scratch.

But I'm also using the module "node clone" (7.x-1.0-beta1).
With this patch, the cloned (duplicated) node gets the same serial number as the original one (= wrong, should be unique). Before applying the patch, cloning worked fine for me.

http://drupal.org/project/node_clone says:

The module provides two mechanisms to clone current content. The default pre-populates the form for adding a new node, but nothing is saved to the DB until that form is submitted. With the alternative save/edit method, a copy of the current node is saved to the DB, and then presented in the edit form. When using the save/edit mode, the admin can set whether a confirmation screen is required, and in all cases you can set whether to reset the publishing options on a per-content-type basis.

I've tested both ways; no difference.

PS: I'm new here (my 1st posting); hope I did everything right :-)

colan’s picture

@ulrichk: I think the best way to handle this would be for Node Clone to provide a hook function that modules can implement in order to run their own code when the clone happens. So then Serial Field can then implement the hook by generating a new serial number instead of simply going with the copied one. I'd recommend creating two new issues, one in the Node Clone queue for the hook, and one here to implement it. (As this stuff is unrelated to this issue, it should be discussed elsewhere.)

carlovdb’s picture

Patch #32 Works fine here

cameron prince’s picture

Applying patch #32 to an already installed module causes "Unknown column uniqid" errors due to missing schema changes. You'll need to disable and uninstall the module, then apply the patch and re-enable.

maxplus’s picture

Patch #32 works for me with Auto Node Title.
It also works with Auto Entity Label now...

Thanks!

colan’s picture

Status: Reviewed & tested by the community » Fixed

Committed in b1c920e. I also added missing newlines at the end of the files. Thanks @kidrobot!

Status: Fixed » Closed (fixed)

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

sic’s picture

The patch from #32 worked like a charm, but as #40 already said you must reenable the module. Deleting and redownloading it however didnt work for me. Thats how I've done it:

- delete the serial folder in modules
- disable automatic nodetitles
- in your database, open the table system, search for an entry with name "serial" and delete the record
- download serial, the patch from #32 and apply the patch outside the drupal installation
- copy the patched serial folder in your modules folder, check the modules list and activate serial, then auto nodetitles
- use the serial token within auto nodetitles :)

thanks all!

blattmann’s picture

Is the patch in #32 for D6 or D7?

drupauler’s picture

Noob alert, sorry. Seems rediculous that this is so hard to acheive, on the other hand I at least understand the issues.

Ive just followed rakeshakurathi's recipe and it works fine with one provisio, which is that the Node creation message reads "*mynodetype* [node:field_serialno] has been created."

Do we need a rule to fire the update on the create node message as well?

Update:

It occured to me that what all I really wanted was a nicely formated node title, so I disabled Auto_NodeID and changed the action rule to

$node->title=sprintf('B%08d', [node:field_serialno]); where serialno is the name of my serial field.

Having disabled auto_nodeid, I have to set the title field to a temporary value {"XX") but thats ok because I'm testing and just wanted to take Auto_nodeid out of the equation.

What happens next is i get a node with Title =XX and a green "action message" (sorry, not sure what that is called) of B000000nn

Now what I was expecting was the node title to be set to B000000nn but it seems that node-> title is actually the green "action message" field???

Where am I going wrong?

pcambra’s picture

Can we please have a release with this change included?

colan’s picture

I don't see why not. I just released 7.x-1.3. Enjoy!

pcambra’s picture

Thanks!

naeem.farhadian’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

I have this issue, with auto_nodetitle version 7.x-1.0 and serial version 7.x-1.5 :(

WorldFallz’s picture

I can confirm this. Since auto_nodetitle hasn't changed version since the commit in #42 and the tag in #48, I went back and tested serial 1.x-1.3, 1.x-1.4, and 1.x-1.5. The regression occurs in the 1.x-1.5-- 1.x-1.4 still works properly.

A diff between 1.4 and 1.5 yields:

diff --git a/serial.module b/serial.module
index 9567fab..ef458e0 100644
--- a/serial.module
+++ b/serial.module
@@ -17,6 +17,7 @@ function serial_field_info() {
       'property_type' => 'serial',
       'default_widget' => 'serial',
       'default_formatter' => 'serial_formatter_default',
+      'property_type' => 'integer',
     ),
   );
 }
@@ -92,10 +93,8 @@ function serial_field_is_empty($item, $field) {
  * Implements hook_node_presave().
  */
 function serial_node_presave($node) {
-  if (module_exists('auto_nodetitle')) {
-    if (auto_nodetitle_get_setting($node->type)) {
-      auto_nodetitle_set_title($node);
-    }
+  if (module_exists('auto_nodetitle') && auto_nodetitle_is_needed($node)) {
+    auto_nodetitle_set_title($node);
   }
 }

Not sure I understand how that brings back the issue.

WorldFallz’s picture

reverting the second hunk fixed the issue again. Now I'll see if I can figure out why, lol.

WorldFallz’s picture

it's failing:

function auto_nodetitle_is_needed($node) {
  return empty($node->auto_nodetitle_applied) && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL && !empty($node->title));
}

because $node->auto_nodetitle_applied is TRUE at this point.

Changing serial_node_presave to the following fixes the issue:

function serial_node_presave($node) {
  if (module_exists('auto_nodetitle') && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL) && !empty($node->title)) {
    auto_nodetitle_set_title($node);
  }
}

However, I can't simply roll a patch for this against the current dev, because that entire function signature has changed, and there is no mention of auto_nodetitle in the serial.module at all.

Also, the issue is back in the 7.x-1.x dev version as well.

However, attached is a patch to the 7.x-1.5 version for anyone else stuck with this regression in the meantime.

WorldFallz’s picture

Looks like it was removed from 7.x-1.x as 'redundant' with this commit on 2/2/16.

It may not be the most elegant way to fix the issue, but it can't be redundant if removing it reintroduces the bug, lol.

Here's a patch against 7.x-1.x that simply re-adds the hook_node_presave implementation.

WorldFallz’s picture

Status: Needs work » Needs review

The last submitted patch, 22: serial_timing_fix-615410-22.patch, failed testing.

The last submitted patch, 22: serial_timing_fix-615410-22.patch, failed testing.

The last submitted patch, 22: serial_timing_fix-615410-22.patch, failed testing.

The last submitted patch, 22: serial_timing_fix-615410-22.patch, failed testing.

The last submitted patch, 25: serial-timing-fix-615410-25.patch, failed testing.

The last submitted patch, 25: serial-timing-fix-615410-25.patch, failed testing.

The last submitted patch, 25: serial-timing-fix-615410-25.patch, failed testing.

The last submitted patch, 25: serial-timing-fix-615410-25.patch, failed testing.

The last submitted patch, 26: serial-timing-fix-615410-26.patch, failed testing.

The last submitted patch, 26: serial-timing-fix-615410-26.patch, failed testing.

The last submitted patch, 26: serial-timing-fix-615410-26.patch, failed testing.

The last submitted patch, 26: serial-timing-fix-615410-26.patch, failed testing.

The last submitted patch, 32: serial-timing-fix-615410-32.patch, failed testing.

The last submitted patch, 32: serial-timing-fix-615410-32.patch, failed testing.

The last submitted patch, 32: serial-timing-fix-615410-32.patch, failed testing.

The last submitted patch, 32: serial-timing-fix-615410-32.patch, failed testing.

The last submitted patch, 53: auto_node_title_compatibility-615410-53.patch, failed testing.

The last submitted patch, 53: auto_node_title_compatibility-615410-53.patch, failed testing.

The last submitted patch, 53: auto_node_title_compatibility-615410-53.patch, failed testing.

The last submitted patch, 53: auto_node_title_compatibility-615410-53.patch, failed testing.

MustangGB’s picture

I "upgraded" from auto_nodetitle to auto_entitylabel (which does exactly the same job, but supports all entities as opposed to just nodes, and has an actively maintained codebase) and it works out of the box.

WorldFallz’s picture

@MustangGB -- brilliant! I hadn't see that one. I can confirm that serial 7.x-1.5 & auto_entitylabel 7.x-1.3 work properly out of the box.

I'm tempted to "won't fix" this with the recommendation being to switch to auto_entitylabel, but I'll leave that to the maintainers.

colan’s picture

Status: Needs review » Postponed (maintainer needs more info)

What I'm worried about is folks who are already using auto_nodetitle. Is it possible to switch easily? Is there an upgrade path? Does it do everything the original module does? If not, let's keep this one open until these are all true.

In other news, I modified the testing config to only run on PHP 5.3 as we need to support that. This should cut down on the noise.

WorldFallz’s picture

I didn't have a chance to test the migration process, but the project page states auto_nodetitle settings are migrated on installation.

MustangGB’s picture

Those are all true as far as I'm concerned.

It doesn't lose any functionality and handles the migration for you.

If you're only using tokens there is literally nothing to do.

If you're using PHP it tells you which content types you need to go into and rename $node to $entity, and that's it.

colan’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Excellent.

All: If you're running into this issue, please switch to Automatic Entity Label instead.

highflyer’s picture

Another solution (before save a node):

{ "rules_TITLE" : {
    "LABEL" : "YOUR_LABEL",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "YOUR_TAGS" ],
    "REQUIRES" : [ "rules", "php" ],
    "ON" : { "node_presave--YOUR_NODE_TYPE" : { "bundle" : "YOUR_NODE_TYPE" } },
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "node:nid" ], "revision_id" : [ "" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "DOWNLOADED_ENTITY" } }
        }
      },
      { "data_set" : {
          "data" : [ "node:title" ],
          "value" : "[node:YOUR_SERIAL_FIELD]"
        }
      }
    ]
  }
}
{ "rules_aktualizaja_tytulu_zamowienia" : {
    "LABEL" : "Aktualizaja tytulu zamowienia",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "zmiana danych" ],
    "REQUIRES" : [ "rules", "php" ],
    "ON" : { "node_presave--zlecenie" : { "bundle" : "zlecenie" } },
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "node:nid" ], "revision_id" : [ "" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Pobrana encja" } }
        }
      },
      { "data_set" : {
          "data" : [ "node:title" ],
          "value" : "Zamowienie nr [node:field_numer_zamowienia]"
        }
      }
    ]
  }
}