Skip to content

Commit 1083f93

Browse files
authored
Fix uninstall (#462)
* Fix(core): secure / fix / enhanced uninstall process * delete table for Model and Type * fix MySQL query error: Identifier name is too long * adapt changelog.md * fix CS
1 parent 144a396 commit 1083f93

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [UNRELEASED]
9+
10+
- Uninstall process
11+
812
## [3.0.1 End-of-Life Updater] - 2025-11-13
913

1014
- Fix Twig error on migration_status page

inc/type.class.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ public static function deleteFile($filename)
111111
}
112112
}
113113

114+
public static function deleteFolder(string $folder)
115+
{
116+
if (!is_dir($folder)) {
117+
return;
118+
}
119+
120+
$it = new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS);
121+
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
122+
123+
foreach ($files as $file) {
124+
if ($file->isDir()) {
125+
rmdir($file->getRealPath());
126+
} else {
127+
unlink($file->getRealPath());
128+
}
129+
}
130+
131+
rmdir($folder);
132+
}
133+
114134

115135
public static function getCompleteClassFilename($name)
116136
{
@@ -289,6 +309,16 @@ public static function deleteTable($itemtype)
289309
$preferences = new DisplayPreference();
290310
$preferences->deleteByCriteria(["itemtype" => $itemtype]);
291311
$DB->dropTable(getTableForItemType($itemtype), true);
312+
313+
314+
if (strlen(getTableForItemType($itemtype) . "Model") <= 64) {
315+
$DB->dropTable(getTableForItemType($itemtype . "Model"), true);
316+
}
317+
318+
if (strlen(getTableForItemType($itemtype) . "Type") <= 64) {
319+
$DB->dropTable(getTableForItemType($itemtype . "Type"), true);
320+
}
321+
292322
}
293323

294324

@@ -301,7 +331,9 @@ public static function deleteItemsTable($itemtype)
301331
{
302332
/** @var DBmysql $DB */
303333
global $DB;
304-
$DB->dropTable(getTableForItemType($itemtype) . "_items", true);
334+
if (strlen(getTableForItemType($itemtype) . "_items") <= 64) {
335+
$DB->dropTable(getTableForItemType($itemtype) . "_items", true);
336+
}
305337
}
306338

307339
/**
@@ -660,6 +692,13 @@ public static function uninstall()
660692
self::deleteItemtypeReferencesInGLPI(self::class);
661693

662694
foreach ($DB->request(['FROM' => 'glpi_plugin_genericobject_types']) as $type) {
695+
696+
// GLPI 11 migration may change plugin itemtype from glpi_plugin_genericobject_types table during CustomAsset migration
697+
// rely on original name to get correct itemtype
698+
if (str_starts_with($type['itemtype'], 'Glpi\\CustomAsset\\')) {
699+
$type['itemtype'] = self::getClassByName($type['name']);
700+
}
701+
663702
//Delete references to PluginGenericobjectType in the following tables
664703
self::deleteItemtypeReferencesInGLPI($type['itemtype']);
665704
//Dropd files and classes
@@ -668,6 +707,9 @@ public static function uninstall()
668707

669708
//Delete table
670709
$migration->dropTable('glpi_plugin_genericobject_types');
710+
711+
self::deleteFolder(GENERICOBJECT_DOC_DIR);
712+
671713
}
672714

673715

0 commit comments

Comments
 (0)