Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | private function insertPageRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) { |
93 | 93 | $dbw = wfGetDB( DB_MASTER ); |
94 | 94 | |
| 95 | + // Try to insert a new "totals" row for this page,rev,rating set |
95 | 96 | $dbw->insert( |
96 | 97 | 'article_feedback_pages', |
97 | 98 | array( |
— | — | @@ -104,8 +105,13 @@ |
105 | 106 | array( 'IGNORE' ) |
106 | 107 | ); |
107 | 108 | |
| 109 | + // If that succeded in inserting a row, then we are for sure rating a previously unrated |
| 110 | + // revision, and we need to add more information about this rating to the new "totals" row, |
| 111 | + // as well as remove the previous rating values from the previous "totals" row |
108 | 112 | if ( $dbw->affectedRows() ) { |
| 113 | + // If there was a previous rating, there should be a "totals" row for it's revision |
109 | 114 | if ( $lastRating ) { |
| 115 | + // Deduct the previous rating values from the previous "totals" row |
110 | 116 | $dbw->update( |
111 | 117 | 'article_feedback_pages', |
112 | 118 | array( |
— | — | @@ -120,6 +126,7 @@ |
121 | 127 | __METHOD__ |
122 | 128 | ); |
123 | 129 | } |
| 130 | + // Add this rating's values to the new "totals" row |
124 | 131 | $dbw->update( |
125 | 132 | 'article_feedback_pages', |
126 | 133 | array( |
— | — | @@ -134,9 +141,10 @@ |
135 | 142 | __METHOD__ |
136 | 143 | ); |
137 | 144 | } else { |
138 | | - // 0 == No change in rating count |
139 | | - // 1 == No rating last time (or new rating), and now there is |
140 | | - // -1 == Rating last time, but abstained this time |
| 145 | + // Calculate the difference between the previous rating and this one |
| 146 | + // * -1 == Rating last time, but abstained this time |
| 147 | + // * 0 == No change in rating count |
| 148 | + // * 1 == No rating last time (or new rating), and now there is |
141 | 149 | $countChange = 0; |
142 | 150 | if ( $lastRating === false || $lastRating === 0 ) { |
143 | 151 | if ( $thisRating === 0 ) { |
— | — | @@ -144,13 +152,15 @@ |
145 | 153 | } else { |
146 | 154 | $countChange = 1; |
147 | 155 | } |
148 | | - } else { // Last rating was > 0 |
| 156 | + } else { |
| 157 | + // Last rating was > 0 |
149 | 158 | if ( $thisRating === 0 ) { |
150 | 159 | $countChange = -1; |
151 | 160 | } else { |
152 | 161 | $countChange = 0; |
153 | 162 | } |
154 | 163 | } |
| 164 | + // Apply the difference between the previous and new ratings to the current "totals" row |
155 | 165 | $dbw->update( |
156 | 166 | 'article_feedback_pages', |
157 | 167 | array( |