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

Add command to fix incorrectly deleted fields from containers tables #525

Conversation

AdrienClairembault
Copy link
Contributor

@AdrienClairembault AdrienClairembault commented Jun 1, 2022

Internal ref: !24075.

EDITED after #526 (see comments)

An issue affected field removal in 1.15.0, 1.15.1 and 1.15.2.
Using these versions, removing a field from a container would drop the field from glpi_plugin_fields_fields but not from the custom container table.

This command remove these incorrectly deleted fields.

Command examples:
image

Unrelated changes kept from the previous iteration:

  • Add PluginFieldsContainerTemplate base class for custom containers classes in order to reduce the generated php classes for each containers.

The main advantage is that you can edit the generic code directly from PluginFieldsContainerTemplate and it will impact all custom container classes without having to "regenerate" the PHP files of these custom classes.

@AdrienClairembault AdrienClairembault added this to the 1.15.3 milestone Jun 1, 2022
@cedric-anne
Copy link
Contributor

Even if such a solution would work, I think it would be better to delete data from DB when field/dropdown is deleted, for instance in PluginFieldsField::pre_deleteItem() and in PluginFieldsDropdown::destroy().
For existing data, cleaning could be handled in migration.

@AdrienClairembault
Copy link
Contributor Author

Looking at PluginFieldsField::pre_deleteItem(), not deleting the fields seems to be done on purpose (the code to delete is there but only run on very specific conditions).

@cedric-anne
Copy link
Contributor

It seems it was only done to improve performances (see 5d087e1). IMHO, not deleting data from DB when deleting a field is a problem and should be fixed.

@cedric-anne
Copy link
Contributor

Values were cleaned in old plugin db schema, and this clean has not been adapted to new schema, see 455c2c2.

@cedric-anne
Copy link
Contributor

Maybe the deletion chain should be reviewed.

  • Container child should be deleted in cleanDBonPurge() method of container.
  • Container/Dropdown files should be deleted in post_deleteFromDB() method of corresponding item.

@AdrienClairembault
Copy link
Contributor Author

AdrienClairembault commented Jun 1, 2022

Actually, after re-reading the code I've found that deletion was just broken since 1.15.0.

removeField was called with the wrong parameters since 954864b#diff-8fd65f1eb4cf4f2c2b956a535e6de83c36b63bfabfd1a3c9131b99a39e47b9a7L219 (it's supposed to be name first, type second).

@AdrienClairembault
Copy link
Contributor Author

I'm not sure about a migration to remove the missing fields... any mistake which would delete legitimate fields would have a huge impact.

@cedric-anne cedric-anne removed this from the 1.15.3 milestone Jun 1, 2022
@AdrienClairembault AdrienClairembault changed the title Remove deleted fields from API results Add command to fix incorrectly deleted fields from containers tables Jun 2, 2022
// header type is for read-only display purpose only and has no SQL field
break;
case $field_type === 'dropdown':
case preg_match('/^dropdown-.+/i', $field_type):
Copy link
Contributor

Choose a reason for hiding this comment

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

case preg_match('/^dropdown-.+/i', $field_type): was a legitimate case and should be preserved.

Diff is huge here, and it is hard to validate the code. Unless I am wrong, if #528 is merged, only the new command and corresponding PluginFieldsMigration methods are required.

I would prefer serarate PR for PSR-12 migration and for migration of PHP template files to abstract classes (should be done globally). We could work on these later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, let's merge #528 and then I'll open separate PR for each topics.

PS: for the huge diff, it's mostly whitespaces and you can ignore them:
image

@AdrienClairembault
Copy link
Contributor Author

Replaced by #532.

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

Successfully merging this pull request may close these issues.

2 participants