From a944cf43ba3e4617594e7e56b240829ae436a374 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 19 Nov 2025 15:20:37 +0100 Subject: [PATCH 1/5] Fix(core): secure / fix / enhanced uninstall process --- inc/type.class.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/inc/type.class.php b/inc/type.class.php index edcba75..546247c 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -111,6 +111,26 @@ public static function deleteFile($filename) } } + public static function deleteFolder(string $folder) + { + if (!is_dir($folder)) { + return; + } + + $it = new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + foreach ($files as $file) { + if ($file->isDir()) { + rmdir($file->getRealPath()); + } else { + unlink($file->getRealPath()); + } + } + + rmdir($folder); + } + public static function getCompleteClassFilename($name) { @@ -660,6 +680,13 @@ public static function uninstall() self::deleteItemtypeReferencesInGLPI(self::class); foreach ($DB->request(['FROM' => 'glpi_plugin_genericobject_types']) as $type) { + + // GLPI 11 migration may change plugin itemtype from glpi_plugin_genericobject_types table during CustomAsset migration + // rely on original name to get correct itemtype + if (str_starts_with($type['itemtype'], 'Glpi\\CustomAsset\\')) { + $type['itemtype'] = self::getClassByName($type['name']); + } + //Delete references to PluginGenericobjectType in the following tables self::deleteItemtypeReferencesInGLPI($type['itemtype']); //Dropd files and classes @@ -668,6 +695,9 @@ public static function uninstall() //Delete table $migration->dropTable('glpi_plugin_genericobject_types'); + + self::deleteFolder(GENERICOBJECT_DOC_DIR); + } From 0949e29356416693fc79adc790b7840fcac9e7f1 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 19 Nov 2025 15:25:26 +0100 Subject: [PATCH 2/5] delete table for Model and Type --- inc/type.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/type.class.php b/inc/type.class.php index 546247c..e48553d 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -309,6 +309,8 @@ public static function deleteTable($itemtype) $preferences = new DisplayPreference(); $preferences->deleteByCriteria(["itemtype" => $itemtype]); $DB->dropTable(getTableForItemType($itemtype), true); + $DB->dropTable(getTableForItemType($itemtype . "Model"), true); + $DB->dropTable(getTableForItemType($itemtype . "Type"), true); } From 78d411c4106539e978d38c266a59a549302404fc Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 19 Nov 2025 15:38:40 +0100 Subject: [PATCH 3/5] fix MySQL query error: Identifier name is too long --- inc/type.class.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/inc/type.class.php b/inc/type.class.php index e48553d..585ba93 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -309,8 +309,16 @@ public static function deleteTable($itemtype) $preferences = new DisplayPreference(); $preferences->deleteByCriteria(["itemtype" => $itemtype]); $DB->dropTable(getTableForItemType($itemtype), true); - $DB->dropTable(getTableForItemType($itemtype . "Model"), true); - $DB->dropTable(getTableForItemType($itemtype . "Type"), true); + + + if (strlen(getTableForItemType($itemtype) . "Model") <= 64) { + $DB->dropTable(getTableForItemType($itemtype . "Model"), true); + } + + if (strlen(getTableForItemType($itemtype) . "Type") <= 64) { + $DB->dropTable(getTableForItemType($itemtype . "Type"), true); + } + } @@ -323,7 +331,9 @@ public static function deleteItemsTable($itemtype) { /** @var DBmysql $DB */ global $DB; - $DB->dropTable(getTableForItemType($itemtype) . "_items", true); + if (strlen(getTableForItemType($itemtype) . "_items") <= 64) { + $DB->dropTable(getTableForItemType($itemtype) . "_items", true); + } } /** From d6e9a09794e8eed8ebcd775a9cd9435c6aae85f0 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 19 Nov 2025 15:39:24 +0100 Subject: [PATCH 4/5] adapt changelog.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e802ff3..162caf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +- Uninstall process + ## [3.0.1 End-of-Life Updater] - 2025-11-13 - Fix Twig error on migration_status page From d35ee3efee6121f67df32f56ac3cae95fe889466 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Wed, 19 Nov 2025 15:53:41 +0100 Subject: [PATCH 5/5] fix CS --- inc/type.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/type.class.php b/inc/type.class.php index 585ba93..0c4f67d 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -696,7 +696,7 @@ public static function uninstall() // GLPI 11 migration may change plugin itemtype from glpi_plugin_genericobject_types table during CustomAsset migration // rely on original name to get correct itemtype if (str_starts_with($type['itemtype'], 'Glpi\\CustomAsset\\')) { - $type['itemtype'] = self::getClassByName($type['name']); + $type['itemtype'] = self::getClassByName($type['name']); } //Delete references to PluginGenericobjectType in the following tables