Skip to content

Commit

Permalink
added additional utility in the admin area
Browse files Browse the repository at this point in the history
0004078: Script to import the value of a custom field to a native field


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2756 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
thraxisp committed Jul 25, 2004
1 parent 898e768 commit 2feaa3e
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 5 deletions.
102 changes: 102 additions & 0 deletions admin/copy_field.php
@@ -0,0 +1,102 @@
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details

# This upgrade moves attachments from the database to the disk

# --------------------------------------------------------
# $Id: copy_field.php,v 1.1 2004-07-25 00:13:08 thraxisp Exp $
# --------------------------------------------------------
?>
<?php
require_once( '../core.php' );

$f_source = gpc_get_int( 'source_id' );
$f_dest = gpc_get( 'dest_id' );
?>
<html>
<head>
<title> Mantis Administration - Copy Custom Fields to Built-in </title>
<link rel="stylesheet" type="text/css" href="admin.css" />
</head>
<body>

<table width="100%" border="0" 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">Refresh view</a> ]
</td>
<td class="title">
Mantis Administration - Copy Custom Fields to Built-in
</td>
</tr>
</table>
<br /><br />

<?php
#checks on validity
#@@@ check that source and destination are compatible

$t_string_table = config_get( 'mantis_custom_field_string_table' );
$t_bug_table = config_get( 'mantis_bug_table' );
$query = 'SELECT * FROM ' . $t_string_table . ' WHERE field_id = ' . $f_source . ' and value <> \'\'';

$result = @db_query( $query );
if ( false == $result ) {
echo '<p>No fields need to be updated.';
}else{

$count = db_num_rows( $result );
echo '<p>Found ' . $count . ' fields to be updated.';
$t_failures = 0;

if ( $count > 0 ) {
echo '<table width="80%" bgcolor="#222222" border="0" 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_bug_id = $v_bug_id;
$t_cust_value = $v_value;
printf("\n<tr %s><td>%8d</td><td>%s</td><td>", helper_alternate_class(), $t_bug_id, $v_value);

switch ( $f_dest ) {
case 'fixed in':
$t_version_id = version_get_id( $t_cust_value, $t_project_id );
if ( $t_version_id <> FALSE ) {
# it matched, update value
$query2 = "UPDATE $t_bug_table SET fixed_in_version = '$t_cust_value' WHERE id = $t_bug_id";
$update = @db_query( $query2 );
if ( ! $update ) {
echo 'database update failed';
$t_failures++;
}else{
echo 'applied';
}
}else{
echo 'no matching version found';
$t_failures++;
}
break;
# other conversions go here
default:
}
echo '</td></tr>';
}

echo '</table><br />' . $count . ' fields processed, ' . $t_failures . ' failures';
}
echo '<p> Completed...';
?>
</body>
</html>
35 changes: 30 additions & 5 deletions admin/system_utils.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: system_utils.php,v 1.1 2004-07-23 23:20:16 vboctor Exp $
# $Id: system_utils.php,v 1.2 2004-07-25 00:13:08 thraxisp Exp $
# --------------------------------------------------------
?>
<?php
Expand Down Expand Up @@ -40,14 +40,39 @@

<!-- each row links to an upgrade
move database bug attachments to disk -->
<tr bgcolor="#ffffff"><td>Move attachments stored in database schema to disk files.</td><td>
<tr bgcolor="#ffffff"><td>Move attachments stored in database schema to disk files.</td><td><center>
<?php html_button( 'move_db2disk.php', 'Move Attachments to Disk', array( 'doc' => 'attachment') ); ?>
</td></tr>
</center></td></tr>

<!-- move database project files to disk -->
<tr bgcolor="#ffffff"><td>Move project files stored in database schema to disk.</td><td>
<tr bgcolor="#ffffff"><td>Move project files stored in database schema to disk.</td><td><center>
<?php html_button( 'move_db2disk.php', 'Move Project Files to Disk', array( 'doc' => 'project') ); ?>
</td></tr>
</center></td></tr>

<!-- move custom field content to standard field -->
<tr bgcolor="#ffffff"><td>Copy Custom Field to Standard Field.</td><td><center>
<form method="post" action="copy_field.php">
From
<SELECT name="source_id">
<?php
$t_custom_ids = custom_field_get_ids();
foreach ( $t_custom_ids as $t_id ) {
printf("<OPTION VALUE=\"%d\">%s", $t_id, custom_field_get_field($t_id, 'name' ) );
}
?>
</SELECT> to
<SELECT name="dest_id">
<?php
$t_dest_ids = array('fixed in'); # @@@ should be expanded and configurable
foreach ( $t_dest_ids as $t_id ) {
printf("<OPTION VALUE=\"%s\">%s", $t_id, $t_id );
}
?>
</SELECT>
<input type="submit" class="button" value="Copy" >
</form>
</center></td></tr>


</table>
</body>
Expand Down
1 change: 1 addition & 0 deletions doc/ChangeLog
Expand Up @@ -19,6 +19,7 @@ Mantis ChangeLog
- 0004175: [bugtracker] Links are not hyperlinked properly if containing '[' or ']' (vboctor)
- 0004182: [bugtracker] print_all_bug_page should show all issues matching current filter (vboctor)
- 0003714: [upgrade] Please add in a way to transfer attachments from the database to disk (thraxisp)
- 0004078: [upgrade] Script to import the value of a custom field to a native field (thraxisp)
- 0003877: [email] Upgrade to PHPMailer 1.72 (vboctor)
- 0002220: [installation] usage of consistent naming schema for images (vboctor)
- New Config: main_menu_custom_options (default empty) - Allow addition of custom menu options to main menu (vboctor)
Expand Down

0 comments on commit 2feaa3e

Please sign in to comment.