/
0_18_inc.php
620 lines (492 loc) · 19.5 KB
/
0_18_inc.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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# Changes applied to 0.18 database
# --------------------------------------------------------
# $Id: 0_18_inc.php,v 1.22 2004-08-14 15:26:20 thraxisp Exp $
# --------------------------------------------------------
?>
<?php
require_once( 'db_table_names_inc.php' );
$upgrades = array();
$upgrades[] = new FunctionUpgrade(
'0.18-vb-1',
'Add index on bug_id field in mantis_bug_file_table.',
'upgrade_0_18_vb_1' );
$upgrades[] = new SQLUpgrade(
'filtersdb-1',
'Add mantis_filters_table',
"CREATE TABLE $t_filters_table (
id int(7) unsigned DEFAULT '1' NOT NULL auto_increment,
user_id int(7) NOT NULL,
project_id int(7) NOT NULL,
is_public BOOL,
name char(64) NOT NULL,
filter_string text NOT NULL,
PRIMARY KEY (id))"
);
function upgrade_0_18_vb_1() {
global $t_bug_file_table;
if ( !db_key_exists_on_field( $t_bug_file_table, 'bug_id', 'MUL' ) ) {
$query = "ALTER TABLE $t_bug_file_table ADD INDEX bug_id ( bug_id )";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
return true;
}
$upgrades[] = new FunctionUpgrade(
'emailsevs-1',
'Add the necessary columns for email severity filtering',
'emailseverities_fix_1' );
function emailseverities_fix_1() {
global $t_user_pref_table;
if ( !db_field_exists( 'email_on_priority_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_priority_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_priority";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_status_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_status_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_priority_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_bugnote_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_bugnote_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_status_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_reopened_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_reopened_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_bugnote_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_closed_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_closed_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_reopened_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_resolved_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_resolved_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_closed_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_feedback_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_feedback_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_resolved_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_assigned_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_assigned_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_feedback_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'email_on_new_minimum_severity', $t_user_pref_table ) ) {
$query = "ALTER TABLE $t_user_pref_table ADD email_on_new_minimum_severity INT(2) DEFAULT '10' NOT NULL
AFTER email_on_assigned_minimum_severity";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
return true;
}
$upgrades[] = new SQLUpgrade(
'sponsorship-1',
'Add sponsorships table',
"CREATE TABLE IF NOT EXISTS mantis_sponsorship_table (
id int(7) NOT NULL auto_increment,
bug_id int(7) NOT NULL default '0',
user_id int(7) NOT NULL default '0',
amount int(7) NOT NULL default '0',
logo varchar(128) NOT NULL default '',
url varchar(128) NOT NULL default '',
paid int(1) NOT NULL default '0',
date_submitted datetime NOT NULL default '1970-01-01 00:00:01',
last_updated datetime NOT NULL default '1970-01-01 00:00:01',
PRIMARY KEY (id),
KEY bug_id (bug_id),
KEY user_id (user_id)
) TYPE=MyISAM COMMENT='A table for sponsorships' AUTO_INCREMENT=1" );
$upgrades[] = new SQLUpgrade(
'sponsorship-2',
'Add sponsorship_total to bug table',
"ALTER TABLE $t_bug_table ADD sponsorship_total INT( 7 ) DEFAULT '0' NOT NULL" );
$upgrades[] = new SQLUpgrade(
'sponsorship-3',
'Add an index on sponsorship_total in bug table',
"ALTER TABLE $t_bug_table ADD INDEX sponsorship_total ( sponsorship_total )" );
$upgrades[] = new SQLUpgrade(
'fixed_in_version-1',
'Add fixed_in_version field to bug table.',
"ALTER TABLE $t_bug_table ADD fixed_in_version VARCHAR( 64 ) NOT NULL AFTER version" );
$upgrades[] = new SQLUpgrade(
'fixed_in_version-2',
'Add index on fixed_in_version field in bug table.',
"ALTER TABLE $t_bug_table ADD INDEX ( fixed_in_version )" );
$upgrades[] = new SQLUpgrade(
'user_realname',
'Add real name to user information.',
"ALTER TABLE $t_user_table ADD realname VARCHAR( 64 ) NOT NULL AFTER username" );
$upgrades[] = new SQLUpgrade(
'custom_fields-1',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD display_resolve BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-2',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD display_close BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-3',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD require_report BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-4',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD require_update BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-5',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD require_resolve BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-6',
'Allow custom fields to be set/required for resolve/close/report/update',
"ALTER TABLE $t_custom_field_table ADD require_close BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'version_remove_pk',
'Remove project_id+version primary key',
"ALTER TABLE $t_project_version_table DROP PRIMARY KEY" );
$upgrades[] = new SQLUpgrade(
'version_add_version_',
'Add id to version table and use it as primary key',
"ALTER TABLE $t_project_version_table ADD id INT( 7 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
$upgrades[] = new SQLUpgrade(
'version_add_project_',
'Add a unique index for project_id + version combination.',
"ALTER TABLE $t_project_version_table ADD UNIQUE project_version ( project_id , version )" );
$upgrades[] = new SQLUpgrade(
'version_add_descript',
'Add description field to versions.',
"ALTER TABLE $t_project_version_table ADD description TEXT NOT NULL" );
$upgrades[] = new SQLUpgrade(
'version_add_released',
'Add released flag to determine whether the version was released or still a future release.',
"ALTER TABLE $t_project_version_table ADD released TINYINT( 1 ) DEFAULT '1' NOT NULL" );
# MASC RELATIONSHIP
# --------------------------------------------------------
# Author: Marcello Scata'° marcello@marcelloscata.com
# UPGRADE THE DATABASE TO IMPLEMENT THE RELATIONSHIPS
# --------------------------------------------------------
# The script executes the following steps:
# - Add index on source_bug_id field in mantis_bug_relationship_table
# - Add index on destination_bug_id field in mantis_bug_relationship_table
# - For each bug with the duplicate_id field filled out:
# Check if there is already a relationship set between bug and duplicate bug
# if yes then do nothing and continue with the next bug
# if no then
# add the relationship between bug and duplicate bug
# search in history of bug the line in which is recorded the duplicate id information
# and replace it with the appropriate history record for relationship (same user id, same time-stamp)
# add an history record in the duplicate bug with same user id, same time-stamp with bug
# - THE CONTENT OF THE DUPLICATE_ID FIELD IS NOT MODIFIED
# --------------------------------------------------------
$upgrades[] = new FunctionUpgrade(
'relationship-1',
'Add index on source_bug_id field in mantis_bug_relationship_table',
'upgrade_0_18_relationship_1' );
function upgrade_0_18_relationship_1() {
global $t_bug_relationship_table;
if ( !db_key_exists_on_field( $t_bug_relationship_table, 'source_bug_id', 'MUL' ) ) {
$query = "ALTER TABLE $t_bug_relationship_table ADD INDEX ( source_bug_id )";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
return true;
}
$upgrades[] = new FunctionUpgrade(
'relationship-2',
'Add index on destination_bug_id field in mantis_bug_relationship_table',
'upgrade_0_18_relationship_2' );
function upgrade_0_18_relationship_2() {
global $t_bug_relationship_table;
if ( !db_key_exists_on_field( $t_bug_relationship_table, 'destination_bug_id', 'MUL' ) ) {
$query = "ALTER TABLE $t_bug_relationship_table ADD INDEX ( destination_bug_id )";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
return true;
}
$upgrades[] = new FunctionUpgrade(
'relationship-3',
'Translate duplicate id information in a new duplicate relationship',
'upgrade_0_18_relationship_3' );
function upgrade_0_18_relationship_3() {
global $t_bug_relationship_table, $t_bug_table, $t_bug_history_table;
$query = "SELECT id, duplicate_id
FROM $t_bug_table
WHERE duplicate_id != '';";
$result = db_query( $query );
$t_count = db_num_rows( $result );
for ( $i = 0 ; $i < $t_count ; $i++ ) {
$t_bug = db_fetch_array( $result );
$t_bug_id = $t_bug['id'];
$t_duplicate_bug_id = $t_bug['duplicate_id'];
$query = "SELECT id
FROM $t_bug_relationship_table
WHERE
(source_bug_id = '$t_bug_id' and
destination_bug_id = '$t_duplicate_bug_id') or
(destination_bug_id = '$t_bug_id' and
source_bug_id = '$t_duplicate_bug_id');";
$result2 = db_query( $query );
$t_count2 = db_num_rows( $result2 );
if( $t_count2 > 0 ) {
continue;
}
$query = "INSERT INTO $t_bug_relationship_table
( source_bug_id, destination_bug_id, relationship_type )
VALUES
( '" . $t_bug_id . "', '" . $t_duplicate_bug_id . "', '" . BUG_DUPLICATE . "')";
db_query( $query );
$query = "SELECT id, user_id, date_modified
FROM $t_bug_history_table
WHERE
bug_id = '$t_bug_id' and
field_name = 'duplicate_id' and
new_value = '$t_duplicate_bug_id';";
$result2 = db_query( $query );
$t_count2 = db_num_rows( $result2 );
if ( $t_count2 < 1) {
continue;
}
$t_history_bug = db_fetch_array( $result2 );
$t_history_id = $t_history_bug['id'];
$t_history_user_id = $t_history_bug['user_id'];
$t_duplicate_bug_last_update = $t_history_bug['date_modified'];
$query = "UPDATE $t_bug_history_table
SET field_name = '',
old_value = '" . BUG_DUPLICATE . "',
type = '" . BUG_ADD_RELATIONSHIP . "'
WHERE id='$t_history_id'";
db_query( $query );
$query = "INSERT INTO $t_bug_history_table
( user_id, bug_id, date_modified, type, old_value, new_value )
VALUES
( '$t_history_user_id', '$t_duplicate_bug_id', '" . $t_duplicate_bug_last_update . "', " .
BUG_ADD_RELATIONSHIP . ", " . BUG_HAS_DUPLICATE . ", '$t_bug_id' )";
db_query( $query );
}
return true;
}
$upgrades[] = new FunctionUpgrade(
'relationship-4',
'Fix swapped value in duplicate relationship',
'upgrade_0_18_relationship_4' );
function upgrade_0_18_relationship_4() {
global $t_bug_relationship_table, $t_bug_table;
$query = "SELECT id, duplicate_id
FROM $t_bug_table
WHERE duplicate_id != '';";
$result = db_query( $query );
$t_count = db_num_rows( $result );
for ( $i = 0 ; $i < $t_count ; $i++ ) {
$t_bug = db_fetch_array( $result );
$t_bug_id = $t_bug['id'];
$t_duplicate_bug_id = $t_bug['duplicate_id'];
$query = "SELECT id
FROM $t_bug_relationship_table
WHERE
relationship_type = '" . BUG_DUPLICATE . "' and
source_bug_id = '$t_duplicate_bug_id' and
destination_bug_id = '$t_bug_id';";
$result2 = db_query( $query );
$t_count2 = db_num_rows( $result2 );
if( $t_count2 != 1 ) {
continue;
}
$t_relationship = db_fetch_array( $result2 );
$t_relationship_id = $t_relationship['id'];
$query = "UPDATE $t_bug_relationship_table
SET source_bug_id = '$t_bug_id',
destination_bug_id = '$t_duplicate_bug_id'
WHERE id='$t_relationship_id'";
db_query( $query );
}
return true;
}
# MASC RELATIONSHIP
if ( config_get( 'differentiate_duplicates' ) ) {
$upgrades[] = new SQLUpgrade(
'user-duplicate',
'Add realname duplicate field to user table',
"ALTER TABLE $t_user_table ADD duplicate_realname INT( 1 ) DEFAULT '0'" );
$upgrades[] = new FunctionUpgrade(
'user-duplicate-fix',
'set values for duplicate_realname',
'upgrade_0_18_user_duplicate' );
}
function upgrade_0_18_user_duplicate() {
global $t_user_table;
$query = "SELECT realname FROM $t_user_table
WHERE realname != ''
GROUP BY realname
HAVING count(realname) > 1";
$result = db_query( $query );
$t_count = db_num_rows( $result );
for ( $i = 0 ; $i < $t_count ; $i++ ) {
$t_row = db_fetch_array( $result );
$t_name = $t_row['realname'];
$query = "UPDATE $t_user_table
SET duplicate_realname = 'Y'
WHERE realname='$t_name'";
db_query( $query );
}
return true;
}
$upgrades[] = new SQLUpgrade(
'cat_user_id_unsigned',
'Change the user_id in mantis_project_category_table to unsigned int.',
"ALTER TABLE $t_project_category_table CHANGE user_id user_id INT( 7 ) UNSIGNED DEFAULT '0' NOT NULL" );
$upgrades[] = new SQLUpgrade(
'custom_fields-7',
'Allow custom fields to be hidden/displayed for report/update',
"ALTER TABLE $t_custom_field_table ADD display_report BOOL NOT NULL default '1'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-8',
'Allow custom fields to be hidden/displayed for report/update',
"ALTER TABLE $t_custom_field_table ADD display_update BOOL NOT NULL default '1'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-9',
'Rename Column',
"ALTER TABLE $t_custom_field_table ADD require_resolved BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-10',
'Rename Column',
"UPDATE $t_custom_field_table SET require_resolved = require_resolve" );
$upgrades[] = new SQLUpgrade(
'custom_fields-11',
'Rename Column',
"ALTER TABLE $t_custom_field_table DROP require_resolve" );
$upgrades[] = new SQLUpgrade(
'custom_fields-12',
'Rename Column',
"ALTER TABLE $t_custom_field_table ADD display_resolved BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-13',
'Rename Column',
"UPDATE $t_custom_field_table SET display_resolved = display_resolve" );
$upgrades[] = new SQLUpgrade(
'custom_fields-14',
'Rename Column',
"ALTER TABLE $t_custom_field_table DROP display_resolve" );
$upgrades[] = new SQLUpgrade(
'custom_fields-15',
'Rename Column',
"ALTER TABLE $t_custom_field_table ADD display_closed BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-16',
'Rename Column',
"UPDATE $t_custom_field_table SET display_closed = display_close" );
$upgrades[] = new SQLUpgrade(
'custom_fields-17',
'Rename Column',
"ALTER TABLE $t_custom_field_table DROP display_close" );
$upgrades[] = new SQLUpgrade(
'custom_fields-18',
'Rename Column',
"ALTER TABLE $t_custom_field_table ADD require_closed BOOL NOT NULL default '0'" );
$upgrades[] = new SQLUpgrade(
'custom_fields-19',
'Rename Column',
"UPDATE $t_custom_field_table SET require_closed = require_close" );
$upgrades[] = new SQLUpgrade(
'custom_fields-20',
'Rename Column',
"ALTER TABLE $t_custom_field_table DROP require_close" );
$upgrades[] = new FunctionUpgrade(
'lost-password',
'Add the necessary columns for managing lost passwords',
'lostpassword_fix_1' );
function lostpassword_fix_1() {
global $t_user_table;
if ( !db_field_exists( 'failed_login_count', $t_user_table ) ) {
$query = "ALTER TABLE $t_user_table ADD failed_login_count INT(2) DEFAULT '0' NOT NULL
AFTER login_count";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
if ( !db_field_exists( 'lost_password_in_progress_count', $t_user_table ) ) {
$query = "ALTER TABLE $t_user_table ADD lost_password_in_progress_count INT(2) DEFAULT '0' NOT NULL
AFTER login_count";
$result = @db_query( $query );
if ( false == $result ) {
return false;
}
}
return true;
}
$upgrades[] = new FunctionUpgrade(
'delete-admin-over',
'Delete any project level access overrides for admin users',
'upgrade_0_18_del_admin_override' );
function upgrade_0_18_del_admin_override() {
global $t_user_table, $t_project_user_list_table;
$t_admin = ADMINISTRATOR;
$query = "select p.user_id
FROM $t_project_user_list_table as p, $t_user_table as u
WHERE ( ( p.user_id = u.id ) AND ( u.access_level >= $t_admin ) )";
$result = db_query( $query );
$t_count = db_num_rows( $result );
for ( $i = 0 ; $i < $t_count ; $i++ ) {
$t_row = db_fetch_array( $result );
$t_user = $t_row['user_id'];
$query = "DELETE FROM $t_project_user_list_table
WHERE user_id=$t_user";
db_query( $query );
}
return true;
}
$upgrades[] = new SQLUpgrade(
'0.18-bugnote-limit',
"Add email_bugnote_limit to user preference table",
"ALTER TABLE $t_user_pref_table ADD email_bugnote_limit INT( 2 ) NOT NULL AFTER email_on_new_minimum_severity" );
$upgrades[] = new SQLUpgrade(
'0.18-bugnote-order',
"Add bugnote_order to user preference table",
"ALTER TABLE $t_user_pref_table ADD bugnote_order VARCHAR( 4 ) NOT NULL DEFAULT '" . config_get( 'default_bugnote_order' ) . "' AFTER redirect_delay" );
return $upgrades;
?>