forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_068_0681.php
730 lines (614 loc) · 27.1 KB
/
update_068_0681.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
/**
* DB class to connect to a OCS server
*
**/
class DBocs extends DBmysql {
function DBocs() {
global $db,$cfg_glpi;
if ($cfg_glpi["ocs_mode"]) {
$query = "SELECT * FROM `glpi_ocs_config`";
$result = $db->query($query);
$this->dbhost = $db->result($result, 0, "ocs_db_host");
$this->dbuser = $db->result($result, 0, "ocs_db_user");
$this->dbpassword = $db->result($result, 0, "ocs_db_passwd");
$this->dbdefault = $db->result($result, 0, "ocs_db_name");
if (!($this->dbh = new mysqli($this->dbhost, $this->dbuser, $this->dbpassword))) {
$this->error = 1;
}
if (!$this->dbh->select_db($this->dbdefault)) {
$this->error = 1;
}
}
}
}
/// Update from 0.68 to 0.68.1
function update068to0681() {
global $DB, $CFG_GLPI;
if ($DB->tableExists("glpi_repair_item")) {
$query = "DROP TABLE `glpi_repair_item`";
$DB->queryOrDie($query, "0.68.1 drop glpi_repair_item");
}
$tables = ["computers", "monitors", "networking", "peripherals", "phones", "printers"];
foreach ($tables as $tbl) {
if (isIndex("glpi_".$tbl, "type")) {
$query = "ALTER TABLE `glpi_$tbl`
DROP INDEX `type`";
$DB->queryOrDie($query, "0.68.1 drop index type glpi_$tbl");
}
if (isIndex("glpi_".$tbl, "type_2")) {
$query = "ALTER TABLE `glpi_$tbl`
DROP INDEX `type_2`";
$DB->queryOrDie($query, "0.68.1 drop index type_2 glpi_$tbl");
}
if (isIndex("glpi_".$tbl, "model")) {
$query = "ALTER TABLE `glpi_$tbl`
DROP INDEX `model`";
$DB->queryOrDie($query, "0.68.1 drop index model glpi_$tbl");
}
if (!isIndex("glpi_".$tbl, "type")) {
$query = "ALTER TABLE `glpi_$tbl`
ADD INDEX (`type`)";
$DB->queryOrDie($query, "0.68.1 add index type glpi_$tbl");
}
if (!isIndex("glpi_".$tbl, "model")) {
$query = "ALTER TABLE `glpi_$tbl`
ADD INDEX (`model`)";
$DB->queryOrDie($query, "0.68.1 add index model glpi_$tbl");
}
if (!isIndex("glpi_".$tbl, "FK_groups")) {
$query = "ALTER TABLE `glpi_$tbl`
ADD INDEX (`FK_groups`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_$tbl.FK_groups");
}
if (!isIndex("glpi_".$tbl, "FK_users")) {
$query = "ALTER TABLE `glpi_$tbl`
ADD INDEX ( `FK_users` )";
$DB->queryOrDie($query, "0.68.1 add index on glpi_$tbl.FK_users");
}
}
if (!isIndex("glpi_software", "FK_groups")) {
$query = "ALTER TABLE `glpi_software`
ADD INDEX (`FK_groups`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_software.FK_groups");
}
if (!isIndex("glpi_software", "FK_users")) {
$query = "ALTER TABLE `glpi_software`
ADD INDEX ( `FK_users` )";
$DB->queryOrDie($query, "0.68.1 add index on glpi_software.FK_users");
}
if (!isIndex("glpi_cartridges_type", "location")) {
$query = "ALTER TABLE `glpi_cartridges_type`
ADD INDEX (`location`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_cartridges_type.location");
}
if ($DB->fieldExists("glpi_cartridges_type", "type", false)) {
$query = "ALTER TABLE `glpi_cartridges_type`
CHANGE `type` `type` INT NOT NULL DEFAULT '0'";
$DB->queryOrDie($query, "0.68.1 alter glpi_cartridges_type.type");
}
if (!isIndex("glpi_cartridges_type", "type")) {
$query = "ALTER TABLE `glpi_cartridges_type`
ADD INDEX (`type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_cartridges_type.type");
}
if (!isIndex("glpi_cartridges_type", "alarm")) {
$query = "ALTER TABLE `glpi_cartridges_type`
ADD INDEX (`alarm`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_cartridges_type.alarm");
}
if (!isIndex("glpi_computers", "os_sp")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`os_sp`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.os_sp");
}
if (!isIndex("glpi_computers", "os_version")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`os_version`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.os_version");
}
if (!isIndex("glpi_computers", "network")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`network`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.network");
}
if (!isIndex("glpi_computers", "domain")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`domain`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.domain");
}
if (!isIndex("glpi_computers", "auto_update")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`auto_update`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.auto_update");
}
if (!isIndex("glpi_computers", "ocs_import")) {
$query = "ALTER TABLE `glpi_computers`
ADD INDEX (`ocs_import`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_computers.ocs_import");
}
if (!isIndex("glpi_consumables", "id_user")) {
$query = "ALTER TABLE `glpi_consumables`
ADD INDEX (`id_user`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_consumables.id_user");
}
if (!isIndex("glpi_consumables_type", "location")) {
$query = "ALTER TABLE `glpi_consumables_type`
ADD INDEX (`location`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_consumables_type.location");
}
if (!isIndex("glpi_consumables_type", "type")) {
$query = "ALTER TABLE `glpi_consumables_type`
ADD INDEX (`type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_consumables_type.type");
}
if (!isIndex("glpi_consumables_type", "alarm")) {
$query = "ALTER TABLE `glpi_consumables_type`
ADD INDEX (`alarm`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_consumables_type.alarm");
}
if ($DB->fieldExists("glpi_contacts", "type", false)) {
$query = "ALTER TABLE `glpi_contacts`
CHANGE `type` `type` INT( 11 ) NULL ";
$DB->queryOrDie($query, "0.68.1 alter glpi_contacts.type");
}
if (!isIndex("glpi_contract_device", "device_type")) {
$query = "ALTER TABLE `glpi_contract_device`
ADD INDEX (`device_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_contract_device.device_type");
}
if (!isIndex("glpi_contract_device", "is_template")) {
$query = "ALTER TABLE `glpi_contract_device`
ADD INDEX (`is_template`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_contract_device.is_template");
}
if (!isIndex("glpi_device_hdd", "interface")) {
$query = "ALTER TABLE `glpi_device_hdd`
ADD INDEX (`interface`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_device_hdd.interface");
}
if (!isIndex("glpi_device_ram", "type")) {
$query = "ALTER TABLE `glpi_device_ram`
ADD INDEX (`type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_device_ram.type");
}
if (!isIndex("glpi_display", "FK_users")) {
$query = "ALTER TABLE `glpi_display`
ADD INDEX (`FK_users`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_display.FK_users");
}
if (!isIndex("glpi_docs", "FK_users")) {
$query = "ALTER TABLE `glpi_docs`
ADD INDEX (`FK_users`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_docs.FK_users");
}
if (!isIndex("glpi_docs", "FK_tracking")) {
$query = "ALTER TABLE `glpi_docs`
ADD INDEX (`FK_tracking`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_docs.FK_tracking");
}
if (!isIndex("glpi_doc_device", "device_type")) {
$query = "ALTER TABLE `glpi_doc_device`
ADD INDEX (`device_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_doc_device.device_type");
}
if (!isIndex("glpi_dropdown_tracking_category", "parentID")) {
$query = "ALTER TABLE `glpi_dropdown_tracking_category`
ADD INDEX (`parentID`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_dropdown_tracking_category.parentID");
}
if (!isIndex("glpi_history", "device_type")) {
$query = "ALTER TABLE `glpi_history`
ADD INDEX (`device_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_history.device_type");
}
if (!isIndex("glpi_history", "device_internal_type")) {
$query = "ALTER TABLE `glpi_history`
ADD INDEX (`device_internal_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_history.device_internal_type");
}
if (!isIndex("glpi_infocoms", "budget")) {
$query = "ALTER TABLE `glpi_infocoms`
ADD INDEX (`budget`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_infocoms.budget");
}
if (!isIndex("glpi_infocoms", "alert")) {
$query = "ALTER TABLE `glpi_infocoms`
ADD INDEX (`alert`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_infocoms.alert");
}
if (!isIndex("glpi_kbitems", "author")) {
$query = "ALTER TABLE `glpi_kbitems`
ADD INDEX (`author`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_kbitems.author");
}
if (!isIndex("glpi_kbitems", "faq")) {
$query = "ALTER TABLE `glpi_kbitems`
ADD INDEX (`faq`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_kbitems.faq");
}
if (!isIndex("glpi_licenses", "oem_computer")) {
$query = "ALTER TABLE `glpi_licenses`
ADD INDEX (`oem_computer`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_licenses.oem_computer");
}
if (!isIndex("glpi_licenses", "oem")) {
$query = "ALTER TABLE `glpi_licenses`
ADD INDEX (`oem`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_licenses.oem");
}
if (!isIndex("glpi_licenses", "buy")) {
$query = "ALTER TABLE `glpi_licenses`
ADD INDEX (`buy`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_licenses.buy");
}
if (!isIndex("glpi_licenses", "serial")) {
$query = "ALTER TABLE `glpi_licenses`
ADD INDEX (`serial`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_licenses.serial");
}
if (!isIndex("glpi_licenses", "expire")) {
$query = "ALTER TABLE `glpi_licenses`
ADD INDEX (`expire`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_licenses.expire");
}
if (!isIndex("glpi_networking", "network")) {
$query = "ALTER TABLE `glpi_networking`
ADD INDEX (`network`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_networking.network");
}
if (!isIndex("glpi_networking", "domain")) {
$query = "ALTER TABLE `glpi_networking`
ADD INDEX (`domain`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_networking.domain");
}
if (!isIndex("glpi_networking_ports", "iface")) {
$query = "ALTER TABLE `glpi_networking_ports`
ADD INDEX (`iface`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_networking_ports.iface");
}
if ($DB->fieldExists("glpi_phones", "power", false)) {
$query = "ALTER TABLE `glpi_phones`
CHANGE `power` `power` INT NOT NULL DEFAULT '0'";
$DB->queryOrDie($query, "0.68.1 alter glpi_phones.power");
}
if (!isIndex("glpi_phones", "power")) {
$query = "ALTER TABLE `glpi_phones`
ADD INDEX (`power`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_phones.power");
}
if (!isIndex("glpi_reminder", "begin")) {
$query = "ALTER TABLE `glpi_reminder`
ADD INDEX (`begin`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_reminder.begin");
}
if (!isIndex("glpi_reminder", "end")) {
$query = "ALTER TABLE `glpi_reminder`
ADD INDEX (`end`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_reminder.end");
}
if (!isIndex("glpi_software", "update_software")) {
$query = "ALTER TABLE `glpi_software`
ADD INDEX (`update_software`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_software.update_software");
}
if (!isIndex("glpi_state_item", "state")) {
$query = "ALTER TABLE `glpi_state_item`
ADD INDEX (`state`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_state_item.state");
}
if (!isIndex("glpi_tracking", "FK_group")) {
$query = "ALTER TABLE `glpi_tracking`
ADD INDEX (`FK_group`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_tracking.FK_group");
}
if (!isIndex("glpi_tracking", "assign_ent")) {
$query = "ALTER TABLE `glpi_tracking`
ADD INDEX (`assign_ent`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_tracking.assign_ent");
}
if (!isIndex("glpi_tracking", "device_type")) {
$query = "ALTER TABLE `glpi_tracking`
ADD INDEX (`device_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_tracking.device_type");
}
if (!isIndex("glpi_tracking", "priority")) {
$query = "ALTER TABLE `glpi_tracking`
ADD INDEX (`priority`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_tracking.priority");
}
if (!isIndex("glpi_tracking", "request_type")) {
$query = "ALTER TABLE `glpi_tracking`
ADD INDEX (`request_type`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_tracking.request_type");
}
if (!isIndex("glpi_users", "location")) {
$query = "ALTER TABLE `glpi_users`
ADD INDEX (`location`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_users.location");
}
if (!isIndex("glpi_printers", "network")) {
$query = "ALTER TABLE `glpi_printers`
ADD INDEX (`network`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_printers.network");
}
if (!isIndex("glpi_printers", "domain")) {
$query = "ALTER TABLE `glpi_printers`
ADD INDEX (`domain`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_printers.domain");
}
if ($DB->fieldExists("glpi_device_case", "format", false)) {
$query = "ALTER TABLE `glpi_device_case`
CHANGE `format` `format` ENUM('Grand', 'Moyen', 'Micro', 'Slim', '')
NULL DEFAULT 'Moyen'";
$DB->queryOrDie($query, "0.68.1 alter glpi_device_case.format");
}
if ($DB->fieldExists("glpi_device_gfxcard", "interface", false)) {
$query = "ALTER TABLE `glpi_device_gfxcard`
CHANGE `interface` `interface` ENUM('AGP', 'PCI', 'PCI-X', 'Other', '')
NULL DEFAULT 'AGP'";
$DB->queryOrDie($query, "0.68.1 alter glpi_device_gfxcard.interface");
}
// Add default values in GLPI_DROPDOWN_HDD_TYPE
// Rename glpi_dropdown HDD_TYPE -> INTERFACE
if (!$DB->tableExists("glpi_dropdown_interface")) {
$query = "ALTER TABLE `glpi_dropdown_hdd_type`
RENAME `glpi_dropdown_interface` ";
$DB->queryOrDie($query, "0.68.1 alter dropdown_hdd_type -> dropdown_interface");
$values = ["SATA", "IDE", "SCSI", "USB"];
$interfaces = [];
foreach ($values as $val) {
$query = "SELECT *
FROM `glpi_dropdown_interface`
WHERE `name` LIKE '$val'";
$result = $DB->query($query);
if ($DB->numrows($result)==1) {
$row = $DB->fetch_array($result);
$interfaces[$val] = $row["ID"];
} else {
$query = "INSERT INTO `glpi_dropdown_interface`
(`name`)
VALUES ('$val');";
$DB->query($query);
$interfaces[$val] = $DB->insert_id();
}
}
// ALTER TABLES
$query = "ALTER TABLE `glpi_device_control`
CHANGE `interface` `interface2` ENUM('IDE', 'SATA', 'SCSI', 'USB') NOT NULL
DEFAULT 'IDE'";
$DB->queryOrDie($query, "0.68.1 alter device_control");
$query = "ALTER TABLE `glpi_device_drive`
CHANGE `interface` `interface2` ENUM('IDE', 'SATA', 'SCSI') NOT NULL DEFAULT 'IDE'";
$DB->queryOrDie($query, "0.68.1 alter device_drive");
$query = "ALTER TABLE `glpi_device_control`
ADD `interface` INT NULL ";
$DB->queryOrDie($query, "0.68.1 alter device_control");
$query = "ALTER TABLE `glpi_device_drive`
ADD `interface` INT NULL ";
$DB->queryOrDie($query, "0.68.1 alter device_drive");
foreach ($interfaces as $name => $ID) {
$query = "UPDATE `glpi_device_drive`
SET `interface` = '$ID'
WHERE `interface2` = '$name'";
$DB->queryOrDie($query, "0.68.1 update data device_drive");
$query = "UPDATE `glpi_device_control`
SET `interface` = '$ID'
WHERE `interface2` = '$name'";
$DB->queryOrDie($query, "0.68.1 update data device_control");
}
// DROP TABLES
$query = "ALTER TABLE `glpi_device_control`
DROP `interface2`";
$DB->queryOrDie($query, "0.68.1 drop interface2 device_drive");
$query = "ALTER TABLE `glpi_device_drive`
DROP `interface2`";
$DB->queryOrDie($query, "0.68.1 drop interface2 device_drive");
// ADD INDEX
$query = "ALTER TABLE `glpi_device_drive`
ADD INDEX (`interface`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_device_drive.interface");
$query = "ALTER TABLE `glpi_device_control`
ADD INDEX (`interface`)";
$DB->queryOrDie($query, "0.68.1 add index on glpi_device_drive.interface");
}
if ($DB->fieldExists("glpi_profiles", "update", false)) {
$query = "ALTER TABLE `glpi_profiles`
CHANGE `update` `check_update` CHAR( 1 ) NULL DEFAULT NULL";
$DB->queryOrDie($query, "0.68.1 alter glpi_profiles.update");
}
if ($DB->fieldExists("glpi_config", "last_update_check", false)) {
$query = "ALTER TABLE `glpi_config`
DROP `last_update_check`";
$DB->queryOrDie($query, "0.68.1 drop glpi_config.last_update_check");
}
if (!$DB->fieldExists("glpi_config", "keep_tracking_on_delete", false)) {
$query = "ALTER TABLE `glpi_config`
ADD `keep_tracking_on_delete` INT DEFAULT '1'";
$DB->queryOrDie($query, "0.68.1 drop glpi_config.keep_tracking_on_delete");
}
if (!$DB->fieldExists("glpi_config", "show_admin_doc", false)) {
$query = "ALTER TABLE `glpi_config`
ADD `show_admin_doc` INT DEFAULT '0' ";
$DB->queryOrDie($query, "0.68.1 drop glpi_config.show_admin_doc");
}
if (!$DB->fieldExists("glpi_config", "time_step", false)) {
$query = "ALTER TABLE `glpi_config`
ADD `time_step` INT DEFAULT '5' ";
$DB->queryOrDie($query, "0.68.1 drop glpi_config.time_step");
}
$query = "UPDATE `glpi_config`
SET `time_step` = '5',
`show_admin_doc` = '0',
`keep_tracking_on_delete` = '0'";
$DB->queryOrDie($query, "0.68.1 update glpi_config data");
if (!$DB->fieldExists("glpi_ocs_config", "cron_sync_number", false)) {
$query = "ALTER TABLE `glpi_ocs_config`
ADD `cron_sync_number` INT DEFAULT '1' ";
$DB->queryOrDie($query, "0.68.1 drop glpi_ocs_config.cron_sync_number");
}
if (!$DB->fieldExists("glpi_profiles", "show_group_ticket", false)) {
$query = "ALTER TABLE `glpi_profiles`
ADD `show_group_ticket` char(1) DEFAULT '0' ";
$DB->queryOrDie($query, "0.68.1 drop glpi_profiles.show_group_ticket");
}
if (!$DB->fieldExists("glpi_config", "ldap_group_condition", false)) {
$query = "ALTER TABLE `glpi_config`
ADD `ldap_group_condition` VARCHAR( 255 ) NULL ,
ADD `ldap_search_for_groups` TINYINT NOT NULL DEFAULT '0',
ADD `ldap_field_group_member` VARCHAR( 255 ) NULL ";
$DB->queryOrDie($query, "0.68.1 add glpi_config.ldap_*_groups");
}
if (!$DB->fieldExists("glpi_groups", "ldap_group_dn", false)) {
$query = "ALTER TABLE `glpi_groups`
ADD `ldap_group_dn` VARCHAR( 255 ) NULL ";
$DB->queryOrDie($query, "0.68.1 add glpi_groups.ldap_group_dn");
}
if (!$DB->fieldExists("glpi_ocs_link", "ocs_deviceid", false)) {
$query = "ALTER TABLE `glpi_ocs_link`
CHANGE `ocs_id` `ocs_deviceid` VARCHAR( 255 ) NOT NULL ";
$DB->queryOrDie($query, "0.68.1 add glpi_ocs_link.ocs_deviceid");
}
if (!$DB->fieldExists("glpi_ocs_link", "ocs_id", false)) {
$query = "ALTER TABLE `glpi_ocs_link`
ADD `ocs_id` INT NOT NULL DEFAULT '0' AFTER `glpi_id` ";
$DB->queryOrDie($query, "0.68.1 add glpi_ocs_link.ocs_id");
}
if (!$DB->fieldExists("glpi_ocs_link", "last_ocs_update", false)) {
$query = "ALTER TABLE `glpi_ocs_link`
ADD `last_ocs_update` DATETIME NULL AFTER `last_update` ";
$DB->queryOrDie($query, "0.68.1 add glpi_ocs_link.last_ocs_update");
}
if (countElementsInTable("glpi_ocs_link")) {
$CFG_GLPI["ocs_mode"] = 1;
$DBocs = new DBocs(1);
// Get datas to update
$query = "SELECT *
FROM `glpi_ocs_link`";
$result_glpi = $DB->query($query);
while ($data_glpi = $DB->fetch_array($result_glpi)) {
// Get ocs information
$query_ocs = "SELECT *
FROM `hardware`
WHERE `DEVICEID` = '".$data_glpi["ocs_deviceid"]."'
LIMIT 1";
$result_ocs = $DBocs->queryOrDie($query_ocs, "0.68.1 get ocs infos");
if ($result_ocs && $DBocs->numrows($result_ocs)) {
$data_ocs = $DBocs->fetch_array($result_ocs);
$query_update = "UPDATE `glpi_ocs_link`
SET `ocs_id` = '".$data_ocs["ID"]."',
`last_ocs_update` = '".$data_ocs["LASTDATE"]."'
WHERE `ID` = '".$data_glpi["ID"]."'";
$DB->queryOrDie($query_update, "0.68.1 update ocs infos");
}
}
}
if (!$DB->tableExists("glpi_dropdown_case_type")) {
$query = "CREATE TABLE `glpi_dropdown_case_type` (
`ID` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`comments` text,
PRIMARY KEY (`ID`),
KEY `name` (`name`)
) ENGINE=MyISAM;";
$DB->queryOrDie($query, "0.68.1 add table dropdown_case_type");
// ajout du champs type
$query = "ALTER TABLE `glpi_device_case`
ADD `type` INT(11) default NULL AFTER `designation` ";
$DB->queryOrDie($query, "0.68.1 add glpi_device_case.type");
// Ajout des entrees dans la table dropdown_case_type
$query = "INSERT INTO `glpi_dropdown_case_type`
(`ID` , `name` , `comments`)
VALUES ('1' , 'Grand', NULL)";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
$query = "INSERT INTO `glpi_dropdown_case_type`
(`ID` , `name` , `comments`)
VALUES ('2' , 'Moyen', NULL)";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
$query = "INSERT INTO `glpi_dropdown_case_type`
(`ID` , `name` , `comments`)
VALUES ('3' , 'Micro', NULL)";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
// Mapping format enum / type
$query = "UPDATE `glpi_device_case`
SET `type` = '1'
WHERE `format` = 'Grand'";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
$query = "UPDATE `glpi_device_case`
SET `type` = '2'
WHERE `format` = 'Moyen'";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
$query = "UPDATE `glpi_device_case`
SET `type` = '3'
WHERE `format` = 'Micro'";
$DB->queryOrDie($query, "0.68.1 glpi_device_case");
// Supression du champ format
$query = "ALTER TABLE `glpi_device_case`
DROP `format`";
$DB->queryOrDie($query, "0.68.1 drop format from glpi_device_case");
}
// Clean state datas
if ($DB->tableExists("glpi_state_item")) {
$query = "SELECT COUNT(*) AS CPT, `device_type`, `id_device`
FROM `glpi_state_item`
GROUP BY `device_type`, `id_device`
HAVING CPT > 1";
$result = $DB->query($query);
if ($DB->numrows($result)) {
while ($data = $DB->fetch_array($result)) {
$query2 = "DELETE
FROM `glpi_state_item`
WHERE `device_type` = '".$data["device_type"]."'
AND `id_device` = '".$data["id_device"]."'
LIMIT ".($data["CPT"]-1)."";
$DB->queryOrDie($query2, "0.68.1 clean glpi_state_item");
}
}
if (isIndex("glpi_state_item", "device_type")) {
$query = "ALTER TABLE `glpi_state_item`
DROP INDEX `device_type` ";
$DB->queryOrDie($query, "0.68.1 drop index glpi_state_item");
}
if (isIndex("glpi_state_item", "device_type2")) {
$query = "ALTER TABLE `glpi_state_item`
DROP INDEX `device_type2` ";
$DB->queryOrDie($query, "0.68.1 drop index glpi_state_item");
}
$query = "ALTER TABLE `glpi_state_item`
ADD INDEX (`device_type`) ";
$DB->queryOrDie($query, "0.68.1 add index glpi_state_item");
$query = "ALTER TABLE `glpi_state_item`
ADD UNIQUE (`device_type`, `id_device`) ";
$DB->queryOrDie($query, "0.68.1 add unique glpi_state_item");
}
} // fin 0.68 #####################################################################################