r1399: - Searches no longer store the actual DB query but rather the parameters for...
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 13 Feb 2007 02:33:06 +0000 (02:33 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 13 Feb 2007 02:33:06 +0000 (02:33 +0000)
- Modified process_custom_fields() to no longer worry about custom data input
- Added a flag in process_custom_fields() for $searchMode
- The mass-update feature now works, except for logging

docs/changes.txt
docs/todo.txt
includes/functions.php
search.php

index f470b5162dc08f5bfbebcdace17ea30940dd9fe3..4af03b0e2810af38c09e5326e7466669c2c13602 100644 (file)
@@ -14,6 +14,8 @@
 - Move custom field data into the bug table to reduce the use of JOINs
 - Remove a query on userctrl.php's save options called by build_assignedto() because the API already does this for us
 - Setting system cleanup that improves speed by reducing queries and not using eval()
+- Can now mass update of bug fields from the search screen
+- Search system no longer stores the actual query of the search, but rather the paramters
 
 1.1.5
 ===============================
index 700c7f2064800c9a8c4282bae6f7be973657d63f..3079a9edeb07ba7048fff3b0f64422ca136edc01 100755 (executable)
@@ -5,7 +5,6 @@ SVN: $Id$
 ###############################################################################
 BUGDAR 1.2
 
-- Mass updates and deletes
 - Importing from other bug systems (bug://report/41)
 - Workflow interface
 
index a713d2c8469cade3fbb9a242b865bdaaf2bc86f8..0604580deb99771f96e7ee0a5f1f5e9c94eaf75c 100755 (executable)
@@ -337,11 +337,11 @@ function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefau
 * @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
+* @param       bool    Search mode: don't change certain fields when they're 0 or empty
 *
 * @return      mixed   NULL if an ID is passed, string if bugid is NULL
 */
-function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $inputdata = array())
+function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $searchMode = false)
 {
        global $bugsys;
        
@@ -363,11 +363,15 @@ function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $inputdata =
                $fieldname = "custom$field[fieldid]";
                if ($field['type'] == 'input_checkbox')
                {
+                       if ($searchMode AND intval($inputdata["$fieldname"]) == 0)
+                       {
+                               continue;
+                       }
                        $bugapi->set($fieldname, intval(isset($inputdata["$fieldname"])));
                        continue;
                }
                                
-               if ($field['required'] AND empty($inputdata["$fieldname"]))
+               if ($field['required'] AND empty($inputdata["$fieldname"]) AND !$searchMode)
                {
                        $errorlist[] = sprintf(_('The "%1$s" field is a required field.'), $field['name']);
                        continue;
@@ -383,16 +387,23 @@ function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $inputdata =
                }
                
                if (isset($inputdata["$fieldname"]))
-               {                       
+               {
                        if ($field['type'] == 'input_text')
                        {
+                               if (empty($inputdata["$fieldname"]) AND $searchMode)
+                               {
+                                       continue;
+                               }
                                $bugapi->set($fieldname, $inputdata["$fieldname"]);
                        }
                        else
                        {
                                if ($inputdata["$fieldname"] == -1)
                                {
-                                       $bugapi->set($fieldname, '');
+                                       if (!$searchMode)
+                                       {
+                                               $bugapi->set($fieldname, '');
+                                       }
                                        continue;
                                }
                                
index 8c5a0702f12d0e207f427c15479a18adcd013d22..d32ce571f9c71074f8f8984dfb2f7842b4d2f8ed 100644 (file)
@@ -37,6 +37,7 @@ $focus['search'] = 'focus';
 require_once('./global.php');
 require_once('./includes/functions_product.php');
 require_once('./includes/class_sort.php');
+require_once('./includes/class_logging.php');
 require_once('./includes/api_bug.php');
 require_once('./includes/class_api_error.php');
 
@@ -47,9 +48,9 @@ if (!can_perform('cansearch'))
        $message->error_permission();
 }
 
-define('MODE_ANY', ($bugsys->in['mode'] == 1));
-define('MODE_ALL', ($bugsys->in['mode'] == 2));
-define('MODE_RAW', ($bugsys->in['mode'] == 3));
+define('MODE_ANY', 1);
+define('MODE_ALL', 2);
+define('MODE_RAW', 3);
 
 $var = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'");
 define('SEARCH_WORD_MIN', $var['Value']);
@@ -67,6 +68,108 @@ if (empty($_REQUEST['do']))
 
 // ###################################################################
 
+if ($_REQUEST['do'] == 'search')
+{
+       if ($bugsys->in['new'])
+       {
+               $newsearch = true;
+       }
+       else if ($bugsys->in['searchid'])
+       {
+               $cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
+       }
+       else if ($bugsys->userinfo['userid'])
+       {
+               $cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']);
+       }
+       else
+       {
+               $newsearch = true;
+       }
+       
+       if ($cachedsearch)
+       {
+               $show['cached'] = true;
+               if ($cachedsearch['dateline'] < TIMNOW - 900 OR $bugsys->in['rerun'])
+               {
+                       $_REQUEST['do'] = 'process';
+                       $bugsys->in = array_merge(unserialize($cachedsearch['query']), $bugsys->in);
+               }
+               else
+               {
+                       $search = $cachedsearch;
+                       $_POST['do'] = 'results';
+               }       
+       }
+       else
+       {
+               $newsearch = true;
+       }
+       
+       if ($newsearch)
+       {
+               if (!is_array($bugsys->datastore['product']))
+               {
+                       $message->error(_('No products are setup, therefore there can be no bugs and thus search cannot function.'));
+               }
+               
+               if (!is_array($bugsys->datastore['version']))
+               {
+                       $message->error(_('No versions have been added underneath your product(s), there can be no bugs and thus search cannot function.'));
+               }
+               
+               $productSelect = ConstructProductSelect();
+               
+               // -------------------------------------------------------------------
+               // 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');
+               $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
+               $select['status'] = construct_datastore_select('status', 'status', 'statusid');
+               $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
+               
+               $searches = '';
+               if ($bugsys->userinfo['userid'])
+               {
+                       $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . $bugsys->userinfo['userid']);
+                       while ($search = $db->fetch_array($searchesFetch))
+                       {
+                               $value = $search['searchid'];
+                               $label = $search['name'];
+                               eval('$searches .= "' . $template->fetch('selectoption') . '";');
+                       }
+               }
+               
+               $select['dev'] = '';
+               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') . '");');
+       }
+}
+
+// ###################################################################
+
 if ($_REQUEST['do'] == 'process')
 {
        // -------------------------------------------------------------------
@@ -84,7 +187,7 @@ if ($_REQUEST['do'] == 'process')
                                continue;
                        }
                        
-                       if (MODE_ALL)
+                       if ($bugsys->in['mode'] == MODE_ALL)
                        {
                                $querybuild['text'] .= " +$word";
                        }
@@ -105,7 +208,7 @@ if ($_REQUEST['do'] == 'process')
                
                $temp = trim($querybuild['text']);
                
-               if (MODE_ALL OR MODE_RAW)
+               if ($bugsys->in['mode'] == MODE_ALL OR $bugsys->in['mode'] == MODE_RAW)
                {
                        $bool_flag = ' IN BOOLEAN MODE';
                }
@@ -259,21 +362,26 @@ if ($_REQUEST['do'] == 'process')
        
        // -------------------------------------------------------------------
        // do the search
-       $query = "
+       
+       $search = $db->query("
                SELECT bug.*, comment.commentid
                FROM " . TABLE_PREFIX . "bug AS bug
                LEFT JOIN "  . TABLE_PREFIX . "comment AS comment
                        ON (bug.bugid = comment.bugid)
                WHERE bug.bugid <> 0
-               AND bug.product IN (#<'ONBITS:VIEW'>#)
-               AND (!bug.hidden OR (bug.hidden AND bug.product IN (#<'ONBITS:HIDDEN'>#))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (#<'ONBITS:OWNHIDDEN'>#))" : "") . ")
+               AND bug.product IN (" . fetch_on_bits('canviewbugs') . ")
+               AND
+               (
+                       !bug.hidden
+                               OR
+                       (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? "
+                               OR
+                       (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewonhidden') . "))" : "") . "
+               )
                " . implode("\n\t\t", $querybuild) . "
                GROUP BY bug.bugid
-               $sortclause";
-       
-       $runquery = str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewonhidden')), $query);
-       
-       $search = $db->query($runquery);
+               $sortclause
+       ");
        
        $numrows = $db->num_rows($search);
        
@@ -288,124 +396,40 @@ if ($_REQUEST['do'] == 'process')
                $results[] = $result;
        }
                
-       if ($bugsys->userinfo['userid'])
+       if ($bugsys->userinfo['userid'] AND $cachedsearch['name'] == null AND !$bugsys->in['rerun'])
        {
                $db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid'] . " AND name IS NULL");
        }
        
-       $db->query("
-               INSERT INTO " . TABLE_PREFIX . "search
-                       (userid, dateline, query, ids, orderby, hilight, resultcount)
-               VALUES
-                       (" . $bugsys->userinfo['userid'] . ",
-                       " . TIMENOW . ", '" . $bugsys->escape($query) . "',
-                       '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
-                       '" . $bugsys->escape($hilight) . "',
-                       " . sizeof($results) . "
-               )"
-       );
-       
-       $searchid = $db->insert_id();
-       
-       $justprocess = true;
-       $search = array('ids' => implode(',', $ids), 'orderby' => $sortclause);
-       
-       $_POST['do'] = 'results';
-}
-
-// ###################################################################
-
-if ($_REQUEST['do'] == 'search')
-{
-       if ($bugsys->in['searchid'] AND !$bugsys->in['new'])
+       // store the search params
+       $params = $bugsys->in;
+       foreach ($_COOKIE AS $key => $value)
        {
-               if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']))
-               {
-                       $_POST['do'] = 'results';
-                       $searchid = $cachedsearch['searchid'];
-               }
-               else
-               {
-                       $newsearch = true;
-               }
+               unset($params["$key"]);
        }
-       else if ($bugsys->userinfo['userid'] AND !$bugsys->in['new'])
+       
+       if ($cachedsearch)
        {
-               if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']))
-               {
-                       $_POST['do'] = 'results';
-                       $searchid = $cachedsearch['searchid'];
-               }
-               else
-               {
-                       $newsearch = true;
-               }
+               $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', resultcount = " . sizeof($results) . " WHERE searchid = " . $cachedsearch['searchid']);
+               $search = $cachedsearch;
        }
        else
        {
-               $newsearch = true;
+               $db->query("
+                       INSERT INTO " . TABLE_PREFIX . "search
+                               (userid, dateline, query, ids, orderby, hilight, resultcount)
+                       VALUES
+                               (" . $bugsys->userinfo['userid'] . ",
+                               " . TIMENOW . ", '" . $bugsys->escape(serialize($params)) . "',
+                               '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
+                               '" . $bugsys->escape($hilight) . "',
+                               " . sizeof($results) . "
+                       )"
+               );
+               $search = array('searchid' => $db->insert_id(), 'ids' => implode(',', $ids), 'orderby' => $sortclause, 'hilight' => $hilight, 'resultcount' => sizeof($results));
        }
        
-       if ($newsearch)
-       {
-               if (!is_array($bugsys->datastore['product']))
-               {
-                       $message->error(_('No products are setup, therefore there can be no bugs and thus search cannot function.'));
-               }
-               
-               if (!is_array($bugsys->datastore['version']))
-               {
-                       $message->error(_('No versions have been added underneath your product(s), there can be no bugs and thus search cannot function.'));
-               }
-               
-               $productSelect = ConstructProductSelect();
-               
-               // -------------------------------------------------------------------
-               // 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');
-               $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
-               $select['status'] = construct_datastore_select('status', 'status', 'statusid');
-               $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
-               
-               $searches = '';
-               if ($bugsys->userinfo['userid'])
-               {
-                       $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . $bugsys->userinfo['userid']);
-                       while ($search = $db->fetch_array($searchesFetch))
-                       {
-                               $value = $search['searchid'];
-                               $label = $search['name'];
-                               eval('$searches .= "' . $template->fetch('selectoption') . '";');
-                       }
-               }
-               
-               $select['dev'] = '';
-               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') . '");');
-       }
+       $_POST['do'] = 'results';
 }
 
 // ###################################################################
@@ -492,6 +516,9 @@ if ($_POST['do'] == 'doupdate')
                }
                                
                $api = new BugApi($bugsys);
+               $api->set('bugid', $bug['bugid']);
+               $api->set_condition();
+               
                $log = new Logging();
                $log->set_bugid($bug['bugid']);
                $log->add_data(true, $bug, $log->getCommonFields());
@@ -514,7 +541,7 @@ if ($_POST['do'] == 'doupdate')
                }
                if ($bugsys->in['assignedto'] AND can_perform('canassign', $bug['product']))
                {
-                       $api->set('severity',   $bugsys->in['severity']);
+                       $api->set('assignedto', $bugsys->in['assignedto']);
                }
                if ($bugsys->in['product'])
                {
@@ -524,15 +551,15 @@ if ($_POST['do'] == 'doupdate')
                        $api->set('version',    $product[2]);
                }
                
-               $log->add_data(false, $api->values, $log->getCommonFields());
-               
-               process_custom_fields($api, $message);
+               process_custom_fields($api, $message, false, true);
                
+               $log->add_data(false, $api->values, $log->getCommonFields());
+                               
                $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']);
+       $message->redirect(_('The specified bugs have been updated and you will now return to your search results.'), 'search.php?searchid=' . $bugsys->in['searchid']);
 }
 
 // ###################################################################
@@ -645,31 +672,15 @@ if ($_REQUEST['do'] == 'save')
 // ###################################################################
 
 if ($_POST['do'] == 'results')
-{
-       $show['cached'] = false;
-       if ($searchid AND !$justprocess)
-       {
-               $search = $cachedsearch;
-               if ($search['dateline'] < TIMENOW - 900 OR $bugsys->in['rerun'])
-               {
-                       $research = $db->query(str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewownhidden')), $search['query']));
-                       while ($bug = $db->fetch_array($research))
-                       {
-                               $ids[] = $bug['bugid'];
-                               $results[] = $bug;
-                       }
-                       $search['ids'] = implode(',', $ids);
-                       $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW . ", resultcount = " . sizeof($results) . " WHERE searchid = " . $search['searchid']);
-               }
-               $show['cached'] = true;
-               $hilight = $search['hilight'];
-       }
-       
+{      
        if (!$search['ids'])
        {
                $message->error(_('No bugs matched your search criteria. Please <a href="search.php?new=1">try again</a> with different search requirements.'));
        }
        
+       $searchid = $search['searchid'];
+       $hilight = $search['hilight'];
+               
        LoadPaginationFramework();
        $pagination->setTotal($search['resultcount']);
        $pagination->splitPages();