[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # This upgrade moves attachments from the database to the disk 21 22 # -------------------------------------------------------- 23 # $Id: move_db2disk.php,v 1.8.2.1 2007-10-13 22:34:55 giallu Exp $ 24 # -------------------------------------------------------- 25 ?> 26 <?php 27 require_once ( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' ); 28 29 $f_move_type = gpc_get( 'doc' ); 30 31 function get_prefix( $file_path ) { 32 if ( substr($file_path, 0, 1) == '/' ) { 33 # Unix absolute 34 return ''; 35 } 36 if ( substr($file_path, 0, 1) == '\\' ) { 37 # Windows absolute 38 return ''; 39 } 40 if ( substr($file_path, 1, 2) == ':\\' ) { 41 # Windows absolute 42 return ''; 43 } 44 return dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR; 45 } 46 47 #------ move file attachments to issues from database to disk 48 # select non-empty data fields 49 # match with the project to get the file path 50 # store the file in the correct folder 51 # 52 # Assumptions: only supports storage in local file system (not FTP) 53 # file paths are set up and working 54 # 55 # Re-running this is safe because the data 56 # is not removed from the database until it is successfully copied. 57 # 58 function upgrade_move_att2disk($p_source) { 59 # $p_source is the string "attachment" or "project" 60 if ( $p_source == 'attachment' ) { 61 $t_file_table = config_get_global( 'mantis_bug_file_table' ); 62 $t_bug_label = "Bug"; 63 } 64 if ( $p_source == 'project' ) { 65 $t_file_table = config_get_global( 'mantis_project_file_table' ); 66 $t_bug_label = "Project"; 67 } 68 # check that the source was valid 69 if ( ! isset($t_file_table) ) { 70 echo 'Failure: Internal Error: File source not set'; 71 return; 72 } 73 74 # check that the destination is set up properly 75 $t_upload_method = config_get_global( 'file_upload_method' ); 76 if ( $t_upload_method <> DISK ) { 77 echo 'Failure: Upload Method is not DISK'; 78 return; 79 } 80 81 $query = 'SELECT * FROM ' . $t_file_table . ' WHERE content <> \'\''; 82 83 $result = @db_query( $query ); 84 85 if ( false == $result ) { 86 echo '<p>No attachments need to be moved.</p>'; 87 return; 88 } 89 90 $count = db_num_rows( $result ); 91 echo '<p>Found ' . $count . ' attachments to be moved.</p>'; 92 $t_failures = 0; 93 94 if ( $count > 0 ) { 95 echo '<table width="80%" bgcolor="#222222" border="0" cellpadding="10" cellspacing="1">'; 96 # Headings 97 echo '<tr bgcolor="#ffffff"><th width="10%">' . $t_bug_label . '</th><th width="20%">Attachment</th><th width="70%">Status</th></tr>'; 98 } 99 100 for ( $i=0 ; $i < $count ; $i++ ) { 101 $row = db_fetch_array( $result ); 102 extract( $row, EXTR_PREFIX_ALL, 'v' ); 103 104 // trace bug id back to project to determine the proper file path 105 if ( $p_source == 'attachment' ) { 106 $t_project_id = bug_get_field( $v_bug_id, 'project_id' ); 107 $t_bug_id = $v_bug_id; 108 } else { 109 $t_project_id = (int) $v_project_id; 110 $t_bug_id = $t_project_id; 111 } 112 $t_file_path = project_get_field( $t_project_id, 'file_path' ); 113 $prefix = get_prefix( $t_file_path ); 114 $t_real_file_path = $prefix . $t_file_path; 115 $c_filename = file_clean_name($v_filename); 116 117 printf("\n<tr %s><td>%8d</td><td>%s</td><td>", helper_alternate_class(), $t_bug_id, $v_filename); 118 119 if ( is_blank( $t_real_file_path ) || !file_exists( $t_real_file_path ) || !is_dir( $t_real_file_path ) || !is_writable( $t_real_file_path ) ) { 120 echo 'Destination '. $t_real_file_path . ' not writable'; 121 $t_failures++; 122 } else { 123 $t_file_name = $t_real_file_path . $c_filename; 124 125 // write file to disk store after adjusting the path 126 if ( file_put_contents( $t_file_name, $v_content ) ){ 127 128 // successful, update database 129 # @@@ do we want to check the size of data transfer matches here? 130 $c_file_path = db_prepare_string( $t_file_path ); 131 $c_new_file_name = db_prepare_string( $t_file_path . $c_filename ); 132 $query2 = "UPDATE $t_file_table SET diskfile = '$c_new_file_name', 133 folder = '$c_file_path', content = '' WHERE id = $v_id"; 134 $update = @db_query( $query2 ); 135 if ( ! $update ) { 136 echo 'database update failed'; 137 $t_failures++; 138 } else { 139 echo 'moved to ' . $t_file_name; 140 } 141 } else { 142 echo 'copy to ' . $t_file_name . ' failed'; 143 $t_failures++; 144 } 145 } 146 echo '</td></tr>'; 147 } 148 149 echo '</table><br />' . $count . ' attachments processed, ' . $t_failures . ' failures'; 150 } 151 152 #--------------------- 153 # main code 154 # 155 if ( $f_move_type == 'attachment' ) { 156 $t_type = 'Attachments'; 157 } else { 158 if ( $f_move_type == 'project' ) { 159 $t_type = 'Project Files'; 160 } else { 161 echo "<p>Invalid value '$f_move_type' for parameter 'doc'.</p>"; 162 exit; 163 } 164 } 165 ?> 166 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 167 <html> 168 <head> 169 <title>Mantis Administration - Move <?php echo $t_type ?> to Disk</title> 170 <link rel="stylesheet" type="text/css" href="admin.css" /> 171 </head> 172 <body> 173 174 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> 175 <tr class="top-bar"> 176 <td class="links"> 177 [ <a href="system_utils.php">Back to System Utilities</a> ] 178 [ <a href="move_db2disk.php">Refresh view</a> ] 179 </td> 180 <td class="title"> 181 Move <?php echo $t_type ?> to Disk 182 </td> 183 </tr> 184 </table> 185 <br /><br /> 186 187 <?php 188 upgrade_move_att2disk( $f_move_type ); 189 echo '<p>Completed...</p>'; 190 ?> 191 </body> 192 </html>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |