/
copy_field.php
128 lines (111 loc) · 3.95 KB
/
copy_field.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
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT 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.
#
# MantisBT 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 MantisBT. If not, see <http://www.gnu.org/licenses/>.
# This upgrade moves attachments from the database to the disk
/**
* @package MantisBT
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
/**
* MantisBT Core API's
*/
require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
access_ensure_global_level( config_get_global( 'admin_site_threshold' ) );
$f_source_field_id = gpc_get_int( 'source_id' );
$f_dest_field = gpc_get( 'dest_id' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title> MantisBT Administration - Copy Custom Fields to Built-in </title>
<link rel="stylesheet" type="text/css" href="admin.css" />
</head>
<body>
<table width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
<tr class="top-bar">
<td class="links">
[ <a href="system_utils.php">Back to System Utilities</a> ]
[ <a href="copy_field.php?source_id=<?php echo $f_source_field_id?>&dest_id=<?php echo $f_dest_field?>">Refresh view</a> ]
</td>
<td class="title">
MantisBT Administration - Copy Custom Fields to Built-in
</td>
</tr>
</table>
<br /><br />
<?php
# checks on validity
$t_valid_fields = array(
'fixed_in_version',
);
if( !in_array( $f_dest_field, $t_valid_fields ) ) {
echo '<p>Invalid destination field (' . $f_dest_field . ') specified.</p>';
echo '</body></html>';
exit;
}
# @@@ check that source and destination are compatible
$t_string_table = db_get_table( 'custom_field_string' );
$t_bug_table = db_get_table( 'bug' );
$query = 'SELECT * FROM ' . $t_string_table . ' WHERE field_id = ' . db_param() . ' and value <> ' . db_param();
$result = @db_query_bound( $query, Array( $f_source_field_id, '' ) );
if( FALSE == $result ) {
echo '<p>No fields need to be updated.</p>';
}
else {
$count = db_num_rows( $result );
echo '<p>Found ' . $count . ' fields to be updated.</p>';
$t_failures = 0;
if( $count > 0 ) {
echo '<table width="80%" bgcolor="#222222" cellpadding="10" cellspacing="1">';
# Headings
echo '<tr bgcolor="#ffffff"><th width="10%">Bug Id</th><th width="20%">Field Value</th><th width="70%">Status</th></tr>';
}
for( $i = 0;$i < $count;$i++ ) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
# trace bug id back to project
$t_project_id = bug_get_field( $v_bug_id, 'project_id' );
$t_cust_value = $v_value;
printf("\n<tr %s><td><a href=\"../view.php?id=%d\">%07d</a></td><td>%s</td><td>",
helper_alternate_class(), $v_bug_id, $v_bug_id, $v_value);
# validate field contents
switch( $f_dest_field ) {
case 'fixed_in_version':
$t_valid = ( version_get_id( $t_cust_value, $t_project_id ) == FALSE ) ? FALSE : TRUE;
break;
default:
$t_valid = FALSE;
}
if( $t_valid ) {
# value was valid, update value
if( !bug_set_field( $v_bug_id, $f_dest_field, $t_cust_value ) ) {
echo 'database update failed';
$t_failures++;
} else {
echo 'applied';
}
} else {
echo 'field value was not valid or previously defined';
$t_failures++;
}
echo '</td></tr>';
}
echo '</table><br />' . $count . ' fields processed, ' . $t_failures . ' failures';
}
echo '<p> Completed...<p>';
?>
</body>
</html>