r107731 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107730‎ | r107731 | r107732 >
Date:18:34, 31 December 2011
Author:mah
Status:deferred (Comments)
Tags:
Comment:
Create a way to get comments on bugs. Helped me clean up.
Modified paths:
  • /trunk/tools/bugzilla/client/bugzilla.php (modified) (history)

Diff [purge]

Index: trunk/tools/bugzilla/client/bugzilla.php
@@ -27,7 +27,6 @@
2828 $this->bz = $bz;
2929 if( !$this->inCache( ) && !$noFetch ) {
3030 $this->data = $this->bz->search( array( "id" => $id ) );
31 - $this->data = $this->data['bugs'][0];
3231 self::$bugs[$id] = $this;
3332 } else if( $this->inCache( ) ){
3433 $this->fromCache( );
@@ -42,6 +41,10 @@
4342 return $bug;
4443 }
4544
 45+ public function getComments() {
 46+ return $this->bz->getBugComments( $this->id );
 47+ }
 48+
4649 /**
4750 * Returns true if the bug is resolvd
4851 */
@@ -115,7 +118,7 @@
116119 }
117120 }
118121 }
119 - foreach($dep as $id => $none) {
 122+ foreach($dep as $id => $none) {
120123 $this->dependency[] = new BugzillaBug( $id, $this->bz );
121124 }
122125 }
@@ -138,6 +141,39 @@
139142 }
140143 }
141144
 145+ public function findCommentByRegexp( $regexp ) {
 146+ foreach( $this->getComments() as $comment ) {
 147+ $hasMatch = preg_match( $regexp, $comment['text'] );
 148+ if( $hasMatch >= 1 ) {
 149+ return $comment;
 150+ }
 151+ if( $hasMatch === false ) {
 152+ if (preg_last_error() == PREG_INTERNAL_ERROR) {
 153+ print 'There is an internal error!';
 154+ exit;
 155+ }
 156+ else if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {
 157+ print 'Backtrack limit was exhausted!';
 158+ exit;
 159+ }
 160+ else if (preg_last_error() == PREG_RECURSION_LIMIT_ERROR) {
 161+ print 'Recursion limit was exhausted!';
 162+ exit;
 163+ }
 164+ else if (preg_last_error() == PREG_BAD_UTF8_ERROR) {
 165+ print 'Bad UTF8 error!';
 166+ exit;
 167+ }
 168+ else if (preg_last_error() == PREG_BAD_UTF8_OFFSET_ERROR) {
 169+ print 'Bad UTF8 offset error!';
 170+ exit;
 171+ }
 172+ }
 173+ }
 174+
 175+ return null;
 176+ }
 177+
142178 public function addResetField( $changeLog ) {
143179 if( $this->bz->isListField( $changeLog['field_name'] ) ) {
144180 return array( $changeLog['field_name'] =>
@@ -258,10 +294,6 @@
259295 return $this->bz->__call( "Bug.fields", array( "" => "" ) );
260296 }
261297
262 - public function getState( $id ) {
263 - $this->bz->__call( "Bug.get", array( "id" => (array)$id ) );
264 - }
265 -
266298 public function search( $conditions ) {
267299 if(is_array($conditions)) {
268300 return $this->bz->__call( "Bug.search", $conditions );
@@ -270,6 +302,17 @@
271303 }
272304 }
273305
 306+ public function getBugComments( $id ) {
 307+ $ret = $this->bz->__call(
 308+ "Bug.comments", array( "ids" => (array)$id ) );
 309+ if( !is_array( $id ) ) {
 310+ $ret = $ret['bugs'][$id]['comments'];
 311+ } else {
 312+ throw new Exception("ugh!");
 313+ }
 314+ return $ret;
 315+ }
 316+
274317 public function getBugHistory( $id ) {
275318 return $this->getHistory( $id );
276319 }

Comments

#Comment by Reedy (talk | contribs)   00:41, 1 January 2012

Use elseif!

Status & tagging log