[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/admin/ -> copy_field.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   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  # This upgrade moves attachments from the database to the disk
  17  
  18  /**
  19   * @package MantisBT
  20   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  21   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  22   * @link http://www.mantisbt.org
  23   */
  24  /**
  25   * MantisBT Core API's
  26   */
  27  require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
  28  
  29  access_ensure_global_level( config_get_global( 'admin_site_threshold' ) );
  30  
  31  $f_source_field_id = gpc_get_int( 'source_id' );
  32  $f_dest_field = gpc_get( 'dest_id' );
  33  ?>
  34  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35  <html>
  36  <head>
  37  <title> MantisBT Administration - Copy Custom Fields to Built-in </title>
  38  <link rel="stylesheet" type="text/css" href="admin.css" />
  39  </head>
  40  <body>
  41  
  42  <table width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
  43      <tr class="top-bar">
  44          <td class="links">
  45              [ <a href="system_utils.php">Back to System Utilities</a> ]
  46              [ <a href="copy_field.php?source_id=<?php echo $f_source_field_id?>&amp;dest_id=<?php echo $f_dest_field?>">Refresh view</a> ]
  47          </td>
  48          <td class="title">
  49              MantisBT Administration - Copy Custom Fields to Built-in
  50          </td>
  51      </tr>
  52  </table>
  53  <br /><br />
  54  
  55  <?php
  56  # checks on validity
  57  $t_valid_fields = array(
  58      'fixed_in_version',
  59  );
  60  if( !in_array( $f_dest_field, $t_valid_fields ) ) {
  61      echo '<p>Invalid destination field (' . $f_dest_field . ') specified.</p>';
  62      echo '</body></html>';
  63      exit;
  64  }
  65  
  66  # @@@ check that source and destination are compatible
  67  
  68  $t_string_table = db_get_table( 'custom_field_string' );
  69  $t_bug_table = db_get_table( 'bug' );
  70  $query = 'SELECT * FROM ' . $t_string_table . ' WHERE field_id = ' . db_param() . ' and value <> ' . db_param();
  71  
  72  $result = @db_query_bound( $query, Array( $f_source_field_id, '' ) );
  73  if( FALSE == $result ) {
  74      echo '<p>No fields need to be updated.</p>';
  75  }
  76  else {
  77  
  78      $count = db_num_rows( $result );
  79      echo '<p>Found ' . $count . ' fields to be updated.</p>';
  80      $t_failures = 0;
  81  
  82      if( $count > 0 ) {
  83          echo '<table width="80%" bgcolor="#222222" cellpadding="10" cellspacing="1">';
  84  
  85          # Headings
  86          echo '<tr bgcolor="#ffffff"><th width="10%">Bug Id</th><th width="20%">Field Value</th><th width="70%">Status</th></tr>';
  87      }
  88  
  89      for( $i = 0;$i < $count;$i++ ) {
  90          $row = db_fetch_array( $result );
  91          extract( $row, EXTR_PREFIX_ALL, 'v' );
  92  
  93          # trace bug id back to project
  94          $t_project_id = bug_get_field( $v_bug_id, 'project_id' );
  95          $t_cust_value = $v_value;
  96          printf("\n<tr %s><td><a href=\"../view.php?id=%d\">%07d</a></td><td>%s</td><td>",
  97              helper_alternate_class(), $v_bug_id, $v_bug_id, $v_value);
  98  
  99          # validate field contents
 100          switch( $f_dest_field ) {
 101              case 'fixed_in_version':
 102                  $t_valid = ( version_get_id( $t_cust_value, $t_project_id ) == FALSE ) ? FALSE : TRUE;
 103                  break;
 104              default:
 105                  $t_valid = FALSE;
 106          }
 107          if( $t_valid ) {
 108  
 109              # value was valid, update value
 110              if( !bug_set_field( $v_bug_id, $f_dest_field, $t_cust_value ) ) {
 111                  echo 'database update failed';
 112                  $t_failures++;
 113              } else {
 114                  echo 'applied';
 115              }
 116          } else {
 117              echo 'field value was not valid or previously defined';
 118              $t_failures++;
 119          }
 120          echo '</td></tr>';
 121      }
 122  
 123      echo '</table><br />' . $count . ' fields processed, ' . $t_failures . ' failures';
 124  }
 125  echo '<p> Completed...<p>';
 126  ?>
 127  </body>
 128  </html>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7