Skip to content

Commit f44e47b

Browse files
committed
Add display preferences migration
Bump version
1 parent 59a4ca5 commit f44e47b

3 files changed

Lines changed: 81 additions & 4 deletions

File tree

connections.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<author>Jérémy Moreau</author>
2727
</authors>
2828
<versions>
29+
<version>
30+
<num>11.0.2</num>
31+
<compatibility>~11.0</compatibility>
32+
<download_url>https://github.com/pluginsGLPI/connections/releases/download/11.0.2/glpi-connections-11.0.2.tar.bz2</download_url>
33+
</version>
2934
<version>
3035
<num>11.0.1</num>
3136
<compatibility>~11.0</compatibility>

hook.php

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
use GlpiPlugin\Connections\Connection_Item;
3535
use GlpiPlugin\Connections\Profile;
3636

37-
define('PLUGIN_CONNECTIONS_VERSION', '11.0.1');
37+
define('PLUGIN_CONNECTIONS_VERSION', '11.0.2');
3838

3939
global $CFG_GLPI;
4040

0 commit comments

Comments
 (0)