/
move_attachments_page.php
160 lines (133 loc) · 4.31 KB
/
move_attachments_page.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
<?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 - 2013 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' ) );
# Page header, menu
html_page_top( 'MantisBT Administration - Moving Attachments' );
echo '<div align="center"><p>';
print_bracket_link( helper_mantis_url( 'admin/system_utils.php' ), 'Back to System Utilities' );
echo '</p></div>';
# File type should be 'bug' (default) or 'project'
$f_file_type = gpc_get( 'type', 'bug' );
$t_bug_table = db_get_table( 'mantis_bug_table' );
$t_project_table = db_get_table( 'mantis_project_table' );
switch( $f_file_type ) {
case 'project':
$t_type = 'Project Files';
$t_file_table = db_get_table( 'mantis_project_file_table' );
$t_query = "SELECT p.id, p.name, COUNT(f.id) disk
FROM $t_file_table f
LEFT JOIN $t_project_table p ON p.id = f.project_id
WHERE content <> ''
GROUP BY p.id, p.name
ORDER BY p.name";
break;
case 'bug':
default:
$t_type = 'Attachments';
$t_file_table = db_get_table( 'mantis_bug_file_table' );
$t_query = "SELECT p.id, p.name, COUNT(f.id) disk
FROM $t_file_table f
JOIN $t_bug_table b ON b.id = f.bug_id
JOIN $t_project_table p ON p.id = b.project_id
WHERE content <> ''
GROUP BY p.id, p.name
ORDER BY p.name";
break;
}
# Move to disk: projects having non-empty attachments in the DB
$t_result = db_query_bound( $t_query );
# Build list, excluding projects having upload method other than DISK
$t_projects = array();
while( $t_row = db_fetch_array( $t_result ) ) {
$t_project_id = (int) $t_row['id'];
$t_upload_method = config_get( 'file_upload_method', null, ALL_USERS, $t_project_id );
if( $t_upload_method == DISK ) {
$t_projects[$t_project_id] = $t_row;
}
}
if( count( $t_projects ) == 0 ) {
# Nothing to do
echo '<div align="center"><p>No attachments need to be moved.</p></div>';
} else {
# Display name for All Projects
if( isset( $t_projects[ALL_PROJECTS] ) ) {
$t_projects[ALL_PROJECTS]['name'] = 'All Projects';
}
# Display table of projects for user selection
?>
<div align="center">
<form name="move_attachments_project_select" method="post" action="move_attachments.php">
<table class="width50">
<tr>
<td class="form-title" colspan="2">
<?php echo "$t_type to move"; ?>
</td>
</tr>
<tr class="row-category">
<th>Project name</th>
<th width="18%">Attachments</th>
<th width="7%">To Disk</th>
</tr>
<?php
# Printing rows of projects with attachments to move
foreach( $t_projects as $t_id => $t_project ) {
echo '<tr ' . helper_alternate_class() . '>';
printf(
'<td>%s</td><td class="center">%s</td><td class="center">'
. '<input type="checkbox" name="to_disk[]" value="%d" /></td>',
$t_project['name'],
$t_project['disk'],
$t_id
);
echo "</tr>\n";
}
if( ON == config_get( 'use_javascript' ) ) {
?>
<tr>
<td class="right" colspan="2">Select All</td>
<td class="center">
<input name="all_proj"
type="checkbox" value="all"
onclick="checkall('move_attachments_project_select', this.form.all_proj.checked)"
/>
</td>
</tr>
<?php
}
echo form_security_field( 'move_attachments_project_select' );
?>
</table>
<span class="center">
<br />
<input name="type" type="hidden" value="<?php echo $f_file_type ?>" />
<input type="submit" class="button" value="Move Attachments" />
</span>
</form>
</div>
<?php
}
html_page_bottom();