2929
3030use Glpi\Plugin\Hooks;
3131use GlpiPlugin\Addressing\Addressing;
32+ use GlpiPlugin\Addressing\AddressingInjection;
3233use GlpiPlugin\Addressing\Filter;
3334use GlpiPlugin\Addressing\PingInfo;
3435use GlpiPlugin\Addressing\Profile;
@@ -174,6 +175,78 @@ function plugin_addressing_install()
174175 }
175176 }
176177
178+ // Version 3.2.2 - Migration des IDs de recherche 1000/1001 vers 100/101
179+ $num_mapping = [1000 => 100, 1001 => 101];
180+
181+ $has_old_prefs = $DB->request([
182+ 'COUNT' => 'cpt',
183+ 'FROM' => 'glpi_displaypreferences',
184+ 'WHERE' => [
185+ 'itemtype' => Addressing::class,
186+ 'num' => array_keys($num_mapping),
187+ ],
188+ ])->current()['cpt'] > 0;
189+
190+ if ($has_old_prefs) {
191+ foreach ($num_mapping as $old_num => $new_num) {
192+ $conflicts = $DB->request([
193+ 'SELECT' => ['users_id', 'interface'],
194+ 'FROM' => 'glpi_displaypreferences',
195+ 'WHERE' => [
196+ 'itemtype' => Addressing::class,
197+ 'num' => $new_num,
198+ ],
199+ ]);
200+
201+ foreach ($conflicts as $conflict) {
202+ $DB->delete('glpi_displaypreferences', [
203+ 'itemtype' => Addressing::class,
204+ 'num' => $old_num,
205+ 'users_id' => $conflict['users_id'],
206+ 'interface' => $conflict['interface'],
207+ ]);
208+ }
209+
210+ $DB->update('glpi_displaypreferences', ['num' => $new_num], [
211+ 'itemtype' => Addressing::class,
212+ 'num' => $old_num,
213+ ]);
214+ }
215+
216+ $saved_searches = $DB->request([
217+ 'FROM' => 'glpi_savedsearches',
218+ 'WHERE' => ['itemtype' => Addressing::class],
219+ ]);
220+
221+ foreach ($saved_searches as $saved_search) {
222+ parse_str($saved_search['query'], $params);
223+ $modified = false;
224+
225+ if (isset($params['criteria']) && is_array($params['criteria'])) {
226+ foreach ($params['criteria'] as &$criterion) {
227+ if (isset($criterion['field']) && isset($num_mapping[(int) $criterion['field']])) {
228+ $criterion['field'] = (string) $num_mapping[(int) $criterion['field']];
229+ $modified = true;
230+ }
231+ }
232+ unset($criterion);
233+ }
234+
235+ if (isset($params['sort']) && isset($num_mapping[(int) $params['sort']])) {
236+ $params['sort'] = (string) $num_mapping[(int) $params['sort']];
237+ $modified = true;
238+ }
239+
240+ if ($modified) {
241+ $DB->update('glpi_savedsearches', [
242+ 'query' => http_build_query($params),
243+ ], [
244+ 'id' => $saved_search['id'],
245+ ]);
246+ }
247+ }
248+ }
249+
177250 if ($update) {
178251 $query_ = "SELECT *
179252 FROM `glpi_plugin_addressing_profiles` ";
@@ -200,7 +273,7 @@ function plugin_addressing_install()
200273 //Add all rights for current user profile
201274 Profile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
202275 //Drop old profile table : not used anymore
203- $migration = new Migration("2.5.0" );
276+ $migration = new Migration(PLUGIN_ADDRESSING_VERSION );
204277 $migration->dropTable('glpi_plugin_addressing_profiles');
205278 CronTask::Register(PingInfo::class, 'UpdatePing', DAY_TIMESTAMP);
206279
@@ -215,7 +288,7 @@ function plugin_addressing_uninstall()
215288{
216289 global $DB;
217290
218- $migration = new Migration("2.5.0" );
291+ $migration = new Migration(PLUGIN_ADDRESSING_VERSION );
219292 $tables = ["glpi_plugin_addressing_addressings",
220293 "glpi_plugin_addressing_configs",
221294 "glpi_plugin_addressing_filters",
@@ -388,7 +461,7 @@ function plugin_addressing_dynamicReport($params)
388461function plugin_addressing_addOrderBy($itemtype, $ID, $order, $key)
389462{
390463 if ($itemtype == Addressing::class
391- && ($ID == 1000 || $ID == 1001 )) {
464+ && ($ID == 100 || $ID == 101 )) {
392465 return "ORDER BY INET_ATON(ITEM_$key) $order";
393466 }
394467}
@@ -404,3 +477,9 @@ function plugin_addressing_postinit()
404477 = [PingInfo::class, 'cleanForItem'];
405478 }
406479}
480+
481+ function plugin_datainjection_populate_addressing()
482+ {
483+ global $INJECTABLE_TYPES;
484+ $INJECTABLE_TYPES[AddressingInjection::class] = 'addressing';
485+ }
0 commit comments