@@ -83,6 +83,78 @@ function plugin_connections_install()
8383 }
8484 $ DB ->runFile (PLUGINCONNECTIONS_DIR . "/sql/update-11.0.0.sql " );
8585
86+ //DisplayPreferences Migration
87+ $ classes = ['PluginConnectionsConnection ' => Connection::class];
88+
89+ foreach ($ classes as $ old => $ new ) {
90+ $ displayusers = $ DB ->request ([
91+ 'SELECT ' => [
92+ 'users_id '
93+ ],
94+ 'DISTINCT ' => true ,
95+ 'FROM ' => 'glpi_displaypreferences ' ,
96+ 'WHERE ' => [
97+ 'itemtype ' => $ old ,
98+ ],
99+ ]);
100+
101+ if (count ($ displayusers ) > 0 ) {
102+ foreach ($ displayusers as $ displayuser ) {
103+ $ iterator = $ DB ->request ([
104+ 'SELECT ' => [
105+ 'num ' ,
106+ 'id '
107+ ],
108+ 'FROM ' => 'glpi_displaypreferences ' ,
109+ 'WHERE ' => [
110+ 'itemtype ' => $ old ,
111+ 'users_id ' => $ displayuser ['users_id ' ],
112+ 'interface ' => 'central '
113+ ],
114+ ]);
115+
116+ if (count ($ iterator ) > 0 ) {
117+ foreach ($ iterator as $ data ) {
118+ $ iterator2 = $ DB ->request ([
119+ 'SELECT ' => [
120+ 'id '
121+ ],
122+ 'FROM ' => 'glpi_displaypreferences ' ,
123+ 'WHERE ' => [
124+ 'itemtype ' => $ new ,
125+ 'users_id ' => $ displayuser ['users_id ' ],
126+ 'num ' => $ data ['num ' ],
127+ 'interface ' => 'central '
128+ ],
129+ ]);
130+ if (count ($ iterator2 ) > 0 ) {
131+ foreach ($ iterator2 as $ dataid ) {
132+ $ query = $ DB ->buildDelete (
133+ 'glpi_displaypreferences ' ,
134+ [
135+ 'id ' => $ dataid ['id ' ],
136+ ]
137+ );
138+ $ DB ->doQuery ($ query );
139+ }
140+ } else {
141+ $ query = $ DB ->buildUpdate (
142+ 'glpi_displaypreferences ' ,
143+ [
144+ 'itemtype ' => $ new ,
145+ ],
146+ [
147+ 'id ' => $ data ['id ' ],
148+ ]
149+ );
150+ $ DB ->doQuery ($ query );
151+ }
152+ }
153+ }
154+ }
155+ }
156+ }
157+
86158 if ($ update ) {
87159 $ iterator = $ DB ->request ([
88160 'SELECT ' => [
@@ -378,7 +450,7 @@ function plugin_connections_addLeftJoin($type, $ref_table, $new_table, $linkfiel
378450 ],
379451 ],
380452 ];
381- $ out ['LEFT JOIN ' ] = array_merge ($ out , $ left );
453+ $ out ['LEFT JOIN ' ] = array_merge ($ out[ ' LEFT JOIN ' ] , $ left );
382454 return $ out ;
383455
384456 case "glpi_plugin_connections_connectionrates " :
@@ -397,7 +469,7 @@ function plugin_connections_addLeftJoin($type, $ref_table, $new_table, $linkfiel
397469 ],
398470 ],
399471 ];
400- $ out ['LEFT JOIN ' ] = array_merge ($ out , $ left );
472+ $ out ['LEFT JOIN ' ] = array_merge ($ out[ ' LEFT JOIN ' ] , $ left );
401473 return $ out ;
402474
403475 case "glpi_plugin_connections_guaranteedconnectionrates " :
@@ -416,7 +488,7 @@ function plugin_connections_addLeftJoin($type, $ref_table, $new_table, $linkfiel
416488 ],
417489 ],
418490 ];
419- $ out ['LEFT JOIN ' ] = array_merge ($ out , $ left );
491+ $ out ['LEFT JOIN ' ] = array_merge ($ out[ ' LEFT JOIN ' ] , $ left );
420492 return $ out ;
421493 }
422494
0 commit comments