Updating api_bug.php, fix a "call to undefined" error in class_notification.php and...
[bugdar.git] / includes / api_bug.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23
24 /**
25 * API: Bug
26 *
27 * Note: When priority, severity, status, and resolution should throw a
28 * verification error, they actually set it to the default value
29 *
30 * @author Blue Static
31 * @copyright Copyright ©2002 - 2007, Blue Static
32 * @version $Revision$
33 * @package Bugdar
34 *
35 */
36 class BugAPI extends BSApi
37 {
38 /**
39 * Database fields
40 * @var array
41 */
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)
66 );
67
68 /**
69 * Database table
70 * @var string
71 */
72 protected $table = 'bug';
73
74 /**
75 * Table prefix
76 * @var string
77 */
78 protected $prefix = TABLE_PREFIX;
79
80 /**
81 * Subclassed set() that will intercept any custom fields and handle
82 * them appropriately, but everyting else will be passed to the parent.
83 */
84 function set($field, $value, $doclean = true, $doverify = true)
85 {
86 // it's a custom field, so add it in
87 if (preg_match('/^custom/', $field) == 1 && !isset($this->fields["$field"]))
88 {
89 $this->fields["$field"] = array(TYPE_STR, REQ_NO);
90 }
91
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);
94 }
95
96 /**
97 * Set field: dateline
98 */
99 protected function set_dateline()
100 {
101 $this->set('dateline', time());
102 }
103
104 /**
105 * Post-insert
106 */
107 protected function post_insert()
108 {
109 BSApp::$db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)");
110 }
111
112 /**
113 * Post-delete
114 */
115 protected function post_delete()
116 {
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']);
121 }
122
123 /**
124 * Verify: product
125 */
126 protected function validate_product($field)
127 {
128 if (!$this->_verifyIsNotZero('product'))
129 {
130 return false;
131 }
132
133 if (!bugdar::$datastore['product'][$this->values['product']])
134 {
135 $this->_error(new FieldException(L_INVALID_ID, $field));
136 return false;
137 }
138
139 return true;
140 }
141
142 /**
143 * Verify: componentid
144 */
145 protected function validate_component($field)
146 {
147 if ($this->values['component'] != 0)
148 {
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'])
153 {
154 $this->_error(new FieldException(L_INVALID_ID, $field));
155 return false;
156 }
157 if (($version['productid'] != $component['productid'] && $version['productid'] != $product['productid']) && $version['productid'] != 0)
158 {
159 $this->_error(new FieldException(L_INVALID_ID, $field));
160 return false;
161 }
162 }
163 return true;
164 }
165
166 /**
167 * Verify: versionid
168 */
169 protected function validate_version()
170 {
171 if ($this->_verifyIsNotZero('version'))
172 {
173 return false;
174 }
175
176 if (!bugdar::$datastore['version'][ $this->values['version'] ])
177 {
178 $this->_error(new FieldException(L_INVALID_ID, $field));
179 return false;
180 }
181 return true;
182 }
183
184 /**
185 * Verify: priority
186 */
187 protected function validate_priority()
188 {
189 if (!bugdar::$datastore['priority'][ $this->values['priority'] ])
190 {
191 $this->set('priority', bugdar::$options['defaultpriority']);
192 }
193 return true;
194 }
195
196 /**
197 * Verify: severity
198 *
199 * @access private
200 */
201 protected function validate_severity()
202 {
203 if (!bugdar::$datastore['severity'][ $this->values['severity'] ])
204 {
205 $this->set('severity', bugdar::$options['defaultseverity']);
206 }
207 return true;
208 }
209
210 /**
211 * Verify: status
212 */
213 protected function validate_status()
214 {
215 if (!bugdar::$datastore['status'][ $this->values['status'] ])
216 {
217 $this->set('status', bugdar::$options['defaultstatus']);
218 }
219 return true;
220 }
221
222 /**
223 * Verify: resolution
224 */
225 protected function validate_resolution()
226 {
227 if (!bugdar::$datastore['resolution'][ $this->values['resolution'] ])
228 {
229 $this->set('resolution', bugdar::$options['defaultresolve']);
230 }
231 return true;
232 }
233
234 /**
235 * Verify: assignedto
236 *
237 * @access private
238 */
239 protected function validate_assignedto()
240 {
241 if (!bugdar::$datastore['assignto'][ $this->values['assignedto'] ] && $this->values['assignedto'] != 0)
242 {
243 $this->set('assignedto', bugdar::$options['defaultassign']);
244 }
245 return true;
246 }
247 }
248
249 /*=====================================================================*\
250 || ###################################################################
251 || # $HeadURL$
252 || # $Id$
253 || ###################################################################
254 \*=====================================================================*/
255 ?>