2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 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 ©2002 - 2007, Blue Static
36 class BugAPI
extends BSApi
42 protected $fields = array(
43 'bugid' => array(TYPE_UINT
, REQ_AUTO
),
44 'userid' => array(TYPE_UINT
, REQ_NO
),
45 'username' => array(TYPE_STR
, REQ_NO
),
46 'dateline' => array(TYPE_UINT
, REQ_SET
),
47 'product' => array(TYPE_UINT
, REQ_YES
),
48 'component' => array(TYPE_UINT
, REQ_NO
),
49 'version' => array(TYPE_UINT
, REQ_YES
),
50 'summary' => array(TYPE_STR
, REQ_YES
),
51 'priority' => array(TYPE_UINT
, REQ_NO
),
52 'severity' => array(TYPE_UINT
, REQ_NO
),
53 'status' => array(TYPE_UINT
, REQ_NO
),
54 'resolution' => array(TYPE_UINT
, REQ_NO
),
55 'assignedto' => array(TYPE_UINT
, REQ_NO
),
56 'duplicateof' => array(TYPE_STR
, REQ_NO
),
57 'dependency' => array(TYPE_STR
, REQ_NO
),
58 'hidden' => array(TYPE_BOOL
, REQ_NO
),
59 'initialreport' => array(TYPE_UINT
, REQ_NO
),
60 'lastposttime' => array(TYPE_UINT
, REQ_NO
),
61 'lastpostby' => array(TYPE_UINT
, REQ_NO
),
62 'lastpostbyname' => array(TYPE_STR
, REQ_NO
),
63 'hiddenlastposttime' => array(TYPE_UINT
, REQ_NO
),
64 'hiddenlastpostby' => array(TYPE_UINT
, REQ_NO
),
65 'hiddenlastpostbyname' => array(TYPE_STR
, REQ_NO
)
72 protected $table = 'bug';
78 protected $prefix = TABLE_PREFIX
;
81 * Subclassed set() that will intercept any custom fields and handle
82 * them appropriately, but everyting else will be passed to the parent.
84 function set($field, $value, $doclean = true
, $doverify = true
)
86 // it's a custom field, so add it in
87 if (preg_match('/^custom/', $field) == 1 && !isset($this->fields
["$field"]))
89 $this->fields
["$field"] = array(TYPE_STR
, REQ_NO
);
92 // TODO - (r1524) one day we can change this back to call_user_func_array(array($this, 'parent::set'), func_get_args())
93 parent
::set($field, $value, $doclean, $doverify);
99 protected function set_dateline()
101 $this->set('dateline', time());
107 protected function post_insert()
109 BSApp
::$db->query("INSERT INTO " . TABLE_PREFIX
. "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid
. ", 0, 0)");
115 protected function post_delete()
117 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "comment WHERE bugid = " . $this->values
['bugid']);
118 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "favorite WHERE bugid = " . $this->values
['bugid']);
119 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "history WHERE bugid = " . $this->values
['bugid']);
120 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "vote WHERE bugid = " . $this->values
['bugid']);
126 protected function validate_product($field)
128 if (!$this->_verifyIsNotZero('product'))
133 if (!bugdar
::$datastore['product'][$this->values
['product']])
135 $this->_error(new FieldException(L_INVALID_ID
, $field));
143 * Verify: componentid
145 protected function validate_component($field)
147 if ($this->values
['component'] != 0)
149 $component = bugdar
::$datastore['component'][ $this->values
['component'] ];
150 $product = bugdar
::$datastore['product'][ $this->values
['product'] ];
151 $version = bugdar
::$datastore['version'][ $this->values
['version'] ];
152 if ($component['parentid'] != $product['productid'])
154 $this->_error(new FieldException(L_INVALID_ID
, $field));
157 if (($version['productid'] != $component['productid'] && $version['productid'] != $product['productid']) && $version['productid'] != 0)
159 $this->_error(new FieldException(L_INVALID_ID
, $field));
169 protected function validate_version()
171 if ($this->_verifyIsNotZero('version'))
176 if (!bugdar
::$datastore['version'][ $this->values
['version'] ])
178 $this->_error(new FieldException(L_INVALID_ID
, $field));
187 protected function validate_priority()
189 if (!bugdar
::$datastore['priority'][ $this->values
['priority'] ])
191 $this->set('priority', bugdar
::$options['defaultpriority']);
201 protected function validate_severity()
203 if (!bugdar
::$datastore['severity'][ $this->values
['severity'] ])
205 $this->set('severity', bugdar
::$options['defaultseverity']);
213 protected function validate_status()
215 if (!bugdar
::$datastore['status'][ $this->values
['status'] ])
217 $this->set('status', bugdar
::$options['defaultstatus']);
225 protected function validate_resolution()
227 if (!bugdar
::$datastore['resolution'][ $this->values
['resolution'] ])
229 $this->set('resolution', bugdar
::$options['defaultresolve']);
239 protected function validate_assignedto()
241 if (!bugdar
::$datastore['assignto'][ $this->values
['assignedto'] ] && $this->values
['assignedto'] != 0)
243 $this->set('assignedto', bugdar
::$options['defaultassign']);
249 /*=====================================================================*\
250 || ###################################################################
253 || ###################################################################
254 \*=====================================================================*/