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 diff --git a/inc/type.class.php b/inc/type.class.php index edcba75..0c4f67d 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) { @@ -289,6 +309,16 @@ public static function deleteTable($itemtype) $preferences = new DisplayPreference(); $preferences->deleteByCriteria(["itemtype" => $itemtype]); $DB->dropTable(getTableForItemType($itemtype), 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); + } + } @@ -301,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); + } } /** @@ -660,6 +692,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 +707,9 @@ public static function uninstall() //Delete table $migration->dropTable('glpi_plugin_genericobject_types'); + + self::deleteFolder(GENERICOBJECT_DOC_DIR); + }