r72537 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72536‎ | r72537 | r72538 >
Date:14:26, 7 September 2010
Author:reedy
Status:ok
Tags:
Comment:
Use !$dbw->affectedRows() to only run query optionally
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php
@@ -124,7 +124,7 @@
125125
126126 $timestamp = $dbw->timestamp();
127127
128 - $res = $dbw->insert(
 128+ $dbw->insert(
129129 'article_assessment',
130130 array_merge(
131131 array(
@@ -142,24 +142,25 @@
143143 array( 'IGNORE' )
144144 );
145145
146 - //TODO: Don't do this if the insert was successful
147 - $dbw->update(
148 - 'article_assessment',
149 - array(
150 - 'aa_timestamp' => $timestamp,
151 - 'aa_rating_value' => $ratingValue,
152 - ),
153 - array_merge(
 146+ if ( !$dbw->affectedRows() ) {
 147+ $dbw->update(
 148+ 'article_assessment',
154149 array(
155 - 'aa_page_id' => $pageId,
156 - 'aa_user_text' => $user->getName(),
157 - 'aa_revision' => $revisionId,
158 - 'aa_rating_id' => $ratingId,
 150+ 'aa_timestamp' => $timestamp,
 151+ 'aa_rating_value' => $ratingValue,
159152 ),
160 - $token
161 - ),
162 - __METHOD__
163 - );
 153+ array_merge(
 154+ array(
 155+ 'aa_page_id' => $pageId,
 156+ 'aa_user_text' => $user->getName(),
 157+ 'aa_revision' => $revisionId,
 158+ 'aa_rating_id' => $ratingId,
 159+ ),
 160+ $token
 161+ ),
 162+ __METHOD__
 163+ );
 164+ }
164165 }
165166
166167 public function getAllowedParams() {

Status & tagging log