r1377: - Added Logging::getCommonFields()
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Jan 2007 23:41:43 +0000 (23:41 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Jan 2007 23:41:43 +0000 (23:41 +0000)
- We have an untested mass update system

includes/class_logging.php
search.php

index f81c24a8105038188aa891d8fc09fb39ba90d794..782eb2fe4e4539347f47168c0ca22e3083a3518a 100644 (file)
@@ -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'
+               );
+       }
 }
 
 /*=====================================================================*\
index f73d3a8e8d43666bc8eabad8e551db3b0608b2af..c976aaa72b3fdaf548d7d423a1a1c477ef334695 100644 (file)
@@ -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'])