@@ -200,4 +200,45 @@ private static function getCustomFieldsInContainerTable(
200200 fn (string $ field ) => !in_array ($ field , $ basic_fields , true ),
201201 );
202202 }
203+
204+ public static function getGenericObjectTypes (): array
205+ {
206+ /** @var DBmysql $DB */
207+ global $ DB ;
208+
209+ // Check GenericObject version
210+ $ genericobject_info = Plugin::getInfo ('genericobject ' );
211+ if (version_compare ($ genericobject_info ['version ' ] ?? '0 ' , '3.0.0 ' , '< ' )) {
212+ throw new RuntimeException (
213+ 'GenericObject plugin cannot be migrated. Please update it to the latest version. ' ,
214+ );
215+ }
216+
217+ // Check glpi_plugin_genericobject_types table
218+ if (!$ DB ->fieldExists ('glpi_plugin_genericobject_types ' , 'itemtype ' )) {
219+ throw new RuntimeException (
220+ 'Integrity error on the glpi_plugin_genericobject_types table from the GenericObject plugin. ' ,
221+ );
222+ }
223+
224+ $ migration_genericobject_itemtype = [];
225+ $ result = $ DB ->request (['FROM ' => 'glpi_plugin_genericobject_types ' ]);
226+ foreach ($ result as $ type ) {
227+ $ customasset_classname = 'Glpi \\\\CustomAsset \\\\' . $ type ['name ' ] . 'Asset ' ;
228+ if (str_ends_with ((string ) $ type ['itemtype ' ], 'Model ' )) {
229+ $ customasset_classname = 'Glpi \\\\CustomAsset \\\\' . $ type ['name ' ] . 'AssetModel ' ;
230+ } elseif (str_ends_with ((string ) $ type ['itemtype ' ], 'Type ' )) {
231+ $ customasset_classname = 'Glpi \\\\CustomAsset \\\\' . $ type ['name ' ] . 'AssetType ' ;
232+ }
233+
234+ $ migration_genericobject_itemtype [$ type ['itemtype ' ]] = [
235+ 'genericobject_itemtype ' => $ type ['itemtype ' ],
236+ 'itemtype ' => $ customasset_classname ,
237+ 'genericobject_name ' => $ type ['name ' ],
238+ 'name ' => $ type ['name ' ] . 'Asset ' ,
239+ ];
240+ }
241+
242+ return $ migration_genericobject_itemtype ;
243+ }
203244}
0 commit comments