Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | * Execute the API call: Save the form values |
32 | 32 | */ |
33 | 33 | public function execute() { |
| 34 | +error_Log('hi there'); |
34 | 35 | global $wgUser, $wgArticleFeedbackv5SMaxage; |
35 | 36 | $params = $this->extractRequestParams(); |
36 | 37 | |
— | — | @@ -41,7 +42,6 @@ |
42 | 43 | $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' ); |
43 | 44 | } |
44 | 45 | |
45 | | - $feedbackId = $this->newFeedback( $params ); |
46 | 46 | $dbr = wfGetDB( DB_SLAVE ); |
47 | 47 | $pageId = $params['pageid']; |
48 | 48 | $bucket = $params['bucket']; |
— | — | @@ -68,7 +68,6 @@ |
69 | 69 | } |
70 | 70 | if ( $this->validateParam( $value, $type, $field['afi_id'] ) ) { |
71 | 71 | $data = array( |
72 | | - 'aa_feedback_id' => $feedbackId, |
73 | 72 | 'aa_field_id' => $field['afi_id'], |
74 | 73 | ); |
75 | 74 | foreach ( array( 'rating', 'text', 'boolean', 'option_id' ) as $t ) { |
— | — | @@ -88,8 +87,10 @@ |
89 | 88 | ); |
90 | 89 | return; |
91 | 90 | } |
| 91 | + $ratingIds = $this->saveUserRatings( $user_answers, $bucket, $params ); |
| 92 | + $ctaId = $ratingIds['cta_id']; |
| 93 | + $feedbackId = $ratingIds['feedback_id']; |
92 | 94 | |
93 | | - $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket ); |
94 | 95 | $this->saveUserProperties( $revisionId ); |
95 | 96 | $this->updateRollupTables( $pageId, $revisionId, $user_answers ); |
96 | 97 | |
— | — | @@ -117,9 +118,9 @@ |
118 | 119 | null, |
119 | 120 | $this->getModuleName(), |
120 | 121 | array( |
121 | | - 'result' => 'Success', |
| 122 | + 'result' => 'Success', |
122 | 123 | 'feedback_id' => $feedbackId, |
123 | | - 'cta_id' => $ctaId, |
| 124 | + 'cta_id' => $ctaId, |
124 | 125 | ) |
125 | 126 | ); |
126 | 127 | } |
— | — | @@ -436,14 +437,18 @@ |
437 | 438 | } |
438 | 439 | |
439 | 440 | /** |
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 |
441 | 443 | * |
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 |
444 | 448 | */ |
445 | | - public function newFeedback( $params ) { |
| 449 | + private function saveUserRatings( $data, $bucket, $params ) { |
446 | 450 | global $wgUser, $wgArticleFeedbackv5LinkBuckets; |
447 | 451 | $dbw = wfGetDB( DB_MASTER ); |
| 452 | + $ctaId = $this->getCTAId( $data, $bucket ); |
448 | 453 | $revId = $params['revid']; |
449 | 454 | $bucket = $params['bucket']; |
450 | 455 | $linkName = $params['link']; |
— | — | @@ -478,6 +483,8 @@ |
479 | 484 | $links = array_flip( array_keys( $wgArticleFeedbackv5LinkBuckets['buckets'] ) ); |
480 | 485 | $linkId = isset($links[$linkName]) ? $links[$linkName] : 0; |
481 | 486 | |
| 487 | + $dbw->begin(); |
| 488 | + |
482 | 489 | $dbw->insert( 'aft_article_feedback', array( |
483 | 490 | 'af_page_id' => $params['pageid'], |
484 | 491 | 'af_revision_id' => $revId, |
— | — | @@ -489,22 +496,12 @@ |
490 | 497 | 'af_link_id' => $linkId, |
491 | 498 | ) ); |
492 | 499 | |
493 | | - return $dbw->insertID(); |
494 | | - } |
| 500 | + $feedbackId = $dbw->insertID(); |
495 | 501 | |
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 | + } |
507 | 505 | |
508 | | - $dbw->begin(); |
509 | 506 | $dbw->insert( 'aft_article_answer', $data, __METHOD__ ); |
510 | 507 | $dbw->update( |
511 | 508 | 'aft_article_feedback', |
— | — | @@ -514,7 +511,10 @@ |
515 | 512 | ); |
516 | 513 | $dbw->commit(); |
517 | 514 | |
518 | | - return $ctaId; |
| 515 | + return array( |
| 516 | + 'cta_id' => ($ctaId ? $ctaId : 0), |
| 517 | + 'feedback_id' => ($feedbackId ? $feedbackId : 0) |
| 518 | + ); |
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |