I've started drupal 7 version but can't find solution to make the field storage per entity because mysql does not allow more then one autoincrement field per table

CommentFileSizeAuthor
#11 serial.zip11.18 KBkirsh
#9 serial.zip11.14 KBkirsh
serial.zip4.53 KBandypost
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kirsh’s picture

The same limitation of MySQL exists also when using Drupal 6.
The trick is to use a separate temporary table for every field - for the serial allocation.
Then, to copy the allocated value from that temporary table to the real CCK field.

derEremit’s picture

So, is there already someone working on a Port to 7?

KirstenLangholz’s picture

I am also looking for a Drupal 7 version of the module as it is one of the main features for this catalog website...

theroyal’s picture

Subscribing

I am using this module on my website,
how can I migrate to D7 without it ?
please port a version for D7

waltf’s picture

subscribing

hgurol’s picture

I, also, would love to see a D7 version of this module...

andypost’s picture

I this we should decide on storage for sequeces. D7 has db_sequence()... maybe better use 'serial' for field but what to do with fieldAPI multiple values - mySQL allows only one autoincrement field per table!!!

hgurol’s picture

@andypost
I dont understand the problem.
Why would I want two autoincrement fields in a table?

kirsh’s picture

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

The D7 version is attached.

If it works for others it could be released as version 7.x-1.0.

hgurol’s picture

Thanks kirsh....

I havent used this module before, so I dont know how to fully test it but...

It installs without problems and straight forward usage works well.

Using it together with auto-path and auto-nodetitles doesnt work but now I have seen on the readme file that this is not supported for D7 yet.

However, I can not reach the Serial Field values thru views. I dont know if this is a problem with views or serial field, or something by design. I dont know how to troubleshoot, debug the problem further.

kirsh’s picture

FileSize
11.18 KB

Apparently a hook that is needed by D7 views was missing.

Thank you for your report. Attached a new version.

andypost’s picture

_serial_get_table_schema() definition still describing NID field but now we operate by entities

So this table should be changed to (sid, entity_id) with description and changed upgrade path

kirsh’s picture

Hi andypost,

I don't know how exactly entity_id is managed in D7. Could you write a patch?

Upgrade should only add a field to the table, because nid is used temporarily and old values are irrelevant.

andypost’s picture

@kirsh I mean to add db_change_field() into next hook_update_N() and introduce upgrade path

serial.inc

function _serial_get_table_schema() {
  return array(
    'fields' => array(
      'sid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The atomic serial field.',
      ),
-      'nid' => array(
+      'entity_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
-        'description' => 'Id of the owner node.',
+        'description' => 'Id of the owner entity.',
      ),
    ),
    'primary key' => array('sid'),
    'unique keys' => array(
-      'nid' => array('nid'),
+      'entity_id' => array('entity_id'),
    ),
  );
}

serial.install

/**
 * Upgrade path.
 *
 * Renames all nids columns.
 */
function serial_update_7000() {
  $field_definition = array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Id of the owner entity.',
  );
  // @todo Loop through old tables.
  db_drop_unique_key($table, 'nid');
  db_change_field($table, 'nid', 'entity_id', $field_definition);
  db_add_unique_key($table, 'entity_id', array('entity_id'));
  // @todo end loop.
kirsh’s picture

Thanks.

I have another idea - replacing the nid or entity_id with a unique random ID (e.g. uniqid).
Since currently nid is only used temporarily to prevent retrieving the same serial ID by 2 concurrent threads.
By using nid or entity_id serial is limited to allocation only after the entity is saved.
Moving to uniqid will enable earlier serial number allocation in next versions of this module.

What do you think? How the new field should be defined in this case? string instead of int?

waltf’s picture

I'm having some problems that i didn't encounter in the drupal 6 version.
In the 6 version i could change the numbers in phpmyadmin, eg to 2011001, and serial would start to count from that number. In the current version this doesnt seem possible.
Any ideas? Thank u by the way!

kirsh’s picture

Changing the sequence value directly in the database has never been supported.

Maybe it works with MySQL MyISAM tables (which are used by default in D6) but not in InnoDB tables (which are used by default in D7).

Anyway, nothing was changed in the serial module itself in this aspect.

waltf’s picture

Thank u for the quick answer, greatly appreciated.
So is there any way i can define a starting number?

I'm using serial to number invoices. Every year the number changes, but the invoices have to keep their number.
2010001-2010002 then jump to 2011001.

