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).
$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
{
--- /dev/null
+<?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
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)
);
$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;
$message->error_permission();
}
- $log->add_data(true, $bugapi->objdata, $bugfields);
+ $log->add_data(true, $bugapi->objdata, $excludeFields, true);
// -------------------------------------------------------------------
// handle automations
$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();
*/
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
*/
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']);
{
$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();
}
* 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']))
{
$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"]);
- }
- }
}
// ###################################################################
}
}
- $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT));
-
$fieldbits = array();
foreach ($fields AS $field)
$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
{
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')
}
else
{
- $value = $fieldvalues["field$field[fieldid]"];
+ $value = $bug["custom$field[fieldid]"];
}
}
else
}
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') . '";');
// ###################################################################
/**
-* 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;
);
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;
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"]) ]));;
}
}
}
$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 #######################
$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']);
$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)
{
$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();
$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'))
{
$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'))
{
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']);
}
// ###################################################################
$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))
// -------------------------------------------------------------------
// 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"
);
<!-- 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
<!-- 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] -->
<!-- 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