From 15a8578e7f21920db07af9c348b0c1c5b018de87 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 11 Feb 2007 21:26:13 +0000 Subject: [PATCH] r1392: Lots of work going into making the custom fields part of the bug table and not part of bugvaluefill: 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). --- admin/field.php | 4 +- docs/migrate_custom_fields.php | 24 +++++++++++ editreport.php | 48 +++++++-------------- includes/api_bug.php | 20 ++++++++- includes/api_field.php | 4 +- includes/class_notification.php | 18 +------- includes/functions.php | 62 ++++++++------------------- newreport.php | 13 ++---- showhistory.php | 8 ++-- showreport.php | 4 +- templates/bugfield_input_checkbox.tpl | 2 +- templates/bugfield_input_text.tpl | 2 +- templates/bugfield_select_single.tpl | 2 +- 13 files changed, 95 insertions(+), 116 deletions(-) create mode 100644 docs/migrate_custom_fields.php diff --git a/admin/field.php b/admin/field.php index bc1ad54..2c27ca0 100644 --- a/admin/field.php +++ b/admin/field.php @@ -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 index 0000000..3385441 --- /dev/null +++ b/docs/migrate_custom_fields.php @@ -0,0 +1,24 @@ +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 diff --git a/editreport.php b/editreport.php index e2ee512..15ce28a 100644 --- a/editreport.php +++ b/editreport.php @@ -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(); diff --git a/includes/api_bug.php b/includes/api_bug.php index 66c62a3..7c4affd 100644 --- a/includes/api_bug.php +++ b/includes/api_bug.php @@ -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']); diff --git a/includes/api_field.php b/includes/api_field.php index 83c2645..8743659 100644 --- a/includes/api_field.php +++ b/includes/api_field.php @@ -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(); } diff --git a/includes/class_notification.php b/includes/class_notification.php index 69f5697..8eb062b 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -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"]); - } - } } // ################################################################### diff --git a/includes/functions.php b/includes/functions.php index f64674d..a713d2c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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 ####################### diff --git a/newreport.php b/newreport.php index a39157b..2ac89be 100755 --- a/newreport.php +++ b/newreport.php @@ -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')) { diff --git a/showhistory.php b/showhistory.php index 90b28f2..ba70f78 100644 --- a/showhistory.php +++ b/showhistory.php @@ -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)) diff --git a/showreport.php b/showreport.php index 8402c72..2ce7cf0 100644 --- a/showreport.php +++ b/showreport.php @@ -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" ); diff --git a/templates/bugfield_input_checkbox.tpl b/templates/bugfield_input_checkbox.tpl index d6dd245..5045a99 100644 --- a/templates/bugfield_input_checkbox.tpl +++ b/templates/bugfield_input_checkbox.tpl @@ -1,6 +1,6 @@
$field[name] $help[field$field[fieldid]] -
custom[$field[fieldid]]field$field[fieldid]" type="checkbox" value="1"$selected />
+
custom[$field[fieldid]]custom$field[fieldid]" type="checkbox" value="1"$selected />
\ No newline at end of file diff --git a/templates/bugfield_input_text.tpl b/templates/bugfield_input_text.tpl index ba67a76..69da9d0 100644 --- a/templates/bugfield_input_text.tpl +++ b/templates/bugfield_input_text.tpl @@ -1,6 +1,6 @@
$field[name] $help[field$field[fieldid]] -
custom[$field[fieldid]]field$field[fieldid]" type="text" value="$value" size="35"maxlength="$field[maxlength] />
+
custom[$field[fieldid]]custom$field[fieldid]" type="text" value="$value" size="35"maxlength="$field[maxlength] />
diff --git a/templates/bugfield_select_single.tpl b/templates/bugfield_select_single.tpl index ecd66d1..80dd971 100644 --- a/templates/bugfield_select_single.tpl +++ b/templates/bugfield_select_single.tpl @@ -1,6 +1,6 @@
$field[name] $help[field$field[fieldid]] -
+
\ No newline at end of file -- 2.43.5