]>
src.bluestatic.org Git - bugdar.git/blob - includes/api_bug.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 require_once ISSO
. '/Api.php';
27 * Note: When priority, severity, status, and resolution should throw a
28 * verification error, they actually set it to the default value
31 * @copyright Copyright (c)2004 - 2009, Blue Static
35 class BugAPI
extends BSApi
41 protected $fields = array(
42 'bugid' => array(TYPE_UINT
, REQ_AUTO
),
43 'userid' => array(TYPE_UINT
, REQ_NO
),
44 'username' => array(TYPE_STR
, REQ_NO
),
45 'dateline' => array(TYPE_UINT
, REQ_SET
),
46 'product' => array(TYPE_UINT
, REQ_YES
),
47 'component' => array(TYPE_UINT
, REQ_NO
),
48 'version' => array(TYPE_UINT
, REQ_YES
),
49 'summary' => array(TYPE_STR
, REQ_YES
),
50 'priority' => array(TYPE_UINT
, REQ_NO
),
51 'severity' => array(TYPE_UINT
, REQ_NO
),
52 'status' => array(TYPE_UINT
, REQ_NO
),
53 'resolution' => array(TYPE_UINT
, REQ_NO
),
54 'assignedto' => array(TYPE_UINT
, REQ_NO
),
55 'duplicateof' => array(TYPE_STR
, REQ_NO
),
56 'dependency' => array(TYPE_STR
, REQ_NO
),
57 'hidden' => array(TYPE_BOOL
, REQ_NO
),
58 'initialreport' => array(TYPE_UINT
, REQ_NO
),
59 'lastposttime' => array(TYPE_UINT
, REQ_NO
),
60 'lastpostby' => array(TYPE_UINT
, REQ_NO
),
61 'lastpostbyname' => array(TYPE_STR
, REQ_NO
),
62 'hiddenlastposttime' => array(TYPE_UINT
, REQ_NO
),
63 'hiddenlastpostby' => array(TYPE_UINT
, REQ_NO
),
64 'hiddenlastpostbyname' => array(TYPE_STR
, REQ_NO
)
71 protected $table = 'bug';
77 protected $prefix = TABLE_PREFIX
;
80 * Subclassed set() that will intercept any custom fields and handle
81 * them appropriately, but everyting else will be passed to the parent.
83 function set($field, $value, $doclean = true, $doverify = true)
85 // it's a custom field, so add it in
86 if (preg_match('/^custom/', $field) == 1 && !isset($this->fields
["$field"]))
88 $this->fields["$field"] = array(TYPE_STR
, REQ_NO
);
91 // TODO - (r1524) one day we can change this back to call_user_func_array(array($this, 'parent::set'), func_get_args())
92 parent
::set($field, $value, $doclean, $doverify);
98 protected function set_dateline()
100 $this->set('dateline', time());
106 protected function post_insert()
108 BSApp
::$db->query("INSERT INTO " . TABLE_PREFIX
. "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid
. ", 0, 0)");
114 protected function post_delete()
116 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "comment WHERE bugid = " . $this->values
['bugid']);
117 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "favorite WHERE bugid = " . $this->values
['bugid']);
118 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "history WHERE bugid = " . $this->values
['bugid']);
119 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "vote WHERE bugid = " . $this->values
['bugid']);
125 protected function validate_product($field)
127 if (!$this->_verifyIsNotZero('product'))
132 if (!bugdar
::$datastore['product'][$this->values
['product']])
134 $this->_error(new FieldException(L_INVALID_ID
, $field));
142 * Verify: componentid
144 protected function validate_component($field)
146 if ($this->values
['component'] != 0)
148 $component = bugdar
::$datastore['component'][ $this->values
['component'] ];
149 $product = bugdar
::$datastore['product'][ $this->values
['product'] ];
150 $version = bugdar
::$datastore['version'][ $this->values
['version'] ];
151 if ($component['parentid'] != $product['productid'])
153 $this->_error(new FieldException(L_INVALID_ID
, $field));
156 if (($version['productid'] != $component['productid'] && $version['productid'] != $product['productid']) && $version['productid'] != 0)
158 $this->_error(new FieldException(L_INVALID_ID
, $field));
168 protected function validate_version()
170 if ($this->_verifyIsNotZero('version'))
175 if (!bugdar
::$datastore['version'][ $this->values
['version'] ])
177 $this->_error(new FieldException(L_INVALID_ID
, $field));
186 protected function validate_priority()
188 if (!bugdar
::$datastore['priority'][ $this->values
['priority'] ])
190 $this->set('priority', bugdar
::$options['defaultpriority']);
200 protected function validate_severity()
202 if (!bugdar
::$datastore['severity'][ $this->values
['severity'] ])
204 $this->set('severity', bugdar
::$options['defaultseverity']);
212 protected function validate_status()
214 if (!bugdar
::$datastore['status'][ $this->values
['status'] ])
216 $this->set('status', bugdar
::$options['defaultstatus']);
224 protected function validate_resolution()
226 if (!bugdar
::$datastore['resolution'][ $this->values
['resolution'] ])
228 $this->set('resolution', bugdar
::$options['defaultresolve']);
238 protected function validate_assignedto()
240 if (!bugdar
::$datastore['assignto'][ $this->values
['assignedto'] ] && $this->values
['assignedto'] != 0)
242 $this->set('assignedto', bugdar
::$options['defaultassign']);