r1392: Lots of work going into making the custom fields part of the bug table and...
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 11 Feb 2007 21:26:13 +0000 (21:26 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 11 Feb 2007 21:26:13 +0000 (21:26 +0000)
Updated process_custom_fields(), the the client code for logging and notifications, the code for bug creation and editing, and history viewing.

Needs to be done still: searching, logging and notification API updates, help documentation, and general cleanup (like making search field names the same as bug modification field names).

13 files changed:
admin/field.php
docs/migrate_custom_fields.php [new file with mode: 0644]
editreport.php
includes/api_bug.php
includes/api_field.php
includes/class_notification.php
includes/functions.php
newreport.php
showhistory.php
showreport.php
templates/bugfield_input_checkbox.tpl
templates/bugfield_input_text.tpl
templates/bugfield_select_single.tpl

index bc1ad5468d53d145f8a99de18287b89d149a02e8..2c27ca01d4213379457298093cdb49839bca901b 100644 (file)
@@ -113,8 +113,8 @@ if ($_REQUEST['do'] == 'update')
                $field->insert();
                $fieldid = $field->insertid;
                
-               $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL");
-               $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill");
+               $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD custom$fieldid MEDIUMTEXT NULL");
+               $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug");
        }
        else
        {
diff --git a/docs/migrate_custom_fields.php b/docs/migrate_custom_fields.php
new file mode 100644 (file)
index 0000000..3385441
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+// migrates custom field data from bugvaluefill to bug
+// SVN $Id$
+
+chdir('../');
+require_once('global.php');
+
+// gets all the fields
+$fields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield");
+while ($field = $db->fetch_array($fields))
+{
+       // create the database field
+       $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD custom$field[fieldid] MEDIUMTEXT NULL");
+       
+       // update all the data
+       $data = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill");
+       while ($custom = $db->fetch_array($data))
+       {
+               $db->query("UPDATE " . TABLE_PREFIX . "bug SET custom$field[fieldid] = '" . $db->escape_string($custom["field$field[fieldid]"]) . "' WHERE bugid = $custom[bugid]");
+       }
+}
+
+?>
\ No newline at end of file
index e2ee512f464a626f89acf3a05efed51158120ab8..15ce28acc5add211a88513dfb1f2f3ffa87b2e55 100644 (file)
@@ -33,12 +33,10 @@ require_once('./includes/class_api_error.php');
 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
 
 $bug = $db->query_first("
-       SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
+       SELECT bug.*, user.email, user.displayname, user.showemail
        FROM " . TABLE_PREFIX . "bug AS bug
        LEFT JOIN " . TABLE_PREFIX . "user AS user
                ON (bug.userid = user.userid)
-       LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
-               ON (bug.bugid = bugvaluefill.bugid)
        WHERE bug.bugid = " . $bugsys->input_clean('bugid', TYPE_UINT)
 );
 
@@ -57,19 +55,14 @@ require_once('./includes/class_logging.php');
 $log = new Logging;
 $log->set_bugid($bug['bugid']);
 
-$bugfields = array(
-       'duplicateof',
-       'dependency',
-       'hidden',
-       'summary',
-       'status',
-       'severity',
-       'priority',
-       'version',
-       'assignedto'    => 'assignto',
-       'resolution',
-       'product',
-       'component'
+$excludeFields = array(
+       'bugid',
+       'lastposttime',
+       'lastpostby',
+       'lastpostbyname',
+       'hiddenlastposttime',
+       'hiddenlastpostby',
+       'hiddenlastpostbyname',
 );
 
 $notif = new NotificationCenter;
@@ -115,7 +108,7 @@ if ($_POST['do'] == 'update')
                $message->error_permission();
        }
        
-       $log->add_data(true, $bugapi->objdata, $bugfields);
+       $log->add_data(true, $bugapi->objdata, $excludeFields, true);
        
        // -------------------------------------------------------------------
        // handle automations
@@ -211,31 +204,22 @@ if ($_POST['do'] == 'update')
                $bugapi->set('assignedto',      $bugsys->in['assignedto']);
        }
        
