From 65e60cfed6312628682c5ead4bfaa5fef051619f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Sep 2008 12:24:40 -0400 Subject: [PATCH] Updating api_bug.php, fix a "call to undefined" error in class_notification.php and making editreport.php work better --- editreport.php | 16 ++- includes/api_bug.php | 184 ++++++++++++++------------------ includes/class_notification.php | 6 +- 3 files changed, 87 insertions(+), 119 deletions(-) diff --git a/editreport.php b/editreport.php index 2ca297c..a3fb714 100644 --- a/editreport.php +++ b/editreport.php @@ -29,8 +29,6 @@ require_once('./includes/class_notification.php'); require_once('./includes/api_bug.php'); require_once('./includes/api_comment.php'); -APIError(array(new API_Error_Handler($message), 'user_cumulative')); - $bug = $db->queryFirst(" SELECT bug.*, user.email, user.displayname, user.showemail FROM " . TABLE_PREFIX . "bug AS bug @@ -51,15 +49,13 @@ if (!check_bug_permissions($bug)) // setup logging require_once('./includes/class_logging.php'); -$log = new Logging; +$log = new Logging(); $log->set_bugid($bug['bugid']); -$notif = new NotificationCenter; +$notif = new NotificationCenter(); $bugapi = new BugAPI(); -$bugapi->set('bugid', $input->in['bugid']); -$bugapi->set_condition(); -$bugapi->dorelations = array(); +$bugapi->set('bugid', $input->in['bugid']); $bugapi->fetch(); // ################################################################### @@ -71,7 +67,7 @@ if ($_POST['do'] == 'kill') $message->errorPermission(); } - $bugapi->delete(); + $bugapi->remove(); $message->redirect(T('The entire bug has been deleted.'), 'index.php'); } @@ -92,7 +88,7 @@ if ($_REQUEST['do'] == 'delete') if ($_POST['do'] == 'update') { - if (!((can_perform('caneditown', $bug['product']) AND bugdar::$userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND bugdar::$userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['product'])) + if (!((can_perform('caneditown', $bug['product']) && bugdar::$userinfo['userid'] == $bug['userid']) || (can_perform('caneditother', $bug['product']) && bugdar::$userinfo['userid'] != $bug['userid'])) && !can_perform('canpostcomments', $bug['product'])) { $message->errorPermission(); } @@ -174,7 +170,7 @@ if ($_POST['do'] == 'update') $dependencies = preg_split('#([^0-9].*?)#', $input->in['dependency'], -1, PREG_SPLIT_NO_EMPTY); $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies)); - if ((can_perform('caneditown', $bug['product']) AND bugdar::$userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND bugdar::$userinfo['userid'] != $bug['userid'])) + if ((can_perform('caneditown', $bug['product']) && bugdar::$userinfo['userid'] == $bug['userid']) || (can_perform('caneditother', $bug['product']) && bugdar::$userinfo['userid'] != $bug['userid'])) { $bugapi->set('summary', $input->in['summary']); $bugapi->set('severity', $input->in['severity']); diff --git a/includes/api_bug.php b/includes/api_bug.php index a686623..0f1e1f6 100644 --- a/includes/api_bug.php +++ b/includes/api_bug.php @@ -36,24 +36,23 @@ require_once ISSO . '/Api.php'; class BugAPI extends BSApi { /** - * Database fields - * @var array - * @access private - */ - var $fields = array( - 'bugid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'), + * Database fields + * @var array + */ + protected $fields = array( + 'bugid' => array(TYPE_UINT, REQ_AUTO), 'userid' => array(TYPE_UINT, REQ_NO), 'username' => array(TYPE_STR, REQ_NO), 'dateline' => array(TYPE_UINT, REQ_SET), - 'product' => array(TYPE_UINT, REQ_YES, ':self'), - 'component' => array(TYPE_UINT, REQ_NO, ':self'), - 'version' => array(TYPE_UINT, REQ_YES, ':self'), - 'summary' => array(TYPE_STR, REQ_YES, 'verify_noempty'), - 'priority' => array(TYPE_UINT, REQ_NO, ':self'), - 'severity' => array(TYPE_UINT, REQ_NO, ':self'), - 'status' => array(TYPE_UINT, REQ_NO, ':self'), - 'resolution' => array(TYPE_UINT, REQ_NO, ':self'), - 'assignedto' => array(TYPE_UINT, REQ_NO, ':self', array('includes/api_user.php', 'UserAPI')), + 'product' => array(TYPE_UINT, REQ_YES), + 'component' => array(TYPE_UINT, REQ_NO), + 'version' => array(TYPE_UINT, REQ_YES), + 'summary' => array(TYPE_STR, REQ_YES), + 'priority' => array(TYPE_UINT, REQ_NO), + 'severity' => array(TYPE_UINT, REQ_NO), + 'status' => array(TYPE_UINT, REQ_NO), + 'resolution' => array(TYPE_UINT, REQ_NO), + 'assignedto' => array(TYPE_UINT, REQ_NO), 'duplicateof' => array(TYPE_STR, REQ_NO), 'dependency' => array(TYPE_STR, REQ_NO), 'hidden' => array(TYPE_BOOL, REQ_NO), @@ -67,28 +66,25 @@ class BugAPI extends BSApi ); /** - * Database table - * @var string - * @access private - */ - var $table = 'bug'; + * Database table + * @var string + */ + protected $table = 'bug'; /** - * Table prefix - * @var string - * @access private - */ - var $prefix = TABLE_PREFIX; + * Table prefix + * @var string + */ + protected $prefix = TABLE_PREFIX; - // ################################################################### /** - * Subclassed set() that will intercept any custom fields and handle - * them appropriately, but everyting else will be passed to the parent. - */ + * Subclassed set() that will intercept any custom fields and handle + * them appropriately, but everyting else will be passed to the parent. + */ function set($field, $value, $doclean = true, $doverify = true) { // it's a custom field, so add it in - if (preg_match('#^custom#', $field) == 1 AND !isset($this->fields["$field"])) + if (preg_match('/^custom/', $field) == 1 && !isset($this->fields["$field"])) { $this->fields["$field"] = array(TYPE_STR, REQ_NO); } @@ -97,35 +93,26 @@ class BugAPI extends BSApi parent::set($field, $value, $doclean, $doverify); } - // ################################################################### /** - * Set field: dateline - * - * @access private - */ - function set_dateline() + * Set field: dateline + */ + protected function set_dateline() { $this->set('dateline', time()); } - // ################################################################### /** - * Post-insert - * - * @access private - */ - function post_insert() + * Post-insert + */ + protected function post_insert() { BSApp::$db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)"); } - // ################################################################### /** - * Post-delete - * - * @access private - */ - function post_delete() + * Post-delete + */ + protected function post_delete() { BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "comment WHERE bugid = " . $this->values['bugid']); BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE bugid = " . $this->values['bugid']); @@ -133,78 +120,71 @@ class BugAPI extends BSApi BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "vote WHERE bugid = " . $this->values['bugid']); } - // ################################################################### /** - * Verify: product - * - * @access private - */ - function verify_product() + * Verify: product + */ + protected function validate_product($field) { - if (!($nozero = $this->verify_nozero('product'))) + if (!$this->_verifyIsNotZero('product')) { - return $nozero; + return false; } - if (!bugdar::$datastore['product'][ $this->values['product'] ]) + if (!bugdar::$datastore['product'][$this->values['product']]) { + $this->_error(new FieldException(L_INVALID_ID, $field)); return false; } + return true; } - // ################################################################### /** - * Verify: componentid - * - * @access private - */ - function verify_component() + * Verify: componentid + */ + protected function validate_component($field) { if ($this->values['component'] != 0) { - $component = bugdar::$datastore['component'][ $this->values['component'] ]; - $product = bugdar::$datastore['product'][ $this->values['product'] ]; - $version = bugdar::$datastore['version'][ $this->values['version'] ]; + $component = bugdar::$datastore['component'][ $this->values['component'] ]; + $product = bugdar::$datastore['product'][ $this->values['product'] ]; + $version = bugdar::$datastore['version'][ $this->values['version'] ]; if ($component['parentid'] != $product['productid']) { + $this->_error(new FieldException(L_INVALID_ID, $field)); return false; } - if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0) + if (($version['productid'] != $component['productid'] && $version['productid'] != $product['productid']) && $version['productid'] != 0) { + $this->_error(new FieldException(L_INVALID_ID, $field)); return false; } } return true; } - // ################################################################### /** - * Verify: versionid - * - * @access private - */ - function verify_version() + * Verify: versionid + */ + protected function validate_version() { - if (!($nozero = $this->verify_nozero('version'))) + if ($this->_verifyIsNotZero('version')) { - return $nozero; + return false; } if (!bugdar::$datastore['version'][ $this->values['version'] ]) { + $this->_error(new FieldException(L_INVALID_ID, $field)); return false; } return true; } - // ################################################################### /** - * Verify: priority - * - * @access private - */ - function verify_priority() + * Verify: priority + */ + protected function validate_priority() { if (!bugdar::$datastore['priority'][ $this->values['priority'] ]) { @@ -213,13 +193,12 @@ class BugAPI extends BSApi return true; } - // ################################################################### /** - * Verify: severity - * - * @access private - */ - function verify_severity() + * Verify: severity + * + * @access private + */ + protected function validate_severity() { if (!bugdar::$datastore['severity'][ $this->values['severity'] ]) { @@ -228,13 +207,10 @@ class BugAPI extends BSApi return true; } - // ################################################################### /** - * Verify: status - * - * @access private - */ - function verify_status() + * Verify: status + */ + protected function validate_status() { if (!bugdar::$datastore['status'][ $this->values['status'] ]) { @@ -243,13 +219,10 @@ class BugAPI extends BSApi return true; } - // ################################################################### /** - * Verify: resolution - * - * @access private - */ - function verify_resolution() + * Verify: resolution + */ + protected function validate_resolution() { if (!bugdar::$datastore['resolution'][ $this->values['resolution'] ]) { @@ -258,15 +231,14 @@ class BugAPI extends BSApi return true; } - // ################################################################### /** - * Verify: assignedto - * - * @access private - */ - function verify_assignedto() + * Verify: assignedto + * + * @access private + */ + protected function validate_assignedto() { - if (!bugdar::$datastore['assignto'][ $this->values['assignedto'] ] AND $this->values['assignedto'] != 0) + if (!bugdar::$datastore['assignto'][ $this->values['assignedto'] ] && $this->values['assignedto'] != 0) { $this->set('assignedto', bugdar::$options['defaultassign']); } diff --git a/includes/class_notification.php b/includes/class_notification.php index 0d76fd4..f56ddf3 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -506,8 +506,8 @@ class NotificationCenter public function finalize() { // get the current bug for permissions checks - $bug = BSApp::$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $this->bug['bugid']); - foreach ($this->_notices as $userid => $noticelist) + $bug = BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $this->bug['bugid']); + foreach ($this->notices as $userid => $noticelist) { if ($userid == bugdar::$userinfo['userid']) { @@ -536,7 +536,7 @@ class NotificationCenter if (!empty($this->users["$userid"]['email'])) { - $mail->send($this->users["$userid"]['email'], $this->users["$userid"]['displayname']); + $mail->send($this->users[$userid]['email'], $this->users[$userid]['displayname']); } else { -- 2.22.5