Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix common db relation insertion #439

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Lainow
Copy link
Contributor

@Lainow Lainow commented Nov 19, 2024

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

  • It fixes !35251
  • Here is a brief description of what this PR does
    Fixed an error when inserting data linked to a relationship table (for example, the supplier identifier was removed from the list because the type was relationship).

Screenshots (if appropriate):

@Lainow Lainow force-pushed the fix-commondbrelation-injection branch from b8d0174 to 9c5735f Compare November 19, 2024 14:13
@Lainow Lainow requested review from stonebuzz and Rom1-B and removed request for stonebuzz November 19, 2024 14:49
Copy link
Contributor

@Rom1-B Rom1-B left a comment

Choose a reason for hiding this comment

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

It looks OK, can you get the customer to validate it?

@@ -1606,7 +1606,7 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr
//CommonDBRelation are managed separately, so related field should be ignored
// Ex : User -> groups_id -> Group_User
// groups_id should not be injected in User (field contains group name (string))
if ($option !== false && isset($option['displaytype']) && $option['displaytype'] == 'relation') {
if ($option !== false && isset($option['displaytype']) && $option['displaytype'] == 'relation' && !($item instanceof CommonDBRelation)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the fix, with this example (inject groups_id from User object)

User -> groups_id (from Group_User)

The condition will return false (to delegate to specific case) -> OK

But with this

User -> name

The condition will return false -> KO

Because User is not an instance of CommonDBRelation

Suggested change
if ($option !== false && isset($option['displaytype']) && $option['displaytype'] == 'relation' && !($item instanceof CommonDBRelation)) {
if (($option !== false && isset($option['displaytype']) && $option['displaytype'] == 'relation') || !($item instanceof CommonDBRelation)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the || operator, the plugin doesn't insert any data, whereas with &&, all data is actually inserted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I tested with a user like you said but everything works perfectly.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@stonebuzz
Copy link
Contributor

It looks OK, can you get the customer to validate it?

@stonebuzz
Copy link
Contributor

Reminder (adapt CHANGELOG.md)

@Lainow Lainow force-pushed the fix-commondbrelation-injection branch from 9153c87 to 8acb323 Compare December 11, 2024 13:47
@stonebuzz stonebuzz self-requested a review December 11, 2024 13:49
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Stanislas <[email protected]>
@stonebuzz
Copy link
Contributor

can you rebase (customer is OK with this change?)

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.

3 participants