Problem/Motivation

After installing the module on a site using PostgreSQL database with existing menu items we can't add menu item.

The PostgreSQL sequence menu_link_content_id_seq is corrupted by MenuLinkContentService::updateMenuLinkContentBundle().
This method backup the data from the menu_link_content table, truncate it, process field storage definition changes and then insert the backup data into the table.

After inserting the backup data the last_value of menu_link_content_id_seq sequence is update using the id of the last menu item that has been inserted.

For instance let's say we have 21 menu items.
When we retrieve the data to backup them in the array $existing_data['menu_link_content'] if we don't order them the last value in it could correspond to the 18th menu items.
The last_value of menu_link_content_id_seq is 18 and not 21 anymore.
Therefore the following error appeared when we try to add a new menu item:

SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "menu_link_content____pkey"
DETAIL:  Key (id)=(19) already exists.: INSERT INTO menu_link_content (bundle, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2);

Proposed resolution

When we retrieve the data to backup them they have to be order by id.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

Todo.

Comments

beram created an issue. See original summary.

beram’s picture

Here's a patch.

beram’s picture

Status: Active » Needs review

Status: Needs review » Needs work
voleger’s picture

Looks good for me. +1 for RTBC

kducharm’s picture

Another +1 RTBC, thanks for finding this since it only seems to affect Postgresql

ozin’s picture

Status: Needs work » Reviewed & tested by the community

  • ozin committed f87399e on 8.x-2.x authored by beram
    Issue #3022035 by beram: Installing the module corrupt PostgreSQL...
ozin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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