Skip to content

Commit 22beb1a

Browse files
committed
Add display preferences migration
Bump version
1 parent d15816b commit 22beb1a

File tree

4 files changed

+81
-24
lines changed

4 files changed

+81
-24
lines changed

addressing.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<author>Nelly Mahu-Lasson</author>
2828
</authors>
2929
<versions>
30+
<version>
31+
<num>3.1.1</num>
32+
<compatibility>~11.0</compatibility>
33+
<download_url>https://github.com/pluginsGLPI/addressing/releases/download/3.1.1/glpi-addressing-3.1.1.tar.bz2</download_url>
34+
</version>
3035
<version>
3136
<num>3.1.0</num>
3237
<compatibility>~11.0</compatibility>

hook.php

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

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use GlpiPlugin\Addressing\PingInfo;
3434
use GlpiPlugin\Addressing\Profile;
3535

36-
define('PLUGIN_ADDRESSING_VERSION', '3.1.0');
36+
define('PLUGIN_ADDRESSING_VERSION', '3.1.1');
3737

3838
if (!defined("PLUGIN_ADDRESSING_DIR")) {
3939
define("PLUGIN_ADDRESSING_DIR", Plugin::getPhpDir("addressing"));

sql/update-3.1.1.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETE FROM `glpi_crontasks` WHERE `itemtype` LIKE 'PluginAddressing%';

0 commit comments

Comments
 (0)