Index: trunk/extensions/ArticleFeedbackv5/sql/filter_count.sql |
— | — | @@ -1,10 +1,12 @@ |
2 | 2 | DELETE FROM aft_article_filter_count; |
3 | | -INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'helpful', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) > 0 GROUP BY af_page_id; |
4 | | -INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'abusive', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_abuse_count > 0 GROUP BY af_page_id; |
| 3 | + |
5 | 4 | INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'all', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 GROUP BY af_page_id; |
6 | | -INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'comment', COUNT(*) FROM aft_article_feedback, aft_article_answer WHERE af_bucket_id = 1 AND af_id = aa_feedback_id AND aa_response_text IS NOT NULL GROUP BY af_page_id; |
7 | | -INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'unhelpful', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) < 0 GROUP BY af_page_id; |
8 | 5 | INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'needsoversight', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_oversight_count > 0 GROUP BY af_page_id; |
9 | 6 | INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'invisible', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_is_hidden IS TRUE GROUP BY af_page_id; |
10 | 7 | INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'visible', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_is_hidden IS FALSE AND af_is_deleted IS FALSE GROUP BY af_page_id; |
11 | 8 | INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'deleted', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_is_deleted IS TRUE GROUP BY af_page_id; |
| 9 | + |
| 10 | +INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'abusive', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND af_abuse_count > 0 AND af_is_hidden IS FALSE AND af_is_deleted IS FALSE GROUP BY af_page_id; |
| 11 | +INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'helpful', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) > 0 AND af_is_hidden IS FALSE AND af_is_deleted IS FALSE GROUP BY af_page_id; |
| 12 | +INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'unhelpful', COUNT(*) FROM aft_article_feedback WHERE af_bucket_id = 1 AND CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) < 0 AND af_is_hidden IS FALSE AND af_is_deleted IS FALSE GROUP BY af_page_id; |
| 13 | +INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'comment', COUNT(*) FROM aft_article_feedback, aft_article_answer WHERE af_bucket_id = 1 AND af_id = aa_feedback_id AND aa_response_text IS NOT NULL AND af_is_hidden IS FALSE AND af_is_deleted IS FALSE GROUP BY af_page_id; |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php |
— | — | @@ -22,19 +22,18 @@ |
23 | 23 | * Execute the API call: Pull the requested feedback |
24 | 24 | */ |
25 | 25 | public function execute() { |
26 | | - $params = $this->extractRequestParams(); |
27 | | - $pageId = $params['pageid']; |
| 26 | + $params = $this->extractRequestParams(); |
| 27 | + $pageId = $params['pageid']; |
28 | 28 | $feedbackId = $params['feedbackid']; |
29 | | - $flag = $params['flagtype']; |
30 | | - $notes = $params['note']; |
31 | | - $direction = isset( $params['direction'] ) ? $params['direction'] : 'increase'; |
32 | | - $counts = array( 'increment' => array(), 'decrement' => array() ); |
33 | | - $counters = array( 'abuse', 'helpful', 'unhelpful', 'oversight' ); |
34 | | - $flags = array( 'hide', 'delete' ); |
35 | | - $results = array(); |
36 | | - $helpful = null; |
37 | | - $error = null; |
38 | | - $where = array( 'af_id' => $feedbackId ); |
| 29 | + $flag = $params['flagtype']; |
| 30 | + $notes = $params['note']; |
| 31 | + $direction = isset( $params['direction'] ) ? $params['direction'] : 'increase'; |
| 32 | + $counters = array( 'abuse', 'helpful', 'unhelpful', 'oversight' ); |
| 33 | + $flags = array( 'hide', 'delete' ); |
| 34 | + $results = array(); |
| 35 | + $helpful = null; |
| 36 | + $error = null; |
| 37 | + $where = array( 'af_id' => $feedbackId ); |
39 | 38 | |
40 | 39 | # load feedback record, bail if we don't have one |
41 | 40 | $record = $this->fetchRecord( $feedbackId ); |
— | — | @@ -48,11 +47,9 @@ |
49 | 48 | switch( $flag ) { |
50 | 49 | case 'hide': |
51 | 50 | $field = 'af_is_hidden'; |
52 | | - $count = 'invisible'; |
53 | 51 | break; |
54 | 52 | case 'delete': |
55 | 53 | $field = 'af_is_deleted'; |
56 | | - $count = 'deleted'; |
57 | 54 | break; |
58 | 55 | default: return; # return error, ideally. |
59 | 56 | } |
— | — | @@ -61,20 +58,6 @@ |
62 | 59 | } else { |
63 | 60 | $update[] = "$field = FALSE"; |
64 | 61 | } |
65 | | - |
66 | | - // Increment or decrement whichever flag is being set. |
67 | | - $countDirection = $direction == 'increase' ? 'increment' : 'decrement'; |
68 | | - $counts[$countDirection][] = $count; |
69 | | - // If this is hiding/deleting, decrement the visible count. |
70 | | - if( ( $flag == 'hide' || $flag == 'delete' ) |
71 | | - && $direction == 'increase' ) { |
72 | | - $counts['decrement'][] = 'visible'; |
73 | | - } |
74 | | - // If this is unhiding/undeleting, increment the visible count. |
75 | | - if( ( $flag == 'hide' || $flag == 'delete' ) |
76 | | - && $direction == 'decrease' ) { |
77 | | - $counts['increment'][] = 'visible'; |
78 | | - } |
79 | 62 | } elseif( 'resetoversight' === $flag) { |
80 | 63 | // special case, oversight request count becomes 0 |
81 | 64 | $update[] = "af_oversight_count = 0"; |
— | — | @@ -103,60 +86,6 @@ |
104 | 87 | // Decrementing from 0 is not allowed. |
105 | 88 | $where[] = "$field > 0"; |
106 | 89 | } |
107 | | - |
108 | | - // Adding a new abuse flag: abusive++ |
109 | | - if( $flag == 'abuse' && $direction == 'increase' |
110 | | - && $record->af_abuse_count == 0 ) { |
111 | | - $counts['increment'][] = 'abusive'; |
112 | | - // Auto-hide after 5 abuse flags. |
113 | | - if( $record->af_abuse_count > 4 ) { |
114 | | - $counts['increment'][] = 'invisible'; |
115 | | - $counts['decrement'][] = 'visible'; |
116 | | - } |
117 | | - } |
118 | | - // Removing the last abuse flag: abusive-- |
119 | | - if( $flag == 'abuse' && $direction == 'decrease' |
120 | | - && $record->af_abuse_count == 1 ) { |
121 | | - $counts['decrement'][] = 'abusive'; |
122 | | - // Un-hide if we don't have 5 flags anymore |
123 | | - if( $record->af_abuse_count == 5 ) { |
124 | | - $counts['increment'][] = 'visible'; |
125 | | - $counts['decrement'][] = 'invisible'; |
126 | | - } |
127 | | - } |
128 | | - |
129 | | - // note that a net helpfulness of 0 is neither helpful nor unhelpful |
130 | | - $netHelpfulness = $record->af_net_helpfulness; |
131 | | - |
132 | | - // increase helpful OR decrease unhelpful |
133 | | - if( ( ($flag == 'helpful' && $direction == 'increase' ) |
134 | | - || ($flag == 'unhelpful' && $direction == 'decrease' ) ) |
135 | | - ) { |
136 | | - // net was -1: no longer unhelpful |
137 | | - if( $netHelpfulness == -1 ) { |
138 | | - $counts['decrement'][] = 'unhelpful'; |
139 | | - } |
140 | | - |
141 | | - // net was 0: now helpful |
142 | | - if( $netHelpfulness == 0 ) { |
143 | | - $counts['increment'][] = 'helpful'; |
144 | | - } |
145 | | - } |
146 | | - |
147 | | - // increase unhelpful OR decrease unhelpful |
148 | | - if( ( ($flag == 'unhelpful' && $direction == 'increase' ) |
149 | | - || ($flag == 'helpful' && $direction == 'decrease' ) ) |
150 | | - ) { |
151 | | - // net was 1: no longer helpful |
152 | | - if( $netHelpfulness == 1 ) { |
153 | | - $counts['decrement'][] = 'helpful'; |
154 | | - } |
155 | | - |
156 | | - // net was 0: now unhelpful |
157 | | - if( $netHelpfulness == 0 ) { |
158 | | - $counts['increment'][] = 'unhelpful'; |
159 | | - } |
160 | | - } |
161 | 90 | } else { |
162 | 91 | $error = 'articlefeedbackv5-invalid-feedback-flag'; |
163 | 92 | } |
— | — | @@ -183,9 +112,7 @@ |
184 | 113 | |
185 | 114 | ApiArticleFeedbackv5Utils::logActivity( $activity , $pageId, $feedbackId, $notes ); |
186 | 115 | |
187 | | - // Update the filter count rollups. |
188 | | - ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $counts['increment'] ); |
189 | | - ApiArticleFeedbackv5Utils::decrementFilterCounts( $pageId, $counts['decrement'] ); |
| 116 | + $this->updateCounts( $flag, $direction, $record, $pageId ); |
190 | 117 | |
191 | 118 | // Update helpful/unhelpful display count after submission. |
192 | 119 | if ( $flag == 'helpful' || $flag == 'unhelpful' ) { |
— | — | @@ -217,7 +144,6 @@ |
218 | 145 | __METHOD__ |
219 | 146 | ); |
220 | 147 | } |
221 | | - |
222 | 148 | } |
223 | 149 | |
224 | 150 | // Conditional formatting for abuse flag |
— | — | @@ -368,6 +294,126 @@ |
369 | 295 | } |
370 | 296 | |
371 | 297 | /** |
| 298 | + * Figures out which filter counts to increment/decrement based on what |
| 299 | + * flag was clicked and which direction it was going. |
| 300 | + * |
| 301 | + * @param $action string type of flag sent to the form |
| 302 | + * @param $direction string type of direction sent to the form |
| 303 | + * @param $record object database object representing the feedback row |
| 304 | + * @param $pageId integer ID of the page to be updated. |
| 305 | + */ |
| 306 | + protected function updateCounts( $action, $direction, $record, $pageId ) { |
| 307 | + $counts = array( 'increment' => array(), 'decrement' => array() ); |
| 308 | + $netHelpfulness = $record->af_net_helpfulness; |
| 309 | + |
| 310 | + // Increment or decrement hide or delete filters. |
| 311 | + if( $action == 'hide' || $action == 'delete' ) { |
| 312 | + $count = $action == 'hide' ? 'invisible' : 'deleted'; |
| 313 | + |
| 314 | + // If this is hiding/deleting, increment the visible count and |
| 315 | + // decrement the visible count. |
| 316 | + if( $direction == 'increase' ) { |
| 317 | + $counts['increment'][] = $count; |
| 318 | + $counts['decrement'][] = 'visible'; |
| 319 | + } |
| 320 | + // For unhiding/undeleting, do the opposite. |
| 321 | + if( $direction == 'decrease' ) { |
| 322 | + $counts['increment'][] = 'visible'; |
| 323 | + $counts['decrement'][] = $count; |
| 324 | + } |
| 325 | + } |
| 326 | + |
| 327 | + // Adding a new abuse flag: abusive++ |
| 328 | + if( $action == 'abuse' && $direction == 'increase' |
| 329 | + && $record->af_abuse_count == 0 ) { |
| 330 | + $counts['increment'][] = 'abusive'; |
| 331 | + // Auto-hide after 5 abuse flags. |
| 332 | + if( $record->af_abuse_count > 4 ) { |
| 333 | + $counts['increment'][] = 'invisible'; |
| 334 | + $counts['decrement'][] = 'visible'; |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + // Removing the last abuse flag: abusive-- |
| 339 | + if( $action == 'abuse' && $direction == 'decrease' |
| 340 | + && $record->af_abuse_count == 1 ) { |
| 341 | + $counts['decrement'][] = 'abusive'; |
| 342 | + // Un-hide if we don't have 5 flags anymore |
| 343 | + if( $record->af_abuse_count == 5 ) { |
| 344 | + $counts['increment'][] = 'visible'; |
| 345 | + $counts['decrement'][] = 'invisible'; |
| 346 | + } |
| 347 | + } |
| 348 | + |
| 349 | + // note that a net helpfulness of 0 is neither helpful nor unhelpful |
| 350 | + |
| 351 | + // increase helpful OR decrease unhelpful |
| 352 | + if( ( ($action == 'helpful' && $direction == 'increase' ) |
| 353 | + || ($action == 'unhelpful' && $direction == 'decrease' ) ) |
| 354 | + ) { |
| 355 | + // net was -1: no longer unhelpful |
| 356 | + if( $netHelpfulness == -1 ) { |
| 357 | + $counts['decrement'][] = 'unhelpful'; |
| 358 | + } |
| 359 | + |
| 360 | + // net was 0: now helpful |
| 361 | + if( $netHelpfulness == 0 ) { |
| 362 | + $counts['increment'][] = 'helpful'; |
| 363 | + } |
| 364 | + } |
| 365 | + |
| 366 | + // increase unhelpful OR decrease unhelpful |
| 367 | + if( ( ($action == 'unhelpful' && $direction == 'increase' ) |
| 368 | + || ($action == 'helpful' && $direction == 'decrease' ) ) |
| 369 | + ) { |
| 370 | + // net was 1: no longer helpful |
| 371 | + if( $netHelpfulness == 1 ) { |
| 372 | + $counts['decrement'][] = 'helpful'; |
| 373 | + } |
| 374 | + |
| 375 | + // net was 0: now unhelpful |
| 376 | + if( $netHelpfulness == 0 ) { |
| 377 | + $counts['increment'][] = 'unhelpful'; |
| 378 | + } |
| 379 | + } |
| 380 | + |
| 381 | + // If someone hides or deletes an abusive/comment/helpful/unhelpful |
| 382 | + // comment, decrement the relevent counter. |
| 383 | + // If they unhide/undelete, increment that same counter. |
| 384 | + if( $action == 'delete' || $action == 'hide' ) { |
| 385 | + $dbr = wfGetDB( DB_SLAVE ); |
| 386 | + $dir = $direction == 'increase' ? 'decrement' : 'increment'; |
| 387 | + $comment = $dbr->select( |
| 388 | + array( 'aft_article_answer', 'aft_article_field' ), |
| 389 | + 'aa_response_text', |
| 390 | + array( |
| 391 | + 'aa_feedback_id' => $record->af_id, |
| 392 | + 'afi_data_type' => 'text', |
| 393 | + 'aa_field_id = afi_id' |
| 394 | + ), |
| 395 | + __METHOD__ |
| 396 | + ); |
| 397 | + |
| 398 | + if( $record->af_abuse_count > 1 ) { |
| 399 | + $counts[$dir][] = 'abusive'; |
| 400 | + } |
| 401 | + if( $comment->numRows() > 0 ) { |
| 402 | + $counts[$dir][] = 'comment'; |
| 403 | + } |
| 404 | + if( $netHelpfulness > 1 ) { |
| 405 | + $counts[$dir][] = 'helpful'; |
| 406 | + } |
| 407 | + if( $netHelpfulness < 1 ) { |
| 408 | + $counts[$dir][] = 'unhelpful'; |
| 409 | + } |
| 410 | + } |
| 411 | + |
| 412 | + // Update the filter count rollups. |
| 413 | + ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $counts['increment'] ); |
| 414 | + ApiArticleFeedbackv5Utils::decrementFilterCounts( $pageId, $counts['decrement'] ); |
| 415 | + } |
| 416 | + |
| 417 | + /** |
372 | 418 | * Figures out which activity happened so it can be logged correctly |
373 | 419 | * |
374 | 420 | * @param $flag string type of flag sent to the form |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php |
— | — | @@ -175,11 +175,9 @@ |
176 | 176 | public function updateFilterCounts( $pageId, $filters, $decrement ) { |
177 | 177 | // Don't do anything unless we have filters to process. |
178 | 178 | if( !$filters ) { |
179 | | -error_log("no filters"); |
180 | 179 | return; |
181 | 180 | } |
182 | 181 | if( !count( $filters ) ) { |
183 | | -error_log("no count of filters"); |
184 | 182 | return; |
185 | 183 | } |
186 | 184 | |
— | — | @@ -187,7 +185,6 @@ |
188 | 186 | $dbw->begin(); |
189 | 187 | |
190 | 188 | foreach ( $filters as $filter ) { |
191 | | -error_log("have filter $filter for page $pageId"); |
192 | 189 | $rows[] = array( |
193 | 190 | 'afc_page_id' => $pageId, |
194 | 191 | 'afc_filter_name' => $filter, |
— | — | @@ -205,10 +202,8 @@ |
206 | 203 | ); |
207 | 204 | |
208 | 205 | $value = $decrement ? 'afc_filter_count - 1' : 'afc_filter_count + 1'; |
209 | | -error_log("new value is $value"); |
210 | 206 | |
211 | 207 | foreach ( $filters as $filter ) { |
212 | | -error_log("setting value for page $pageId, filter $filter"); |
213 | 208 | # Update each row with the new count. |
214 | 209 | $dbw->update( |
215 | 210 | 'aft_article_filter_count', |