Hello !!

I've just install xmlsitemap (and xmlsitemap_custom) to create my sitemap.
It works fine, but i want to create a script to insert custom links by running a hook_update.
And db_insert query abort, cause of duplicate key in xmlsitemap table.
So I check hook_schema, and xmlsitemap id is an integer, but no autoincrement..

Is there a reason for that ?

Here is a little patch to make this field autoincrement !!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

OwilliwO’s picture

dpovshed’s picture

Status: Active » Needs work

Hi OwilliwO,
your patch is formally fine. But I think adding that change may have side effects with current approach about primary key - (both type+id).

I would recommend for your script to use the drupal_write_record() function, in the same way as the xmlsitemap_link_save() does.

What do you think?

Dave Reid’s picture

Status: Needs work » Closed (works as designed)

The field is not a serial value because it's coming from actual data, so we need to save the right value, and not have it autogenerated. For example, when saving the link for node 1, the id = 1 and type = 'node'. If we saved the link for user 1 next, then id = 1 and type = 'user'. Both of those records need an ID of '1' since that correspond to the ID of the item being inserted. This is why the primary key is actually a compound key of both the id and type columns.

OwilliwO’s picture

Hi Dave.

I don't remember why it was a problem to me.. I think that was some SQL error, kind of duplicate entry in id column..
But if the primary is both id and type column, it should be fine for entites link.
What if I add a custom hook_menu_entry ? No type for this xmlsitemap entry ?

Maybe it would be better if you set a id with autoincrement, and a index or foreign jey on entity_id and type columns ?

Have a nice day !