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