hgurol’s picture

@waltf
with the #11, views problem is solved. I guess your using the older version..

waltf’s picture

indeed, works now. Great!

theroyal’s picture

Guys someone clear that for me, am an admin more than a developer
I am using serial in my D6 website
so I think I need 2 things to move to D7
1- a patch for the migration.
2- a D7 version to continue the same job.

am I right? , or this feature is already built in D7 core ?
someone clear that up for me please.

kirsh’s picture

Assigned: Unassigned » kirsh
kirsh’s picture

Version: 6.x-1.0 » 7.x-1.0
PepeMty’s picture

subs

Rix-1’s picture

Have tested and this works great (so far!) I used the most recent zip file you supplied. The site I have used it on is a Drupal 7 site with only views, chaos tools and serial installed with no conflicts.

Two quick requests / questions:
1. How do I start the auto-number in the format 1001 instead of just 1?
This is important because users who search for a serial number and type in "1" in search it would actually bring up every node with a "1" in it (comments, titles, fields, etc)! If it was 1001 onwards this would seriously limit the results.

2. What is the maximum serial number? 9,999? Can it go higher?

PS - Thanks for all your work on this - great job!

Rix-1’s picture

Any movement on this? Happy to paypal donate if it speeds up development.

kirshi’s picture

Hi Rix,

Thanks, but that will not be necessary.

You can use the Computed Field module to define another field that will be based on serial field + 1000, etc.

I believe serial fields are not limited to 9999.

yugongtian’s picture

+1

Rix-1’s picture

Thanks for the response, I have tried to use it but can't work out the steps to do it - I'm sure it's simple enough. Help anyone?

enjaygee’s picture

Issue tags: +db_rewrite_sql()

I get the following error when installing:
Call to undefined function db_rewrite_sql() in serial.inc on line 55

db_rewrite_sql() is for versions prior to D7.
hook_query_alter() is apparently the way to go now
(see http://api.drupal.org/api/drupal/includes--database.inc/function/db_rewr...)

enjaygee’s picture

Issue tags: -db_rewrite_sql() +old_type

Was receiving the following message:
Notice: Undefined property: stdClass::$old_type in serial.module (line 101). Was able to deal with this by checking if the value was set:

function serial_node_type_update($info) {
// Handle content type rename:
if(isset($info->old_type)) {
if($info->old_type != $info->type) {
module_load_include('inc', 'serial');
_serial_rename_tables($info->old_type, $info->type);
}
}
}

Ollie222’s picture

Using Drupal 7 when I set the display to hidden instead of 9999 it shows an blue ring (autocomplete style) which just stays on the screen. If I press save it just reverts back to the 9999 format.

Does anyone else have this issue?

lightstring’s picture

Subscribing

TommyChris’s picture

subscribe

alexmoreno’s picture

hi,

after installing the versión 3 (posted in #11), i get this error every time i try to submit a new node with this field:

Notice: Undefined property: stdClass::$field_serial en locale_field_node_form_submit() (línea 409 de /var/www/facturacion/modules/locale/locale.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '17' for key 'nid': INSERT INTO {serial_factura_cliente_field_serial} (nid) VALUES(:nid); Array ( [nid] => 17 ) en _serial_generate_value() (línea 139 de /var/www/facturacion/sites/all/modules/serial/serial.inc).

any idea?

Thanks.

alexmoreno’s picture

checked the versions in dev and rc1 with same results

Yuri’s picture

subscribing

leszek.hanusz’s picture

subscribing

hubrt’s picture

subscribed

JohnnyX’s picture

Also problems after install...

Subscribe

rreimche’s picture

subscribing

montchr’s picture

subscribe

wizian’s picture

subscribe

david.riches’s picture

subscribe

colan’s picture

Status: Needs review » Needs work

It would seem as though users are experiencing problems.

westbywest’s picture

subscribing

field4000’s picture

Subscribing.

TommyChris’s picture

Title: Drupal 7 port » Serial Field D7 port

Renamed issue.

toomanypets’s picture

subscribe -- anyone have any leads on a similar module that is being actively maintained?

colan’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Needs work » Closed (fixed)
Issue tags: -old_type

There is now a release for D7. Some problems here already exist as other issues. If you can't find your problem in the queue, please create a new issue, but make sure you try the dev version first.

alex.barylski’s picture

Nevermind...figured it out...my bad :)