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

Duplicate Inventory Items and Deleted Templates #6

Open
mgurm opened this issue Nov 25, 2015 · 0 comments
Open

Duplicate Inventory Items and Deleted Templates #6

mgurm opened this issue Nov 25, 2015 · 0 comments

Comments

@mgurm
Copy link

mgurm commented Nov 25, 2015

Hello

We ran into a strange bug concerning the preItemAdd hook in the geninventory plugin, so I thought I'd post it here.

We add new items into GLPI using the template feature (this means the insert form URL looks like /front/computer.form.php?id=123&withtemplate=2). Now when inventory number generation is deactivated for the item type that is inserted, the function preItemAdd performs an update on a DB entry before the insert. This happens in the else clause of the following code part:

     if (PluginGeninventorynumberConfig::isGenerationActive()
        && PluginGeninventorynumberConfigField::isActiveForItemType(get_class($item))) {
          // ...
     } else {
            $values['otherserial'] = '';
            $values['id']          = $item->getID();
            $tmp->update($values);
     }

However, this update uses the ID of the template, not the ID of the new item (which, as far as I understand, is not yet in the database at this point). The problem with this is that it sets is_template to false. This means that the template is transformed into a normal item. So in the end, I have two new items instead of one. And, of course, the template is gone.

I was able to fix this by removing the update call in the else clause, but I don't know if that is a good fix. I am not sure why this update is needed in the first place (maybe someone can explain it to me?).

Regards,
mgurm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant