Skip to content

Conversation

@Herafia
Copy link
Contributor

@Herafia Herafia commented Dec 16, 2025

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.

Description

  • It fixes !40431

When transferring a ticket to another entity, if a document is already linked to the same object in the destination entity, a SQL duplicate error occurs.

This error is caused by the unique constraint on the glpi_documents_items table, applied to the columns (documents_id, itemtype, items_id, timeline_position).

Modification of the transferDocuments method in Transfer.php.

Before each UPDATE: check whether the target relationship already exists :

  • If it does: delete the existing entry instead of updating it
  • If it does not: perform the UPDATE as usual

Before each INSERT: check whether the relationship already exists :

  • If it does: skip the insertion (no error)
  • If it does not: perform the INSERT as usual

@Herafia Herafia requested review from Rom1-B and stonebuzz December 16, 2025 15:52
@trasher
Copy link
Contributor

trasher commented Dec 16, 2025

Please add tests.

Similar errors also happen on other itemtypes; see #20256 (documents and softwareversion so far). Fix is maybe the same.

]);
$this->assertGreaterThan(0, $ticket_source_id);

// Link the SAME document to the source ticket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that was what I missed when I take a look at similar issue ^^

@cedric-anne cedric-anne added this to the 11.0.5 milestone Dec 18, 2025
@Herafia Herafia requested review from Rom1-B and stonebuzz December 19, 2025 14:56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests do not seem to execute the code you modified.

@stonebuzz
Copy link
Contributor

@AdrienClairembault, the E2E tests that are failing do not seem to be related to this PR. Could you please confirm?

@AdrienClairembault
Copy link
Contributor

@AdrienClairembault, the E2E tests that are failing do not seem to be related to this PR. Could you please confirm?

Yes, I confirm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants