| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 # Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 # 17 # -------------------------------------------------------- 18 # $Id$ 19 # -------------------------------------------------------- 20 21 require_once ( 'core.php' ); 22 23 auth_ensure_user_authenticated( ); 24 helper_begin_long_process( ); 25 26 $t_page_number = 1; 27 $t_per_page = -1; 28 $t_bug_count = null; 29 $t_page_count = null; 30 31 $t_nl = "\n"; 32 33 # Get bug rows according to the current filter 34 $t_result = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count ); 35 if( $t_result === false ) { 36 $t_result = array( ); 37 } 38 39 $t_filename = "exported_issues.xml"; 40 41 # Send headers to browser to activate mime loading 42 # Make sure that IE can download the attachments under https. 43 header( 'Pragma: public' ); 44 45 header( 'Content-Type: text/xml; name=' . $t_filename ); 46 header( 'Content-Transfer-Encoding: BASE64;' ); 47 48 # Added Quotes (") around file name. 49 header( 'Content-Disposition: attachment; filename="' . $t_filename . '"' ); 50 51 $t_version = MANTIS_VERSION; 52 $t_url = config_get( 'path' ); 53 $t_bug_link = config_get( 'bug_link_tag' ); 54 $t_bugnote_link = config_get( 'bugnote_link_tag' ); 55 56 $writer = new XMLWriter; 57 58 $writer->openURI( 'php://output' ); 59 $writer->setIndent( true ); 60 $writer->setIndentString( ' ' ); 61 62 $writer->startDocument( '1.0', 'UTF-8' ); 63 $writer->startElement( 'mantis' ); 64 $writer->writeAttribute( 'version', $t_version ); 65 $writer->writeAttribute( 'urlbase', $t_url ); 66 $writer->writeAttribute( 'issuelink', $t_bug_link ); 67 $writer->writeAttribute( 'notelink', $t_bugnote_link ); 68 $writer->writeAttribute( 'format', '1' ); 69 70 # Ignored fields, these will be skipped 71 $t_ignore = array( 72 '_stats', 73 'bug_text_id', 74 ); 75 76 /* properties that we want to export are 'protected' */ 77 $t_columns = array_keys( getClassProperties('BugData', 'protected') ); 78 79 # export the rows 80 foreach( $t_result as $t_row ) { 81 82 $writer->startElement( 'issue' ); 83 84 foreach( $t_columns as $t_element ) { 85 $t_value = $t_row->$t_element; 86 if( empty( $t_value ) ) { 87 continue; 88 } 89 90 if( in_array( $t_element, $t_ignore ) ) { 91 continue; 92 } 93 94 switch( $t_element ) { 95 case 'reporter_id': 96 case 'handler_id': 97 $t_element_name = substr( $t_element, 0, - 3 ); 98 $t_element_data = user_get_name( $t_value ); 99 100 $writer->startElement( $t_element_name ); 101 $writer->writeAttribute( 'id', $t_value ); 102 $writer->text( $t_element_data ); 103 $writer->endElement( ); 104 break; 105 106 case 'category_id': 107 108 // id for categories were introduced in 1.2 109 $t_element_name = 'category'; 110 $t_element_data = category_get_name( $t_value ); 111 112 $writer->startElement( $t_element_name ); 113 $writer->writeAttribute( 'id', $t_value ); 114 $writer->text( $t_element_data ); 115 $writer->endElement( ); 116 break; 117 118 case 'project_id': 119 $t_element_name = 'project'; 120 $t_element_data = project_get_name( $t_value ); 121 122 $writer->startElement( $t_element_name ); 123 $writer->writeAttribute( 'id', $t_value ); 124 $writer->text( $t_element_data ); 125 $writer->endElement( ); 126 127 break; 128 129 case 'eta': 130 case 'priority': 131 case 'projection': 132 case 'reproducibility': 133 case 'resolution': 134 case 'severity': 135 case 'status': 136 case 'view_state': 137 $t_element_data = get_enum_element( $t_element, $t_value ); 138 139 $writer->startElement( $t_element ); 140 $writer->writeAttribute( 'id', $t_value ); 141 $writer->text( $t_element_data ); 142 $writer->endElement( ); 143 break; 144 145 default: 146 $writer->writeElement( $t_element, $t_value ); 147 } 148 } 149 150 # fetch and export custom fields 151 $t_custom_fields = custom_field_get_all_linked_fields( $t_row->id ); 152 if ( is_array( $t_custom_fields ) && count( $t_custom_fields ) > 0 ) { 153 $writer->startElement( 'custom_fields' ); 154 foreach ( $t_custom_fields as $custom_field_name => $t_custom_field ) { 155 $writer->startElement( 'custom_field' ); 156 # id 157 $writer->writeElement( 'id', custom_field_get_id_from_name( $custom_field_name ) ); 158 # title 159 $writer->writeElement( 'name', $custom_field_name ); 160 # filename 161 $writer->writeElement( 'type', $t_custom_field['type'] ); 162 # filesize 163 $writer->writeElement( 'value', $t_custom_field['value'] ); 164 # file_type 165 $writer->writeElement( 'access_level_r', $t_custom_field['access_level_r'] ); 166 167 $writer->endElement(); # custom_field 168 } 169 $writer->endElement(); # custom_fields 170 } 171 172 # fetch and export bugnotes 173 $t_bugnotes = bugnote_get_all_bugnotes( $t_row->id ); 174 if ( is_array( $t_bugnotes ) && count( $t_bugnotes ) > 0 ) { 175 $writer->startElement( 'bugnotes' ); 176 foreach ( $t_bugnotes as $t_bugnote ) { 177 $writer->startElement( 'bugnote' ); 178 # id 179 $writer->writeElement( 'id', $t_bugnote->id ); 180 # reporter 181 $writer->startElement( 'reporter' ); 182 $writer->writeAttribute( 'id', $t_bugnote->reporter_id ); 183 $writer->text( user_get_name( $t_bugnote->reporter_id ) ); 184 $writer->endElement( ); 185 # bug note 186 $writer->writeElement( 'note', $t_bugnote->note ); 187 # view state 188 $writer->startElement( 'view_state' ); 189 $writer->writeAttribute( 'id', $t_bugnote->view_state ); 190 $writer->text( get_enum_element( 'view_state', $t_bugnote->view_state ) ); 191 $writer->endElement( ); 192 # date submitted 193 $writer->writeElement( 'date_submitted', $t_bugnote->date_submitted ); 194 # last modified 195 $writer->writeElement( 'last_modified', $t_bugnote->last_modified ); 196 # note type 197 $writer->writeElement( 'note_type', $t_bugnote->note_type ); 198 # note attr 199 $writer->writeElement( 'note_attr', $t_bugnote->note_attr ); 200 # time tracking 201 $writer->writeElement( 'time_tracking', $t_bugnote->time_tracking ); 202 203 $writer->endElement(); # bugnote 204 } 205 $writer->endElement(); # bugnotes 206 } 207 208 # fetch and export attachments 209 $t_attachments = bug_get_attachments( $t_row->id ); 210 if ( is_array( $t_attachments ) && count( $t_attachments ) > 0 ) { 211 $writer->startElement( 'attachments' ); 212 foreach ( $t_attachments as $t_attachment ) { 213 $writer->startElement( 'attachment' ); 214 # id 215 $writer->writeElement( 'id', $t_attachment['id'] ); 216 # title 217 $writer->writeElement( 'title', $t_attachment['title'] ); 218 # filename 219 $writer->writeElement( 'filename', $t_attachment['filename'] ); 220 # filesize 221 $writer->writeElement( 'filesize', $t_attachment['filesize'] ); 222 # file_type 223 $writer->writeElement( 'file_type', $t_attachment['file_type'] ); 224 # last added 225 $writer->writeElement( 'date_added', $t_attachment['date_added'] ); 226 # content 227 $content = file_get_content( $t_attachment['id'] ); 228 229 $writer->writeElement( 'content', base64_encode( $content['content'] ) ); 230 231 $writer->endElement(); # attachment 232 } 233 $writer->endElement(); # bugnotes 234 } 235 236 $writer->endElement(); # issue 237 238 // Save memory by clearing cache 239 //bug_clear_cache(); 240 //bug_text_clear_cache(); 241 } 242 243 $writer->endElement(); # mantis 244 $writer->endDocument( );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |