Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -281,49 +281,8 @@ |
282 | 282 | $this->insertChunks( $dbw, 'code_paths', $data, __METHOD__, array( 'IGNORE' ) ); |
283 | 283 | } |
284 | 284 | |
285 | | - // Update bug references table... |
286 | | - $affectedBugs = array(); |
287 | | - if ( preg_match_all( '/\bbug (\d+)\b/', $this->mMessage, $m ) ) { |
288 | | - $data = array(); |
289 | | - foreach ( $m[1] as $bug ) { |
290 | | - $data[] = array( |
291 | | - 'cb_repo_id' => $this->mRepoId, |
292 | | - 'cb_from' => $this->mId, |
293 | | - 'cb_bug' => $bug |
294 | | - ); |
295 | | - $affectedBugs[] = intval( $bug ); |
296 | | - } |
297 | | - $dbw->insert( 'code_bugs', $data, __METHOD__, array( 'IGNORE' ) ); |
298 | | - } |
| 285 | + $affectedRevs = $this->getUniqueAffectedRevs(); |
299 | 286 | |
300 | | - // Get the revisions this commit references... |
301 | | - $affectedRevs = array(); |
302 | | - if ( preg_match_all( '/\br(\d{2,})\b/', $this->mMessage, $m ) ) { |
303 | | - foreach ( $m[1] as $rev ) { |
304 | | - $affectedRev = intval( $rev ); |
305 | | - if ( $affectedRev != $this->mId ) { |
306 | | - $affectedRevs[] = $affectedRev; |
307 | | - } |
308 | | - } |
309 | | - } |
310 | | - |
311 | | - // Also, get previous revisions that have bugs in common... |
312 | | - if ( count( $affectedBugs ) ) { |
313 | | - $res = $dbw->select( 'code_bugs', |
314 | | - array( 'cb_from' ), |
315 | | - array( |
316 | | - 'cb_repo_id' => $this->mRepoId, |
317 | | - 'cb_bug' => $affectedBugs, |
318 | | - 'cb_from < ' . intval( $this->mId ), # just in case |
319 | | - ), |
320 | | - __METHOD__, |
321 | | - array( 'USE INDEX' => 'cb_repo_id' ) |
322 | | - ); |
323 | | - foreach ( $res as $row ) { |
324 | | - $affectedRevs[] = intval( $row->cb_from ); |
325 | | - } |
326 | | - } |
327 | | - |
328 | 287 | if ( count( $affectedRevs ) ) { |
329 | 288 | $this->addReferencesTo( $affectedRevs ); |
330 | 289 | } |
— | — | @@ -391,6 +350,76 @@ |
392 | 351 | $dbw->commit(); |
393 | 352 | } |
394 | 353 | |
| 354 | + /** |
| 355 | + * Returns a unique value array from that of getAffectedRevs() and getAffectedBugRevs() |
| 356 | + * |
| 357 | + * @return array |
| 358 | + */ |
| 359 | + public function getUniqueAffectedRevs() { |
| 360 | + return array_unique( array_merge( $this->getAffectedRevs(), $this->getAffectedBugRevs() ) ); |
| 361 | + } |
| 362 | + |
| 363 | + /** |
| 364 | + * Get the revisions this commit references |
| 365 | + * |
| 366 | + * @return array |
| 367 | + */ |
| 368 | + public function getAffectedRevs() { |
| 369 | + $affectedRevs = array(); |
| 370 | + if ( preg_match_all( '/\br(\d{2,})\b/', $this->mMessage, $m ) ) { |
| 371 | + foreach ( $m[1] as $rev ) { |
| 372 | + $affectedRev = intval( $rev ); |
| 373 | + if ( $affectedRev != $this->mId ) { |
| 374 | + $affectedRevs[] = $affectedRev; |
| 375 | + } |
| 376 | + } |
| 377 | + } |
| 378 | + return $affectedRevs; |
| 379 | + } |
| 380 | + |
| 381 | + /** |
| 382 | + * Parses references bugs in the comment, inserts them to code bugs, and returns an array of previous revs linking to the same bug |
| 383 | + * |
| 384 | + * @return array |
| 385 | + */ |
| 386 | + public function getAffectedBugRevs() { |
| 387 | + // Update bug references table... |
| 388 | + $affectedBugs = array(); |
| 389 | + if ( preg_match_all( '/\bbug (\d+)\b/', $this->mMessage, $m ) ) { |
| 390 | + $data = array(); |
| 391 | + foreach ( $m[1] as $bug ) { |
| 392 | + $data[] = array( |
| 393 | + 'cb_repo_id' => $this->mRepoId, |
| 394 | + 'cb_from' => $this->mId, |
| 395 | + 'cb_bug' => $bug |
| 396 | + ); |
| 397 | + $affectedBugs[] = intval( $bug ); |
| 398 | + } |
| 399 | + $dbw = wfGetDB( DB_MASTER ); |
| 400 | + $dbw->insert( 'code_bugs', $data, __METHOD__, array( 'IGNORE' ) ); |
| 401 | + } |
| 402 | + |
| 403 | + // Also, get previous revisions that have bugs in common... |
| 404 | + $affectedRevs = array(); |
| 405 | + if ( count( $affectedBugs ) ) { |
| 406 | + $res = $dbw->select( 'code_bugs', |
| 407 | + array( 'cb_from' ), |
| 408 | + array( |
| 409 | + 'cb_repo_id' => $this->mRepoId, |
| 410 | + 'cb_bug' => $affectedBugs, |
| 411 | + 'cb_from < ' . intval( $this->mId ), # just in case |
| 412 | + ), |
| 413 | + __METHOD__, |
| 414 | + array( 'USE INDEX' => 'cb_repo_id' ) |
| 415 | + ); |
| 416 | + foreach ( $res as $row ) { |
| 417 | + $affectedRevs[] = intval( $row->cb_from ); |
| 418 | + } |
| 419 | + } |
| 420 | + |
| 421 | + return $affectedRevs; |
| 422 | + } |
| 423 | + |
395 | 424 | public function getModifiedPaths() { |
396 | 425 | $dbr = wfGetDB( DB_SLAVE ); |
397 | 426 | return $dbr->select( |