@@ -97,6 +97,80 @@ function plugin_addressing_install()
9797 if (!$ DB ->fieldExists ("glpi_plugin_addressing_addressings " , "vlans_id " )) {
9898 $ DB ->runFile (PLUGIN_ADDRESSING_DIR . "/sql/update-3.0.1.sql " );
9999 }
100+
101+ $ DB ->runFile (PLUGIN_ADDRESSING_DIR . "/sql/update-3.1.1.sql " );
102+ }
103+
104+ //DisplayPreferences Migration
105+ $ classes = ['PluginAddressingAddressing ' => Addressing::class];
106+
107+ foreach ($ classes as $ old => $ new ) {
108+ $ displayusers = $ DB ->request ([
109+ 'SELECT ' => [
110+ 'users_id '
111+ ],
112+ 'DISTINCT ' => true ,
113+ 'FROM ' => 'glpi_displaypreferences ' ,
114+ 'WHERE ' => [
115+ 'itemtype ' => $ old ,
116+ ],
117+ ]);
118+
119+ if (count ($ displayusers ) > 0 ) {
120+ foreach ($ displayusers as $ displayuser ) {
121+ $ iterator = $ DB ->request ([
122+ 'SELECT ' => [
123+ 'num ' ,
124+ 'id '
125+ ],
126+ 'FROM ' => 'glpi_displaypreferences ' ,
127+ 'WHERE ' => [
128+ 'itemtype ' => $ old ,
129+ 'users_id ' => $ displayuser ['users_id ' ],
130+ 'interface ' => 'central '
131+ ],
132+ ]);
133+
134+ if (count ($ iterator ) > 0 ) {
135+ foreach ($ iterator as $ data ) {
136+ $ iterator2 = $ DB ->request ([
137+ 'SELECT ' => [
138+ 'id '
139+ ],
140+ 'FROM ' => 'glpi_displaypreferences ' ,
141+ 'WHERE ' => [
142+ 'itemtype ' => $ new ,
143+ 'users_id ' => $ displayuser ['users_id ' ],
144+ 'num ' => $ data ['num ' ],
145+ 'interface ' => 'central '
146+ ],
147+ ]);
148+ if (count ($ iterator2 ) > 0 ) {
149+ foreach ($ iterator2 as $ dataid ) {
150+ $ query = $ DB ->buildDelete (
151+ 'glpi_displaypreferences ' ,
152+ [
153+ 'id ' => $ dataid ['id ' ],
154+ ]
155+ );
156+ $ DB ->doQuery ($ query );
157+ }
158+ } else {
159+ $ query = $ DB ->buildUpdate (
160+ 'glpi_displaypreferences ' ,
161+ [
162+ 'itemtype ' => $ new ,
163+ ],
164+ [
165+ 'id ' => $ data ['id ' ],
166+ ]
167+ );
168+ $ DB ->doQuery ($ query );
169+ }
170+ }
171+ }
172+ }
173+ }
100174 }
101175
102176 if ($ update ) {
@@ -129,29 +203,6 @@ function plugin_addressing_install()
129203 $ migration ->dropTable ('glpi_plugin_addressing_profiles ' );
130204 CronTask::Register (PingInfo::class, 'UpdatePing ' , DAY_TIMESTAMP );
131205
132- if (!$ DB ->request ([
133- 'FROM ' => 'glpi_displaypreferences ' ,
134- 'WHERE ' => [
135- 'itemtype ' => Addressing::class,
136- 'num ' => 2 ,
137- 'users_id ' => 0 ,
138- 'interface ' => 'central '
139- ]
140- ])->count ()) {
141- try {
142- $ DB ->insert ('glpi_displaypreferences ' , [
143- 'itemtype ' => Addressing::class,
144- 'num ' => 2 ,
145- 'rank ' => 2 ,
146- 'users_id ' => 0 ,
147- 'interface ' => 'central '
148- ]);
149- } catch (Throwable $ e ) {
150- Toolbox::logDebug ('Error when inserting into glpi_displaypreferences : ' . $ e ->getMessage ());
151- return false ;
152- }
153- }
154-
155206 return true ;
156207}
157208
0 commit comments