-       $notif->set_bug_data($bugapi->objdata, $bugapi->values);
+       process_custom_fields($bugapi, $message, false);
        
        // -------------------------------------------------------------------
        // handle logging and perform updates
        
-       if ($fields = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"))
-       {
-               $log->add_data(true, $fields, array('bugid'), true, 'custom');
-       }
-       
-       $log->add_data(false, $bugapi->values, $bugfields);
-       
-       process_custom_fields($bug['bugid'], $message, false);
-       
+       $notif->set_bug_data($bugapi->objdata, $bugapi->values);
+       $log->add_data(false, $bugapi->values, $excludeFields, true);
+               
        $bugapi->update();
        
        // -------------------------------------------------------------------
        // do diff history
-       
-       $fieldsnew = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
-       $log->add_data(false, $fieldsnew, array('bugid'), true, 'custom');
-       
+
        $log->update_history();
        
-       $notif->send_bug_changes_notice($fields, $fieldsnew);
+       $notif->send_bug_changes_notice();
        
        $notif->finalize();
        
index 66c62a32fdfb1aada851766aebc3a77fe3167284..7c4affdd2a7cb9ae72a24b98234a77eea1848060 100644 (file)
@@ -80,6 +80,25 @@ class BugAPI extends API
        */
        var $prefix = TABLE_PREFIX;
        
+       // ###################################################################
+       /**
+       * Subclassed set() that will intercept any custom fields and handle
+       * them appropriately, but everyting else will be passed to the parent.
+       */
+       function set()
+       {
+               $args = func_get_args();
+               
+               // it's a custom field, so add it in
+               if (preg_match('#^custom#', $args[0]) == 1 AND !isset($this->fields["$args[0]"]))
+               {
+                       $this->fields["$args[0]"] = array(TYPE_STR, REQ_NO);
+                       print_r($args);
+               }
+               
+               call_user_func_array(array($this, 'parent::set'), $args);
+       }
+       
        // ###################################################################
        /**
        * Set field: dateline
@@ -110,7 +129,6 @@ class BugAPI extends API
        */
        function post_delete()
        {
-               $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . $this->values['bugid']);
                $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "comment WHERE bugid = " . $this->values['bugid']);
                $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE bugid = " . $this->values['bugid']);
                $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE bugid = " . $this->values['bugid']);
index 83c2645d216534698e3118b0c1e074eb7926c81a..87436594b93b5c828fbdbcb19077bc0595bff472 100644 (file)
@@ -129,8 +129,8 @@ class FieldAPI extends API
        {
                $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . $this->values['fieldid']);
                $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $this->values['fieldid']);
-               $this->registry->db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill DROP field" . $this->values['fieldid']);
-               $this->registry->db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill");
+               $this->registry->db->query("ALTER TABLE " . TABLE_PREFIX . "bug DROP custom" . $this->values['fieldid']);
+               $this->registry->db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug");
                
                build_user_help();
        }
index 69f5697c082f245e7394f60b8c0f6c704ea6423c..8eb062b3c70dc39d88c6893235724e49a1082e49 100644 (file)
@@ -213,11 +213,8 @@ class NotificationCenter
        * with the differences.
        *
        * @access       public
-       *
-       * @param        array   Original custom fields data
-       * @param        array   Modified custom fields data
        */
-       function send_bug_changes_notice($original, $modified)
+       function send_bug_changes_notice()
        {
                if (!isset($this->modified['bugid']))
                {
@@ -275,19 +272,6 @@ class NotificationCenter
                                $this->notice_other_change($field, $this->original["$field"], $this->modified["$field"]);
                        }
                }
-               
-               // custom field data
-               foreach ($modified AS $field => $value)
-               {
-                       if ($field == 'bugid')
-                       {
-                               continue;
-                       }
-                       if ($original["$field"] != $modified["$field"])
-                       {
-                               $this->notice_other_change($field, $original["$field"], $modified["$field"]);
-                       }
-               }
        }
        
        // ###################################################################
