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(Core): prevent twice 'date_mod' updates #18130

Closed
wants to merge 1 commit into from

Conversation

stonebuzz
Copy link
Contributor

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.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

Bug found with fields plugin (but all plugins could be impacted when)

The fields plugin (after managing additional fields) adds a date_mod in the mainitem's input to update only last modification date.

when the update occurs glpi checks if date_mod exists in $this->fields, and if so, adds it to $this->updates (which already contains date_mode -> because of fields plugin)

if (array_key_exists('date_mod', $this->fields)) {
    // is a non blacklist field exists
    if (count(array_diff($this->updates, $this->history_blacklist)) > 0) {
        $this->fields['date_mod'] = $_SESSION["glpi_currenttime"];
        $this->updates[$x++]      = 'date_mod';
    }
}

When glpihandle locked fields, this

$idx = array_search('date_mod', $fields);
if ($idx !== false) {
    unset($fields[$idx]);
}

doesn't work perfectly because the date_mod value exists twice and array_search returns only the first occurrence found.

So we need to check if date_mod alrady exist in $this->updates

To sum up, it is currently impossible to update only date_mod without causing a lock on this field (for dynamic item).

Set is_dynamic to false is not a good solution either, as it removes the link between the mainitem and related agent.

Screenshots (if appropriate):

@stonebuzz
Copy link
Contributor Author

I close i favor of -> https://github.com/glpi-project/glpi/pull/18120/files (I hadn't seen)

@stonebuzz stonebuzz closed this Oct 23, 2024
@ladenree76000
Copy link
Contributor

it looks fine, date_mod is no longer locked 👍

@stonebuzz
Copy link
Contributor Author

@ladenree76000

preferred #18120

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.

date_mod (core) field locked when asset is updated
2 participants