Skip to content

handle mediumtext type used in comments#433

Merged
trasher merged 1 commit into
pluginsGLPI:mainfrom
flonou:fix-comments-display
May 12, 2025
Merged

handle mediumtext type used in comments#433
trasher merged 1 commit into
pluginsGLPI:mainfrom
flonou:fix-comments-display

Conversation

@flonou

@flonou flonou commented May 5, 2025

Copy link
Copy Markdown
Contributor

Comments are not correctly displayed in generic objects:

  • Comments use mediumtext type
  • Add 'form-control' class to get the correct style for comments

Checklist before requesting a review

Please delete options that are not relevant.

  • [x ] 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

Screenshots (if appropriate):

without fix:
image
with fix:
image

Comments use mediumtext type
Add 'form-control' class to get the correct style for comments
@stonebuzz stonebuzz requested review from Rom1-B and stonebuzz May 6, 2025 07:02

@stonebuzz stonebuzz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GLPI currently does not support using the MEDIUMTEXT type—it is automatically normalized to TEXT.
We normalize all MEDIUMTEXT and LONGTEXT fields to TEXT by design.

Unless, of course, you haven't migrated your database to use_utf8mb4.

@flonou

flonou commented May 7, 2025

Copy link
Copy Markdown
Contributor Author

Hi, do you mean there must be something wrong in my GLPI configuration to need that change ?

@stonebuzz

Copy link
Copy Markdown
Contributor

Have you a message on central page for "use_utf8mb4" ?

@flonou

flonou commented May 7, 2025

Copy link
Copy Markdown
Contributor Author

I do not see use_utf8mb4 on the central page, even with debug activated

@flonou

flonou commented May 7, 2025

Copy link
Copy Markdown
Contributor Author

I've tried to check and it seems all my glpi columns are using utf8mb4 and a lot of them are indeed MEDIUMTEXT.

+--------------+-----------------------------------------------+------------------+-------------------------------+---------------+--------------------+
| TABLE_SCHEMA | TABLE_NAME                                    | DEFAULT_CHAR_SET | COLUMN_NAME                   | COLUMN_TYPE   | CHARACTER_SET_NAME |
+--------------+-----------------------------------------------+------------------+-------------------------------+---------------+--------------------+
| glpidb       | glpi_agents                                   | utf8mb4          | deviceid                      | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | itemtype                      | varchar(100)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | port                          | varchar(6)    | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | remote_addr                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | tag                           | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | useragent                     | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agents                                   | utf8mb4          | version                       | varchar(255)  | utf8mb4            |
| glpidb       | glpi_agenttypes                               | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_alerts                                   | utf8mb4          | itemtype                      | varchar(100)  | utf8mb4            |
| glpidb       | glpi_apiclients                               | utf8mb4          | app_token                     | varchar(255)  | utf8mb4            |
| glpidb       | glpi_apiclients                               | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_apiclients                               | utf8mb4          | ipv6                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_apiclients                               | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_applianceenvironments                    | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_applianceenvironments                    | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | contact                       | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | contact_num                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | externalidentifier            | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | otherserial                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | pictures                      | mediumtext    | utf8mb4            |
| glpidb       | glpi_appliances                               | utf8mb4          | serial                        | varchar(255)  | utf8mb4            |
| glpidb       | glpi_appliances_items                         | utf8mb4          | itemtype                      | varchar(100)  | utf8mb4            |
| glpidb       | glpi_appliances_items_relations               | utf8mb4          | itemtype                      | varchar(100)  | utf8mb4            |
| glpidb       | glpi_appliancetypes                           | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
...

config_db.php does have public $use_utf8mb4 = true;

This PR basically adds MEDIUMTEXT type handling next to TEXT and LONGTEXT. I would guess if LONGTEXT is handled, then MEDIUMTEXT should be handled too from what I understand ? (or both should not be handled at all)

@stonebuzz

stonebuzz commented May 9, 2025

Copy link
Copy Markdown
Contributor

The plugin does not allow the addition of fields with the "mediumtext" data type.
Could you confirm whether any of the glpi_plugin_genericobject tables currently contain columns of type mediumtext?

@stonebuzz

Copy link
Copy Markdown
Contributor

Default comment field have TEXT datatype

Have you added your own comment field?

@flonou

flonou commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

The plugin does not allow the addition of fields with the "mediumtext" data type. Could you confirm whether any of the glpi_plugin_genericobject tables currently contain columns of type mediumtext?

I can confirm :


| glpidb       | glpi_plugin_genericobject_accessoriemodels    | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessoriemodels    | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessories         | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessories         | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessories         | utf8mb4          | otherserial                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessories         | utf8mb4          | serial                        | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessories         | utf8mb4          | template_name                 | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessorietypes     | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_accessorietypes     | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiermodels     | utf8mb4          | comment                       | text          | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiermodels     | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiers          | utf8mb4          | comment                       | text          | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiers          | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiers          | utf8mb4          | otherserial                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiers          | utf8mb4          | serial                        | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_amplifiers          | utf8mb4          | template_name                 | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audiomodels         | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audiomodels         | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audios              | utf8mb4          | comment                       | mediumtext    | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audios              | utf8mb4          | name                          | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audios              | utf8mb4          | otherserial                   | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audios              | utf8mb4          | serial                        | varchar(255)  | utf8mb4            |
| glpidb       | glpi_plugin_genericobject_audios              | utf8mb4          | template_name                 | varchar(255)  | utf8mb4            |

@flonou

flonou commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

Default comment field have TEXT datatype

Have you added your own comment field?

No, the only additional field (using the additional field plugin) I have is about storage location.

Sound like something went a bit wrong in my database over the years. Should the solution be to change the column types to "text" instead of "mediumtext" ?

I'm wondering why largetext is present in the plugin however, is that supposed to happen too ?

@stonebuzz

Copy link
Copy Markdown
Contributor

Should the solution be to change the column types to "text" instead of "mediumtext" ?

Yes, the plugin currently uses the TEXT type for the “comment” column

@trasher

trasher commented May 12, 2025

Copy link
Copy Markdown
Contributor

It's always difficult to know how this kind of issue comes... It may depends on which db (maria/mysql) or version used.

Anyway - even if this should not happen - I guess the proposed patch could be accepted; since it does not seem it can really break anything. @stonebuzz your opinion?

Also, now you know your database is incorrect, you should also consider fixing it ;)

@stonebuzz

Copy link
Copy Markdown
Contributor

I guess the proposed patch could be accepted

I agree with that as well. The scope is indeed quite limited.

@flonou

flonou commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

I will fix my DB then and try to investigate from the backups I have if I can find a culprit.

@stonebuzz stonebuzz self-requested a review May 12, 2025 13:22
@trasher trasher merged commit 564f564 into pluginsGLPI:main May 12, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

Comments do not display as they should

3 participants