index f64674d3e39374afb6cb96a7b7d6217798c74463..a713d2c8469cade3fbb9a242b865bdaaf2bc86f8 100755 (executable)
@@ -214,8 +214,6 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
                }
        }
        
-       $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT));
-       
        $fieldbits = array();
        
        foreach ($fields AS $field)
@@ -225,10 +223,10 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
                        $field['defaultvalue'] = '';
                }
                
-               if (!is_null($bug["field$field[fieldid]"]))
+               if (!is_null($bug["custom$field[fieldid]"]))
                {
                        $bugsys->debug("not null: $field[fieldid]");
-                       $value = $bug["field$field[fieldid]"];
+                       $value = $bug["custom$field[fieldid]"];
                }
                else
                {
@@ -292,7 +290,7 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
                else
                {
                        $bugsys->debug('mask 1 processing');
-                       if (is_null($fieldvalues["field$field[fieldid]"]))
+                       if (is_null($bug["custom$field[fieldid]"]))
                        {
                                $bugsys->debug("is null: $field[fieldid]");
                                if ($field['type'] == 'select_single')
@@ -304,7 +302,7 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
                                        }
                                        else
                                        {
-                                               $value = $fieldvalues["field$field[fieldid]"];
+                                               $value = $bug["custom$field[fieldid]"];
                                        }
                                }
                                else
@@ -314,12 +312,12 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
                        }
                        else
                        {
-                               $value = $fieldvalues["field$field[fieldid]"];
+                               $value = $bug["custom$field[fieldid]"];
                        }
                                        
                        if ($field['type'] == 'input_checkbox')
                        {
-                               $value = (($value) ? 'True' : 'False');
+                               $value = ($value ? 'True' : 'False');
                        }
                        $field['value'] = $value;
                        eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
@@ -332,18 +330,18 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
 
 // ###################################################################
 /**
-* This takes the bug ID and input data and then sanitizes, verifies,
+* This takes the bug API object and input data and then sanitizes, verifies,
 * and processes the data for custom fields. If there are any errors,
 * they are passed to the message reporter.
 *
-* @param       integer The bug ID; if NULL, then it returns a query that needs to have %1$s replaced with the bug ID, otherwise it executes the query itself
+* @param       object  A BugAPI object
 * @param       object  MessageReporter object
 * @param       bool    If there are errors, add them to an errorbox format? If not, then display-on-encounter
 * @param       array   If you don't want to get the data from $bugsys->in[], then an optional input source
 *
 * @return      mixed   NULL if an ID is passed, string if bugid is NULL
 */
-function process_custom_fields($bugid, $msg, $errorbox = false, $inputdata = array())
+function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $inputdata = array())
 {
        global $bugsys;
        
@@ -362,21 +360,14 @@ function process_custom_fields($bugid, $msg, $errorbox = false, $inputdata = arr
        );
        while ($field = $bugsys->db->fetch_array($fields))
        {
+               $fieldname = "custom$field[fieldid]";
                if ($field['type'] == 'input_checkbox')
                {
-                       $fieldbuild[] = 'field' . $field['fieldid'];
-                       if (isset($inputdata["field$field[fieldid]"]))
-                       {
-                               $fieldvalue[] = 1;
-                       }
-                       else
-                       {
-                               $fieldvalue[] = 0;
-                       }
+                       $bugapi->set($fieldname, intval(isset($inputdata["$fieldname"])));
                        continue;
                }
                                
-               if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
+               if ($field['required'] AND empty($inputdata["$fieldname"]))
                {
                        $errorlist[] = sprintf(_('The "%1$s" field is a required field.'), $field['name']);
                        continue;
@@ -384,31 +375,29 @@ function process_custom_fields($bugid, $msg, $errorbox = false, $inputdata = arr
                
                if (!empty($field['regexmatch']))
                {
-                       if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["field$field[fieldid]"]))
+                       if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["$fieldname"]))
                        {
                                $errorlist[] = sprintf(_('%1$s does not match the specified format'), $field['name']);
                                continue;
                        }
                }
                
