From f3f23bb6a9b59d902fda589933c5dfcf384f8ceb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 21 Jan 2007 23:41:43 +0000 Subject: [PATCH] r1377: - Added Logging::getCommonFields() - We have an untested mass update system --- includes/class_logging.php | 26 +++++++ search.php | 134 +++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/includes/class_logging.php b/includes/class_logging.php index f81c24a..782eb2f 100644 --- a/includes/class_logging.php +++ b/includes/class_logging.php @@ -225,6 +225,32 @@ class Logging "); } } + + // ################################################################### + /** + * Returns an array of the common fields used by the logging mechanism + * + * @access public + * + * @return array Fields used in logging + */ + function getCommonFields() + { + return array( + 'duplicateof', + 'dependency', + 'hidden', + 'summary', + 'status', + 'severity', + 'priority', + 'version', + 'assignedto' => 'assignto', + 'resolution', + 'product', + 'component' + ); + } } /*=====================================================================*\ diff --git a/search.php b/search.php index f73d3a8..c976aaa 100644 --- a/search.php +++ b/search.php @@ -22,6 +22,7 @@ $fetchtemplates = array( 'search', 'search_results', + 'search_update', 'trackerhome_bits', 'list_head', 'pagenav_bit', @@ -35,6 +36,10 @@ $focus['search'] = 'focus'; require_once('./global.php'); require_once('./includes/functions_product.php'); require_once('./includes/class_sort.php'); +require_once('./includes/api_bug.php'); +require_once('./includes/class_api_error.php'); + +APIError(array($message, 'error')); if (!can_perform('cansearch')) { @@ -406,6 +411,135 @@ if ($_REQUEST['do'] == 'search') // ################################################################### +if ($_REQUEST['do'] == 'update') +{ + $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']); + if (!$search) + { + $message->error_permission(); + } + + $productSelect = ConstructProductSelect(); + + $show['update'] = true; + + // ------------------------------------------------------------------- + // custom fields + $fields = construct_custom_fields(null, true, false, true); + $i = 0; + foreach ($fields AS $field) + { + if ($i % 2 == 0) + { + $customfields['left'] .= $field; + } + else + { + $customfields['right'] .= $field; + } + $i++; + } + + // ------------------------------------------------------------------- + // built-in fields + $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', 0, 0); + $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', 0, 0); + $select['status'] = construct_datastore_select('status', 'status', 'statusid', 0, 0); + $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', 0, 0); + + $select['dev'] = ''; + $value = '0'; + $label = ''; + $selected = true; + eval('$select[dev] .= "' . $template->fetch('selectoption') . '";'); + $selected = false; + foreach ($bugsys->datastore['assignto'] AS $dev) + { + $value = $dev['userid']; + $label = construct_user_display($dev, false); + eval('$select[dev] .= "' . $template->fetch('selectoption') . '";'); + } + + eval('$template->flush("' . $template->fetch('search_update') . '");'); +} + +// ################################################################### + +if ($_POST['do'] == 'doupdate') +{ + $search = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']); + if (!$search) + { + $message->error_permission(); + } + + // find all the bugs that we can edit + $bugs = $db->query(" + SELECT * FROM " . TABLE_PREFIX . "bug + WHERE bugid IN ($search[ids]) + AND product IN (" . fetch_on_bits('canviewbugs') . ") + AND + ( + product IN (" . fetch_on_bits('caneditother') . ") + OR + (userid = " . $bugsys->userinfo['userid'] . " AND product IN (" . fetch_on_bits('caneditown') . ")) + ) + "); + while ($bug = $db->fetch_array($bugs)) + { + if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['product'])) + { + continue; + } + + // TODO - need to add logging for custom fields + + $api = new BugApi($bugsys); + $log = new Logging(); + $log->set_bugid($bug['bugid']); + $log->add_data(true, $bug, $log->getCommonFields()); + + if ($bugsys->in['status'] AND can_perform('canchangestatus', $bug['product'])) + { + $api->set('status', $bugsys->in['status']); + } + if ($bugsys->in['priority'] AND can_perform('canchangestatus', $bug['product'])) + { + $api->set('priority', $bugsys->in['priority']); + } + if ($bugsys->in['severity']) + { + $api->set('severity', $bugsys->in['severity']); + } + if ($bugsys->in['resolution'] AND can_perform('canchangestatus', $bug['product'])) + { + $api->set('resolution', $bugsys->in['resolution']); + } + if ($bugsys->in['assignedto'] AND can_perform('canassign', $bug['product'])) + { + $api->set('severity', $bugsys->in['severity']); + } + if ($bugsys->in['product']) + { + $product = explode(',', $bugsys->in['product']); + $api->set('product', $product[0]); + $api->set('component', $product[1]); + $api->set('version', $product[2]); + } + + $log->add_data(false, $api->values, $log->getCommonFields()); + + process_custom_fields($bug['bugid'], $message); + + $api->update(); + $log->update_history(); + } + + $message->redirect(_('The specified bugs have been updated and you will now return to your search results.'), 'search.php?do=results&searchid=' . $bugsys->in['searchid']); +} + +// ################################################################### + if ($_REQUEST['do'] == 'export') { if (!$bugsys->in['searchid'] AND $bugsys->userinfo['userid']) -- 2.22.5