@@ -95,7 +95,11 @@ public static function getSpecificValueToDisplay($field, $values, array $options
9595 $ value = ' ' ;
9696 $ out = ' ' ;
9797 if (!str_contains ((string ) $ values ['id ' ], Search::NULLVALUE )) {
98- $ search_params = Search::manageParams ('Computer ' , unserialize ($ values ['search ' ]));
98+ $ search_params = Search::manageParams ('Computer ' ,
99+ json_decode ($ values ['search ' ], true , 512 , JSON_THROW_ON_ERROR )
100+ );
101+
102+
99103 $ data = Search::prepareDatasForSearch ('Computer ' , $ search_params );
100104 Search::constructSQL ($ data );
101105 Search::constructData ($ data );
@@ -160,7 +164,10 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
160164
161165 private function countDynamicItems ()
162166 {
163- $ search_params = Search::manageParams ('Computer ' , unserialize ($ this ->fields ['search ' ]));
167+ $ search_params = Search::manageParams ('Computer ' ,
168+ json_decode ($ this ->fields ['search ' ], true , 512 , JSON_THROW_ON_ERROR )
169+ );
170+
164171 $ data = Search::prepareDatasForSearch ('Computer ' , $ search_params );
165172 Search::constructSQL ($ data );
166173 Search::constructData ($ data );
@@ -171,7 +178,8 @@ private function countDynamicItems()
171178 public function isDynamicSearchMatchComputer (Computer $ computer )
172179 {
173180 // add new criteria to force computer ID
174- $ search = unserialize ($ this ->fields ['search ' ]);
181+ $ search = json_decode ($ this ->fields ['search ' ]);
182+
175183 $ search ['criteria ' ][] = [
176184 'link ' => 'AND ' ,
177185 'field ' => 2 , // computer ID
@@ -206,7 +214,10 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
206214 if ($ computergroup_dynamic ->getFromDBByCrit ([
207215 'plugin_databaseinventory_computergroups_id ' => $ ID ,
208216 ])) {
209- $ p = Search::manageParams ('Computer ' , unserialize ($ computergroup_dynamic ->fields ['search ' ]));
217+ $ p = Search::manageParams ('Computer ' ,
218+ json_decode ($ computergroup_dynamic ->fields ['search ' ], true , 512 , JSON_THROW_ON_ERROR )
219+ );
220+
210221 $ search_params = $ p ;
211222 $ firsttime = false ;
212223 } else {
@@ -283,6 +294,36 @@ public static function install(Migration $migration)
283294 ) ENGINE=InnoDB DEFAULT CHARSET= {$ default_charset } COLLATE= {$ default_collation } ROW_FORMAT=DYNAMIC;
284295SQL ;
285296 $ DB ->doQuery ($ query );
297+ } else {
298+
299+ // search field migration from serialized to json
300+ $ result = $ DB ->doQuery ("SELECT `id`, `search` FROM ` " . $ table . "` WHERE `search` NOT LIKE '{%' " );
301+
302+ while ($ data = $ DB ->fetchAssoc ($ result )) {
303+ $ id = $ data ['id ' ];
304+ $ search = $ data ['search ' ];
305+ $ json_search = json_encode ([]); // default value in case of error
306+
307+ try {
308+ $ unserialized = @unserialize ($ search , ['allowed_classes ' => false ]);
309+
310+ if ($ unserialized !== false ) {
311+ $ json_search = json_encode ($ unserialized , JSON_THROW_ON_ERROR );
312+ }
313+ } catch (Throwable $ e ) {
314+ $ migration ->displayMessage (
315+ "DatabaseInventory - Invalid serialized data for DynamicGroup ID {$ id }, data will be reset. "
316+ );
317+ continue ;
318+ }
319+
320+ $ DB ->update (
321+ $ table ,
322+ ['search ' => $ json_search ],
323+ ['id ' => $ id ]
324+ );
325+ }
326+
286327 }
287328 }
288329
0 commit comments