Index: trunk/extensions/GPoC/models/Rating.php |
— | — | @@ -45,8 +45,6 @@ |
46 | 46 | return; |
47 | 47 | } |
48 | 48 | $dbw = wfGetDB( DB_MASTER ); |
49 | | - // Rating has just been detected. |
50 | | - // So we can ignore $old_importance and $old_quality |
51 | 49 | $importance_column = Statistics::getImportanceColumn( $this->importance ); |
52 | 50 | $dbw->insert( |
53 | 51 | 'project_stats', |
— | — | @@ -68,37 +66,30 @@ |
69 | 67 | __METHOD__ |
70 | 68 | ); |
71 | 69 | |
72 | | - //FIXME: Needs cleaner logic for four combinations of what can change |
73 | | - //Just Importance, Just Quality, Neither and Both |
74 | | - //Currently, code fails for 'both'. |
75 | | - if(! $is_new_rating && ! empty( $this->old_importance ) ) { |
76 | | - $old_importance_column = Statistics::getImportanceColumn( $this->old_importance ); |
77 | | - $dbw->update( |
78 | | - 'project_stats', |
79 | | - array( "$old_importance_column = $old_importance_column - 1" ), |
80 | | - array( |
81 | | - "ps_project" => $this->project, |
82 | | - "ps_quality" => $this->quality |
83 | | - ), |
84 | | - __METHOD__ |
85 | | - ); |
86 | | - } |
87 | | - if(! $is_new_rating && ! empty( $this->old_quality ) ) { |
88 | | - if(! isset($old_importance_column) ) { |
89 | | - $old_importance_column = $importance_column; |
| 70 | + if(! $is_new_rating ) { |
| 71 | + // Is not a new rating, and atleast one of quality or importance has changed |
| 72 | + if(! empty( $this->old_quality ) ) { |
| 73 | + $q_value = $this->old_quality; |
| 74 | + } else { |
| 75 | + $q_value = $this->quality; |
90 | 76 | } |
| 77 | + if(! empty( $this->old_importance) ) { |
| 78 | + $i_column = Statistics::getImportanceColumn( $this->old_importance ); |
| 79 | + } else { |
| 80 | + $i_column = Statistics::getImportanceColumn( $this->importance ); |
| 81 | + } |
91 | 82 | $dbw->update( |
92 | 83 | 'project_stats', |
93 | | - array( "$old_importance_column = $old_importance_column - 1" ), |
| 84 | + array( "$i_column = $i_column - 1" ), |
94 | 85 | array( |
95 | 86 | "ps_project" => $this->project, |
96 | | - "ps_quality" => $this->old_quality |
| 87 | + "ps_quality" => $q_value |
97 | 88 | ), |
98 | 89 | __METHOD__ |
99 | 90 | ); |
100 | | - |
101 | 91 | } |
102 | 92 | } |
| 93 | + |
103 | 94 | public function saveAll() { |
104 | 95 | $data_array = array( |
105 | 96 | 'r_project' => $this->project, |