https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108247
Revision: 108247
Author: gregchiasson
Date: 2012-01-06 16:12:53 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
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: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
2012-01-06 16:09:21 UTC (rev 108246)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
2012-01-06 16:12:53 UTC (rev 108247)
@@ -30,6 +30,7 @@
* Execute the API call: Save the form values
*/
public function execute() {
+error_Log('hi there');
global $wgUser, $wgArticleFeedbackv5SMaxage;
$params = $this->extractRequestParams();
@@ -41,7 +42,6 @@
$this->dieUsage( 'ArticleFeedback is not enabled on
this page', 'invalidpage' );
}
- $feedbackId = $this->newFeedback( $params );
$dbr = wfGetDB( DB_SLAVE );
$pageId = $params['pageid'];
$bucket = $params['bucket'];
@@ -68,7 +68,6 @@
}
if ( $this->validateParam( $value, $type,
$field['afi_id'] ) ) {
$data = array(
- 'aa_feedback_id' => $feedbackId,
'aa_field_id' =>
$field['afi_id'],
);
foreach ( array( 'rating', 'text',
'boolean', 'option_id' ) as $t ) {
@@ -88,8 +87,10 @@
);
return;
}
+ $ratingIds = $this->saveUserRatings( $user_answers, $bucket,
$params );
+ $ctaId = $ratingIds['cta_id'];
+ $feedbackId = $ratingIds['feedback_id'];
- $ctaId = $this->saveUserRatings( $user_answers, $feedbackId,
$bucket );
$this->saveUserProperties( $revisionId );
$this->updateRollupTables( $pageId, $revisionId, $user_answers
);
@@ -117,9 +118,9 @@
null,
$this->getModuleName(),
array(
- 'result' => 'Success',
+ 'result' => 'Success',
'feedback_id' => $feedbackId,
- 'cta_id' => $ctaId,
+ 'cta_id' => $ctaId,
)
);
}
@@ -436,14 +437,18 @@
}
/**
- * Creates a new feedback row and returns the id
+ * Creates a new feedback record and inserts the user's rating
+ * for a specific revision
*
- * @param $params array the parameters
- * @return int the feedback id
+ * @param array $data the data
+ * @param int $feedbackId the feedback id
+ * @param int $bucket the bucket id
+ * @return int the cta id
*/
- public function newFeedback( $params ) {
+ private function saveUserRatings( $data, $bucket, $params ) {
global $wgUser, $wgArticleFeedbackv5LinkBuckets;
$dbw = wfGetDB( DB_MASTER );
+ $ctaId = $this->getCTAId( $data, $bucket );
$revId = $params['revid'];
$bucket = $params['bucket'];
$linkName = $params['link'];
@@ -478,6 +483,8 @@
$links = array_flip( array_keys(
$wgArticleFeedbackv5LinkBuckets['buckets'] ) );
$linkId = isset($links[$linkName]) ? $links[$linkName] : 0;
+ $dbw->begin();
+
$dbw->insert( 'aft_article_feedback', array(
'af_page_id' => $params['pageid'],
'af_revision_id' => $revId,
@@ -489,22 +496,12 @@
'af_link_id' => $linkId,
) );
- return $dbw->insertID();
- }
+ $feedbackId = $dbw->insertID();
- /**
- * Inserts the user's rating for a specific revision
- *
- * @param array $data the data
- * @param int $feedbackId the feedback id
- * @param int $bucket the bucket id
- * @return int the cta id
- */
- private function saveUserRatings( $data, $feedbackId, $bucket ) {
- $dbw = wfGetDB( DB_MASTER );
- $ctaId = $this->getCTAId( $data, $bucket );
+ foreach($data as $key => $item) {
+ $data[$key]['aa_feedback_id'] = $feedbackId;
+ }
- $dbw->begin();
$dbw->insert( 'aft_article_answer', $data, __METHOD__ );
$dbw->update(
'aft_article_feedback',
@@ -514,7 +511,10 @@
);
$dbw->commit();
- return $ctaId;
+ return array(
+ 'cta_id' => ($ctaId ? $ctaId : 0),
+ 'feedback_id' => ($feedbackId ? $feedbackId : 0)
+ );
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs