r108247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108246‎ | r108247 | r108248 >
Date:16:12, 6 January 2012
Author:gregchiasson
Status:resolved
Tags:
Comment:
AFTv5 - Refactor feedback/answer saving so we can get it all in one transaction. Moves the contents of newFeedback into saveUserAnswers, which new returns an array with CTA ID and feedbackID. Should prevent issues with feedback saving without answers (which was possible on bucket 3).
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -30,6 +30,7 @@
3131 * Execute the API call: Save the form values
3232 */
3333 public function execute() {
 34+error_Log('hi there');
3435 global $wgUser, $wgArticleFeedbackv5SMaxage;
3536 $params = $this->extractRequestParams();
3637
@@ -41,7 +42,6 @@
4243 $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
4344 }
4445
45 - $feedbackId = $this->newFeedback( $params );
4646 $dbr = wfGetDB( DB_SLAVE );
4747 $pageId = $params['pageid'];
4848 $bucket = $params['bucket'];
@@ -68,7 +68,6 @@
6969 }
7070 if ( $this->validateParam( $value, $type, $field['afi_id'] ) ) {
7171 $data = array(
72 - 'aa_feedback_id' => $feedbackId,
7372 'aa_field_id' => $field['afi_id'],
7473 );
7574 foreach ( array( 'rating', 'text', 'boolean', 'option_id' ) as $t ) {
@@ -88,8 +87,10 @@
8988 );
9089 return;
9190 }
 91+ $ratingIds = $this->saveUserRatings( $user_answers, $bucket, $params );
 92+ $ctaId = $ratingIds['cta_id'];
 93+ $feedbackId = $ratingIds['feedback_id'];
9294
93 - $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket );
9495 $this->saveUserProperties( $revisionId );
9596 $this->updateRollupTables( $pageId, $revisionId, $user_answers );
9697
@@ -117,9 +118,9 @@
118119 null,
119120 $this->getModuleName(),
120121 array(
121 - 'result' => 'Success',
 122+ 'result' => 'Success',
122123 'feedback_id' => $feedbackId,
123 - 'cta_id' => $ctaId,
 124+ 'cta_id' => $ctaId,
124125 )
125126 );
126127 }
@@ -436,14 +437,18 @@
437438 }
438439
439440 /**
440 - * Creates a new feedback row and returns the id
 441+ * Creates a new feedback record and inserts the user's rating
 442+ * for a specific revision
441443 *
442 - * @param $params array the parameters
443 - * @return int the feedback id
 444+ * @param array $data the data
 445+ * @param int $feedbackId the feedback id
 446+ * @param int $bucket the bucket id
 447+ * @return int the cta id
444448 */
445 - public function newFeedback( $params ) {
 449+ private function saveUserRatings( $data, $bucket, $params ) {
446450 global $wgUser, $wgArticleFeedbackv5LinkBuckets;
447451 $dbw = wfGetDB( DB_MASTER );
 452+ $ctaId = $this->getCTAId( $data, $bucket );
448453 $revId = $params['revid'];
449454 $bucket = $params['bucket'];
450455 $linkName = $params['link'];
@@ -478,6 +483,8 @@
479484 $links = array_flip( array_keys( $wgArticleFeedbackv5LinkBuckets['buckets'] ) );
480485 $linkId = isset($links[$linkName]) ? $links[$linkName] : 0;
481486
 487+ $dbw->begin();
 488+
482489 $dbw->insert( 'aft_article_feedback', array(
483490 'af_page_id' => $params['pageid'],
484491 'af_revision_id' => $revId,
@@ -489,22 +496,12 @@
490497 'af_link_id' => $linkId,
491498 ) );
492499
493 - return $dbw->insertID();
494 - }
 500+ $feedbackId = $dbw->insertID();
495501
496 - /**
497 - * Inserts the user's rating for a specific revision
498 - *
499 - * @param array $data the data
500 - * @param int $feedbackId the feedback id
501 - * @param int $bucket the bucket id
502 - * @return int the cta id
503 - */
504 - private function saveUserRatings( $data, $feedbackId, $bucket ) {
505 - $dbw = wfGetDB( DB_MASTER );
506 - $ctaId = $this->getCTAId( $data, $bucket );
 502+ foreach($data as $key => $item) {
 503+ $data[$key]['aa_feedback_id'] = $feedbackId;
 504+ }
507505
508 - $dbw->begin();
509506 $dbw->insert( 'aft_article_answer', $data, __METHOD__ );
510507 $dbw->update(
511508 'aft_article_feedback',
@@ -514,7 +511,10 @@
515512 );
516513 $dbw->commit();
517514
518 - return $ctaId;
 515+ return array(
 516+ 'cta_id' => ($ctaId ? $ctaId : 0),
 517+ 'feedback_id' => ($feedbackId ? $feedbackId : 0)
 518+ );
519519 }
520520
521521 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r108280Dropped debug line from r108247rsterbin20:26, 6 January 2012
r1084701.18wmf1: MFT r108239, r108245, r108247, r108250, r108269, r108280catrope20:28, 9 January 2012

Status & tagging log