-               if (isset($inputdata["field$field[fieldid]"]))
-               {
-                       $fieldbuild[] = 'field' . $field['fieldid'];
-                       
+               if (isset($inputdata["$fieldname"]))
+               {                       
                        if ($field['type'] == 'input_text')
                        {
-                               $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
+                               $bugapi->set($fieldname, $inputdata["$fieldname"]);
                        }
                        else
                        {
-                               if ($inputdata["field$field[fieldid]"] == -1)
+                               if ($inputdata["$fieldname"] == -1)
                                {
-                                       $fieldvalue[] = "''";
+                                       $bugapi->set($fieldname, '');
                                        continue;
                                }
                                
                                $temp = unserialize($field['selects']);
-                               $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
+                               $bugapi->set($fieldname, trim($temp[ intval($inputdata["$fieldname"]) ]));;
                        }
                }
        }
@@ -427,19 +416,6 @@ function process_custom_fields($bugid, $msg, $errorbox = false, $inputdata = arr
                        $msg->error($errorlist[0]);
                }
        }
-       
-       if (sizeof($fieldbuild) < 1)
-       {
-               return;
-       }
-       
-       $query = "REPLACE INTO " . TABLE_PREFIX . "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES (%1\$s, " . implode(', ', $fieldvalue) . ")";
-       if ($bugid === null)
-       {
-               return $query;
-       }
-       
-       $bugsys->db->query(sprintf($query, $bugid));
 }
 
 // ####################### Start fetch_on_bits #######################
index a39157b7fc3a1231ad0dc6743ab5e6ac9d392767..2ac89bec961d9ca3642d4a17b27ec91d667c4584 100755 (executable)
@@ -56,7 +56,7 @@ if ($_POST['do'] == 'insert')
        $bug = new BugAPI($bugsys);
        $comment = new CommentAPI($bugsys);
        
-       $notif = new NotificationCenter;
+       $notif = new NotificationCenter();
                
        $bug->set('userid',                     $bugsys->userinfo['userid']);
        $bug->set('username',           $bugsys->userinfo['displayname']);
@@ -96,7 +96,7 @@ if ($_POST['do'] == 'insert')
        $bug->set('component',          $product[1]);
        $bug->set('version',            $product[2]);
        
