Skip to content

Commit

Permalink
XML import/export plugin fixes
Browse files Browse the repository at this point in the history
This resolves a number of warnings and notices with the plugin when
strict error reporting.

As far as I can tell, the fixes mentioned in issue #12013 after dhx
committed the changes (8401753), i.e.
bugnotes are not needed:
- ~28391 by schoppi71: don't think this is a bug
- ~28855 by ninguno: already included in dhx's commit
  • Loading branch information
dregad committed Oct 27, 2013
2 parents bdb6e9a + aca7cdf commit de607de
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/file_api.php
Expand Up @@ -1021,7 +1021,7 @@ function file_get_content( $p_file_id, $p_type = 'bug' ) {
$result = db_query_bound( $query, array( $p_file_id ) );
$row = db_fetch_array( $result );

if ( $f_type == 'bug' ) {
if( $p_type == 'bug' ) {
$t_project_id = bug_get_field( $row['bug_id'], 'project_id' );
} else {
$t_project_id = $row['bug_id'];
Expand Down
1 change: 1 addition & 0 deletions plugins/XmlImportExport/ImportXml.php
Expand Up @@ -171,6 +171,7 @@ public function import( ) {
printf( "Processing cross-references for %s issues...", count( $importedIssues ) );
foreach( $importedIssues as $oldId => $newId ) {
$bugData = bug_get( $newId, true );
$content_replaced = false;

$bugLinkRegexp = '/(^|[^\w])(' . preg_quote( $this->source_->issuelink, '/' ) . ')(\d+)\b/e';
// replace links in description
Expand Down
39 changes: 29 additions & 10 deletions plugins/XmlImportExport/ImportXml/Issue.php
Expand Up @@ -23,8 +23,8 @@
*/


require_once( 'bug_api.php' );
require_once( 'user_api.php' );
require_api( 'bug_api.php' );
require_api( 'user_api.php' );
require_once( 'Interface.php' );

/**
Expand Down Expand Up @@ -71,6 +71,10 @@ public function process( XMLreader $reader ) {
$t_project_id = helper_get_current_project(); // TODO: category_get_id_by_name could work by default on current project
$userId = auth_get_current_user_id( );

$t_custom_fields = array();
$t_bugnotes = array();
$t_attachments = array();

$depth = $reader->depth;
while( $reader->read() &&
($reader->depth > $depth ||
Expand Down Expand Up @@ -153,7 +157,7 @@ public function process( XMLreader $reader ) {
$reader->nodeType != XMLReader::END_ELEMENT ) ) {
if ( $reader->nodeType == XMLReader::ELEMENT ) {
if ($reader->localName == 'custom_field') {
$i++;
$t_custom_fields[++$i] = new stdClass();
}
switch ( $reader->localName ) {
default:
Expand All @@ -174,7 +178,7 @@ public function process( XMLreader $reader ) {
$reader->nodeType != XMLReader::END_ELEMENT ) ) {
if ( $reader->nodeType == XMLReader::ELEMENT ) {
if ($reader->localName == 'bugnote') {
$i++;
$t_bugnotes[++$i] = new stdClass();
}
switch ( $reader->localName ) {
case 'reporter':
Expand Down Expand Up @@ -207,7 +211,7 @@ public function process( XMLreader $reader ) {
$reader->nodeType != XMLReader::END_ELEMENT ) ) {
if ( $reader->nodeType == XMLReader::ELEMENT ) {
if ($reader->localName == 'attachment') {
$i++;
$t_attachments[++$i] = new stdClass();
}
switch ( $reader->localName ) {
default:
Expand Down Expand Up @@ -249,7 +253,19 @@ public function process( XMLreader $reader ) {
// add bugnotes
if ( $this->new_id_ > 0 && is_array( $t_bugnotes ) && count( $t_bugnotes ) > 0 ) {
foreach ( $t_bugnotes as $t_bugnote) {
bugnote_add( $this->new_id_, $t_bugnote->note, $t_bugnote->time_tracking, $t_bugnote->private, $t_bugnote->note_type, $t_bugnote_>note_attr, $t_bugnote->reporter_id, false, $t_bugnote->date_submitted, $t_bugnote->last_modified, true );
bugnote_add(
$this->new_id_,
$t_bugnote->note,
$t_bugnote->time_tracking,
$t_bugnote->private,
$t_bugnote->note_type,
$t_bugnote->note_attr,
$t_bugnote->reporter_id,
false,
$t_bugnote->date_submitted,
$t_bugnote->last_modified,
true
);
}
}

Expand All @@ -259,10 +275,13 @@ public function process( XMLreader $reader ) {
// Create a temporary file in the temporary files directory using sys_get_temp_dir()
$temp_file_name = tempnam( sys_get_temp_dir(), 'MantisImport' );
file_put_contents( $temp_file_name, base64_decode( $t_attachment->content ) );
$file_data = array( 'name' => $t_attachment->filename,
'type' => $t_attachment->file_type,
'tmp_name' => $temp_file_name,
'size' => filesize( $temp_file_name ) );
$file_data = array(
'name' => $t_attachment->filename,
'type' => $t_attachment->file_type,
'tmp_name' => $temp_file_name,
'size' => filesize( $temp_file_name ),
'error' => UPLOAD_ERR_OK,
);
// unfortunately we have no clue who has added the attachment (this could only be fetched from history -> feel free to implement this)
// also I have no clue where description should come from...
file_add( $this->new_id_, $file_data, 'bug', $t_attachment->title, $p_desc = '', $p_user_id = null, $t_attachment->date_added, true );
Expand Down
2 changes: 1 addition & 1 deletion plugins/XmlImportExport/lang/strings_english.txt
Expand Up @@ -50,7 +50,7 @@ $s_plugin_XmlImportExport_description = 'Adds XML based import and export capabi
$s_plugin_XmlImportExport_import = 'Import issues';
$s_plugin_XmlImportExport_export = 'XML Export';

$s_plugin_XmlImportExport_importing_in_project = 'Importing issues in project:';
$s_plugin_XmlImportExport_importing_in_project = 'Importing issues into project: \'%s\'';
$s_plugin_XmlImportExport_import_options = 'Import options';

$s_plugin_XmlImportExport_cross_references = 'Cross references';
Expand Down
9 changes: 6 additions & 3 deletions plugins/XmlImportExport/pages/import.php
Expand Up @@ -43,17 +43,20 @@

?>

<div class="center">
<div class="table-container">
<form name="file_upload" method="post" enctype="multipart/form-data" action="<?php echo plugin_page( 'import_action' )?>">
<?php echo form_security_field( 'plugin_xml_import_action' ) ?>

<input type="hidden" name="project_id" value="<?php echo $t_project_id;?>" />

<table class="width100">
<table>
<tr>
<td class="form-title" colspan="2">
<?php
echo plugin_lang_get( 'importing_in_project' ) . ' ' . string_display( project_get_field( $t_project_id, 'name' ) );
printf(
plugin_lang_get( 'importing_in_project' ),
string_display( project_get_field( $t_project_id, 'name' ) )
);
?>
</td>
</tr>
Expand Down
13 changes: 11 additions & 2 deletions plugins/XmlImportExport/pages/import_action.php
Expand Up @@ -46,8 +46,17 @@

print_manage_menu( 'manage_import_issues_page.php' );

echo "<pre>\n";
?>

<br />

<pre>

<?php
$importer->import( );
echo "</pre>\n";
?>

</pre>

<?php
html_page_bottom();

0 comments on commit de607de

Please sign in to comment.