Index: trunk/extensions/GPoC/models/Rating.php |
— | — | @@ -50,26 +50,55 @@ |
51 | 51 | // Rating has just been detected. |
52 | 52 | // So we can ignore $old_importance and $old_quality |
53 | 53 | $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'. |
60 | 77 | if(! $is_new_rating && ! empty( $this->old_importance ) ) { |
61 | 78 | $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 | + ); |
63 | 88 | } |
64 | | - $query .= ";"; |
65 | | - $dbw->query($query); |
66 | 89 | if(! $is_new_rating && ! empty( $this->old_quality ) ) { |
67 | 90 | if(! isset($old_importance_column) ) { |
68 | 91 | $old_importance_column = $importance_column; |
69 | 92 | } |
| 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 | + ); |
70 | 102 | |
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); |
74 | 103 | } |
75 | 104 | } |
76 | 105 | public function saveAll() { |