r91384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91383‎ | r91384 | r91385 >
Date:20:42, 3 July 2011
Author:yuvipanda
Status:ok
Tags:
Comment:
Removed raw SQL Queries, use wrappers instead.

Thanks Roan!
Modified paths:
  • /trunk/extensions/GPoC/models/Rating.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/models/Rating.php
@@ -50,26 +50,55 @@
5151 // Rating has just been detected.
5252 // So we can ignore $old_importance and $old_quality
5353 $importance_column = Statistics::getImportanceColumn( $this->importance );
54 - $project = $dbw->addQuotes($this->project);
55 - $quality = $dbw->addQuotes($this->quality);
56 - $query = "INSERT INTO project_stats (ps_project, ps_quality, $importance_column) ";
57 - $query .= "VALUES ($project, $quality, 1) ";
58 - $query .= "ON DUPLICATE KEY ";
59 - $query .= "UPDATE $importance_column = $importance_column + 1 ";
 54+ $dbw->insert(
 55+ 'project_stats',
 56+ array(
 57+ 'ps_project' => $this->project,
 58+ 'ps_quality' => $this->quality,
 59+ $importance_column => '0'
 60+ ),
 61+ __METHOD__,
 62+ array( 'IGNORE' )
 63+ );
 64+ $dbw->update(
 65+ 'project_stats',
 66+ array( "$importance_column = $importance_column + 1" ),
 67+ array(
 68+ "ps_project" => $this->project,
 69+ "ps_quality" => $this->quality
 70+ ),
 71+ __METHOD__
 72+ );
 73+
 74+ //FIXME: Needs cleaner logic for four combinations of what can change
 75+ //Just Importance, Just Quality, Neither and Both
 76+ //Currently, code fails for 'both'.
6077 if(! $is_new_rating && ! empty( $this->old_importance ) ) {
6178 $old_importance_column = Statistics::getImportanceColumn( $this->old_importance );
62 - $query .= ", $old_importance_column = $old_importance_column - 1";
 79+ $dbw->update(
 80+ 'project_stats',
 81+ array( "$old_importance_column = $old_importance_column - 1" ),
 82+ array(
 83+ "ps_project" => $this->project,
 84+ "ps_quality" => $this->quality
 85+ ),
 86+ __METHOD__
 87+ );
6388 }
64 - $query .= ";";
65 - $dbw->query($query);
6689 if(! $is_new_rating && ! empty( $this->old_quality ) ) {
6790 if(! isset($old_importance_column) ) {
6891 $old_importance_column = $importance_column;
6992 }
 93+ $dbw->update(
 94+ 'project_stats',
 95+ array( "$old_importance_column = $old_importance_column - 1" ),
 96+ array(
 97+ "ps_project" => $this->project,
 98+ "ps_quality" => $this->old_quality
 99+ ),
 100+ __METHOD__
 101+ );
70102
71 - $query = "UPDATE project_stats SET $old_importance_column = $old_importance_column - 1 ";
72 - $query .= "WHERE ps_project = '$this->project' and ps_quality = '$this->old_quality';";
73 - $dbw->query($query);
74103 }
75104 }
76105 public function saveAll() {

Status & tagging log