Skip to content

fix(migration): table rename exceeds table name length limit#1217

Open
MyvTsv wants to merge 6 commits into
pluginsGLPI:mainfrom
MyvTsv:ticket45001
Open

fix(migration): table rename exceeds table name length limit#1217
MyvTsv wants to merge 6 commits into
pluginsGLPI:mainfrom
MyvTsv:ticket45001

Conversation

@MyvTsv

@MyvTsv MyvTsv commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

  • It fixes !45001
  • The migration of the "fields" plugin did not work if the container name was too long

Screenshots (if appropriate):

[2026-07-01 09:16:09] glpi.CRITICAL:   *** Uncaught PHP Exception RuntimeException: "MySQL query error: Incorrect table name 'glpi_plugin_fields_glpicustomassetvideoprojecteurassetfivesixnineeighttwosevensixzerosixes' (1103) in SQL query "CREATE TABLE IF NOT EXISTS `glpi_plugin_fields_glpicustomassetvideoprojecteurassetfivesixnineeighttwosevensixzerosixes` (
                  `id`                               INT          unsigned NOT NULL auto_increment,
                  `items_id`                         INT          unsigned NOT NULL,
                  `itemtype`                         VARCHAR(255) DEFAULT 'Glpi\\CustomAsset\\videoprojecteurAsset',
                  `plugin_fields_containers_id`      INT          unsigned NOT NULL DEFAULT 1,
                  PRIMARY KEY                        (`id`),
                  UNIQUE INDEX `itemtype_item_container`
                     (`itemtype`, `items_id`, `plugin_fields_containers_id`)
               ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;"." at DBmysql.php line 416
  Backtrace :
  ./src/DBmysql.php:416                              
  ...fivesixnineeighttwosevensixzerosix.class.php:31 DBmysql->doQuery()
  ./plugins/fields/inc/container.class.php:764       PluginFieldsGlpicustomassetvideoprojecteurassetfivesixnineeighttwosevensixzerosix::install()
  ./plugins/fields/inc/container.class.php:476       PluginFieldsContainer::create()
  ./plugins/fields/hook.php:90                       PluginFieldsContainer::installUserData()
  ./src/Plugin.php:1249                              plugin_fields_install()
  :                                                  Plugin->install()
  ./src/Glpi/Marketplace/Controller.php:710          call_user_func()
  ./src/Glpi/Marketplace/Controller.php:600          Glpi\Marketplace\Controller->setPluginState()
  ./ajax/marketplace.php:62                          Glpi\Marketplace\Controller->installPlugin()
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

@MyvTsv MyvTsv self-assigned this Jul 1, 2026
@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz July 1, 2026 13:34
@MyvTsv MyvTsv marked this pull request as ready for review July 1, 2026 13:35

@Rom1-B Rom1-B 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.

Please rebase

Comment thread inc/container.class.php
}

$container['name'] = $new_name;
$container['label'] = $new_name;

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.

Suggested change
$container['label'] = $new_name;

setContainerName overwrites the human-readable label with the truncated system name. After migration, affected containers would display the internal machine name (e.g. verylongcontainernamef) instead of the original descriptive label. Only name needs to be truncated; label should remain the original value.

Comment thread inc/container.class.php
}

$container = $container_obj->setContainerName($container);
$container_obj->update($container);

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.

Suggested change
$container_obj->update($container);
return $container_obj->update($container);

return if update process failed or not

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.

If setContainerName produces an empty name (edge case where even a 1-char system name yields a table name exceeding 64 chars) or if prepareInputForUpdate rejects the input, the update silently fails and the migration returns true.

Comment thread inc/toolbox.class.php

if (!PluginFieldsContainer::checkContainerName($input)) {
Session::addMessageAfterRedirect(
__('Container name is too long for database', 'fields'),

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.

Suggested change
__('Container name is too long for database', 'fields'),
__('Container name is invalid or too long for database', 'fields'),

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.

3 participants