Skip to content

feat(migration): add type renaming to resolve native asset name conflicts#472

Open
MyvTsv wants to merge 12 commits into
pluginsGLPI:mainfrom
MyvTsv:ticket42658
Open

feat(migration): add type renaming to resolve native asset name conflicts#472
MyvTsv wants to merge 12 commits into
pluginsGLPI:mainfrom
MyvTsv:ticket42658

Conversation

@MyvTsv

@MyvTsv MyvTsv commented Apr 17, 2026

Copy link
Copy Markdown
Contributor
  • 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

  • It fixes !42658
  • It is not possible to migrate an asset from the genericobject plugin if its name is similar to an asset in the GLPI core. This fix allows users to rename an asset so they can continue the migration.

Screenshots (if appropriate):

Conflict:
image

Migrate
image

@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz April 17, 2026 15:43
@MyvTsv MyvTsv self-assigned this Apr 17, 2026
@Rom1-B

Rom1-B commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Does this apply to names that are too long? And CLI ?

@stonebuzz

Copy link
Copy Markdown
Contributor

CLI compatibility would be a plus.

@stonebuzz

Copy link
Copy Markdown
Contributor

At the time of renaming, it should also be ensured that the total length (PluginGenericObject + New name) does not exceed the maximum allowed size for MySQL table names.

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

It works.
Could you add a check that alerts if the table name exceeds 64 characters?
In the CLI, add at least one check and a message to prompt renaming in the interface.

@MyvTsv MyvTsv requested review from Lainow and removed request for Lainow April 24, 2026 10:11

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

We also need to add the case where the Fields plugin adds fields

@MyvTsv MyvTsv requested a review from Rom1-B April 30, 2026 15:20
Comment thread inc/type.class.php Outdated
Comment thread inc/type.class.php Outdated
@MyvTsv MyvTsv requested a review from Rom1-B May 7, 2026 12:38
Comment thread templates/migration_status.html.twig Outdated
Comment thread inc/type.class.php Outdated
@MyvTsv MyvTsv requested a review from Rom1-B May 21, 2026 09:22
Comment thread inc/type.class.php Outdated
Comment thread inc/type.class.php Outdated
@MyvTsv MyvTsv requested a review from Rom1-B May 28, 2026 09:54
Comment thread templates/migration_status.html.twig
@MyvTsv MyvTsv requested a review from Rom1-B June 1, 2026 14:02
MyvTsv and others added 2 commits June 3, 2026 09:56
Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
@MyvTsv MyvTsv requested a review from Rom1-B June 3, 2026 11:52
@MyvTsv MyvTsv requested review from Lainow and Rom1-B July 2, 2026 08:44
@stonebuzz

Copy link
Copy Markdown
Contributor

@MyvTsv, could you please submit this fix for validation?

Comment thread inc/type.class.php
Comment on lines +1015 to +1016
ProfileRight::cleanAllPossibleRights();
$migration->executeMigration();

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.

ProfileRight::cleanAllPossibleRights() was called before $migration->executeMigration(), so the profile-right rename post-query (added inside updateNameAndItemtype() at line 1189) ran after the cleanup. cleanAllPossibleRights() removes the old right name (the renamed class no longer exists), and the subsequent UPDATE finds nothing to rename. Result: users lose their profile rights for any renamed type. Fixed by swapping the two lines.

Suggested change
ProfileRight::cleanAllPossibleRights();
$migration->executeMigration();
$migration->executeMigration();
ProfileRight::cleanAllPossibleRights();

Comment thread inc/type.class.php
if ($DB->fieldExists($table_name, $fkey_newname)) {
throw new RuntimeException(
sprintf(
'Field "%s" cannot be renamed in table "%s" as "%s" is field already exists.',

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
'Field "%s" cannot be renamed in table "%s" as "%s" is field already exists.',
'Field "%s" cannot be renamed in table "%s": field "%s" already exists.',

Comment thread inc/type.class.php
Comment on lines +1301 to +1305
if (str_contains($table_name, strtolower($old_itemtype))) {
$new_table_name = str_replace(strtolower($old_itemtype), strtolower($new_itemtype), $table_name);
$migration->renameTable($table_name, $new_table_name);
$table_name = $new_table_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.

str_contains($table_name, strtolower($old_itemtype)) never matches standard GLPI plugin table names: GLPI converts PluginGenericobjectCar to glpi_plugin_genericobject_cars (snake_case), so the string "plugingenericobjectcar" does not appear in any standard table name. The table-rename branch is dead code; only the itemtypes JSON-field UPDATE (lines 1312-1330) does real work.

</div>
<small id="{{ modal_id }}-counter"
class="text-muted flex-shrink-0">
{{ genericobject_type.name|length }}/{{ constant('PluginGenericobjectType::MAX_TYPE_NAME_LENGTH') }}

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
{{ genericobject_type.name|length }}/{{ constant('PluginGenericobjectType::MAX_TYPE_NAME_LENGTH') }}
{{ call('PluginGenericobjectType::getSystemName', [genericobject_type.name])|length }}/{{ constant('PluginGenericobjectType::MAX_TYPE_NAME_LENGTH') }}

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.

4 participants