Skip to content

Fix incorrect declaration during order deletion#580

Open
stonebuzz wants to merge 2 commits into
mainfrom
fix_declaration
Open

Fix incorrect declaration during order deletion#580
stonebuzz wants to merge 2 commits into
mainfrom
fix_declaration

Conversation

@stonebuzz
Copy link
Copy Markdown
Contributor

@stonebuzz stonebuzz commented May 18, 2026

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.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

When deleting an order, GLPI was logging the following warnings:

Invalid relations declared between "glpi_plugin_order_orderpayments" and
"glpi_plugin_order_orders" table. Target field "plugin_order_orderpayments_id"
is not a foreign key field of "PluginOrderOrderpayment".

Three separate issues were identified:

1. Incorrect Parent/Child Relationship Direction

The previous relation declarations incorrectly defined glpi_plugin_order_orders as the parent table and the dropdown tables (orderpayments, ordertaxes, ordertypes, orderstates) as child tables.

Additionally, the relations referenced a non-existent field (plugin_order_orders_id) in these dropdown tables.

The correct relationship direction is the opposite:

  • Dropdown tables are the parent entities.

  • glpi_plugin_order_orders is the child table through foreign keys such as:

    • plugin_order_orderpayments_id
    • plugin_order_ordertaxes_id
    • plugin_order_ordertypes_id
    • plugin_order_orderstates_id

2. Case Mismatch During Initial Class Resolution

GLPI core method getItemTypeForTable() returns a lowercase-computed class name (PluginOrderOrderpayment) during the first resolution, then returns the correctly cached class name (PluginOrderOrderPayment) on subsequent calls.

Inside getDbRelations(), GLPI validates these values using a strict comparison (!==), which causes the validation to fail if the plugin classes have not yet been loaded at the time the method is executed.

As a result, relation validation failed during the initial lookup phase.


3. Missing glpi_ Table Prefix

The analyticnatures table was incorrectly declared as:

plugin_order_analyticnatures

instead of the correct table name:

glpi_plugin_order_analyticnatures

Solution

The issue was resolved through the following changes:

  • Refactored plugin_order_getDatabaseRelations() to declare all relations using the correct parent → child direction.

  • Added include_once statements for all inc/*.php files at the beginning of the function to ensure that all plugin classes are loaded before GLPI attempts class resolution, preventing case mismatch issues.

  • Corrected the table declaration:

    • plugin_order_analyticnatures
    • glpi_plugin_order_analyticnatures

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.

Error while permanently delete from orders in the trashbin

2 participants