-       $cfields = process_custom_fields(null, $message, true);
+       process_custom_fields($bug, $message, true);
        
        if (!$message->items)
        {
@@ -122,11 +122,6 @@ if ($_POST['do'] == 'insert')
                $bug->set('hiddenlastpostbyname',       $bugsys->userinfo['displayname']);
                $bug->update();
                
-               if ($cfields)
-               {
-                       $db->query(sprintf($cfields, $comment->values['bugid']));
-               }
-               
                $notif->set_bug_data($bug->objdata);
                
                $notif->finalize();
@@ -156,7 +151,7 @@ if ($_REQUEST['do'] == 'add')
        
        $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
 
-       $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
+       $show['changestatus'] = can_perform('canchangestatus');
        
        if (can_perform('canchangestatus'))
        {
@@ -165,7 +160,7 @@ if ($_REQUEST['do'] == 'add')
                $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
        }
        
-       $show['assign'] = ((can_perform('canassign')) ? true : false);
+       $show['assign'] = can_perform('canassign');
        
        if (can_perform('canassign'))
        {
index 90b28f2b6d5032b816c20e14a7db4861713b4b46..ba70f78d51560f13c9fc68cc63780cefbf4c1eb7 100644 (file)
@@ -65,7 +65,7 @@ $customfields = $db->query("
 
 while ($field = $db->fetch_array($customfields))
 {
-       $fieldlist["custom.field$field[fieldid]"] = sprintf(_('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
+       $fieldlist["$field[fieldid]"] = sprintf(_('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
 }
 
 // ###################################################################
@@ -114,11 +114,11 @@ foreach ($logs AS $dateline => $logitems)
                                $log['field'] = sprintf(_('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
                        }
                }
-               else if (preg_match('#^custom.field([0-9]+?)#', $log['field'], $matches))
+               else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
                {
-                       if ($fieldlist["$log[field]"])
+                       if ($fieldlist["$matches[2]"])
                        {
-                               $log['field'] = $fieldlist["$log[field]"];
+                               $log['field'] = $fieldlist["$matches[2]"];
                        }
                }
                else if (preg_match('#^\.(.*)#', $log['field'], $matches))
index 8402c72396067a88a6e2506c973f390e90fdd8ae..2ce7cf0728671e0e8f0e45f67fcc299249b85e2c 100644 (file)
@@ -62,12 +62,10 @@ if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
 // -------------------------------------------------------------------
 // get the report
 $bug = $db->query_first("
-       SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
+       SELECT bug.*, user.email, user.displayname, user.showemail
        FROM " . TABLE_PREFIX . "bug AS bug
        LEFT JOIN " . TABLE_PREFIX . "user AS user
                ON (bug.userid = user.userid)
-       LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
-               ON (bug.bugid = bugvaluefill.bugid)
        WHERE bug.bugid = $bugid"
 );
 
index d6dd245f77f7cf9b3b8d081bd023f18cce9b1522..5045a99b30059ecf17b4f5f70f05241f642f6762 100644 (file)
@@ -1,6 +1,6 @@
        <!-- custom field$field[fieldid] -->
        <fieldset>
                <legend>$field[name] $help[field$field[fieldid]]</legend>
-               <div class="field"><if condition="$searchMode"><select name="<if condition="$show['search']">custom[$field[fieldid]]<else />field$field[fieldid]</if>"><option value="0">{@"Ignore"}</option><option value="1">{@"Yes"}</option><option value="-1">{@"No"}</option></select><else /><input name="<if condition="$show['search']">custom[$field[fieldid]]<else />field$field[fieldid]</if>" type="checkbox" value="1"$selected /></if></div>
+               <div class="field"><if condition="$searchMode"><select name="<if condition="$show['search']">custom[$field[fieldid]]<else />field$field[fieldid]</if>"><option value="0">{@"Ignore"}</option><option value="1">{@"Yes"}</option><option value="-1">{@"No"}</option></select><else /><input name="<if condition="$show['search']">custom[$field[fieldid]]<else />custom$field[fieldid]</if>" type="checkbox" value="1"$selected /></if></div>
        </fieldset>
        <!-- / custom field$field[fieldid] -->
\ No newline at end of file
index ba67a76a2e5da603133e058d0278b2a6d94875af..69da9d0d39e18660878b1410e7cf9bcf45df033e 100644 (file)
@@ -1,6 +1,6 @@
        <!-- custom field$field[fieldid] -->
        <fieldset>
                <legend>$field[name] $help[field$field[fieldid]]</legend>
-               <div class="field"><input name="<if condition="$show['search']">custom[$field[fieldid]]<else />field$field[fieldid]</if>" type="text" value="$value" size="35"<if condition="$field['maxlength']">maxlength="$field[maxlength]</if> /></div>
+               <div class="field"><input name="<if condition="$show['search']">custom[$field[fieldid]]<else />custom$field[fieldid]</if>" type="text" value="$value" size="35"<if condition="$field['maxlength']">maxlength="$field[maxlength]</if> /></div>
        </fieldset>
        <!-- / custom field$field[fieldid] -->
index ecd66d1318d90d31579a8d94d26784273c873988..80dd9711a95663945790bf2e0af4e096fc2cef73 100644 (file)
@@ -1,6 +1,6 @@
        <!-- custom field$field[fieldid] -->
        <fieldset>
                <legend>$field[name] $help[field$field[fieldid]]</legend>
-               <div class="field"><select name="<if condition="$show['search']">custom[$field[fieldid]]<else />field$field[fieldid]</if>">$options</select></div>
+               <div class="field"><select name="<if condition="$show['search']">custom[$field[fieldid]]<else />custom$field[fieldid]</if>">$options</select></div>
        </fieldset>
        <!-- / custom field$field[fieldid] -->
\ No newline at end of file