Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql |
— | — | @@ -61,19 +61,19 @@ |
62 | 62 | ALTER TABLE aft_article_feedback ADD COLUMN af_helpful_count integer unsigned NOT NULL DEFAULT 0; |
63 | 63 | ALTER TABLE aft_article_feedback ADD COLUMN af_delete_count integer unsigned NOT NULL DEFAULT 0; |
64 | 64 | |
| 65 | + |
| 66 | +-- added 1/19 (greg) |
| 67 | +ALTER TABLE aft_article_feedback ADD COLUMN af_unhelpful_count integer unsigned NOT NULL DEFAULT 0; |
| 68 | + |
| 69 | +-- added or updated 1/24 (greg) |
65 | 70 | DELETE FROM aft_article_filter_count; |
66 | | -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_helpful_count > 0 GROUP BY af_page_id; |
67 | | -INSERT INTO aft_article_filter_count(afc_page_id, afc_filter_name, afc_filter_count) SELECT af_page_id, 'abuse', COUNT(*) FROM aft_article_feedback WHERE af_abuse_count = 0 GROUP BY af_page_id; |
| 71 | +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 CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) > 0 GROUP BY af_page_id; |
| 72 | +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_abuse_count = 0 GROUP BY af_page_id; |
68 | 73 | 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_hide_count > 0 GROUP BY af_page_id; |
69 | 74 | 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_hide_count = 0 GROUP BY af_page_id; |
70 | 75 | 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 GROUP BY af_page_id; |
71 | 76 | 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_id = aa_feedback_id AND aa_response_text IS NOT NULL GROUP BY af_page_id; |
72 | | - |
73 | | -ALTER TABLE aft_article_feedback ADD COLUMN af_unhelpful_count integer unsigned NOT NULL DEFAULT 0; |
74 | | - |
75 | 77 | 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_delete_count > 0 GROUP BY af_page_id; |
76 | | -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_helpful_count <= 0 GROUP BY af_page_id; |
| 78 | +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 CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) < 0 GROUP BY af_page_id; |
| 79 | +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_needs_oversight IS TRUE GROUP BY af_page_id; |
77 | 80 | ALTER TABLE aft_article_feedback ADD COLUMN af_needs_oversight boolean NOT NULL DEFAULT FALSE; |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php |
— | — | @@ -23,9 +23,11 @@ |
24 | 24 | */ |
25 | 25 | public function execute() { |
26 | 26 | $params = $this->extractRequestParams(); |
| 27 | + $pageId = $params['pageid']; |
27 | 28 | $error = null; |
28 | 29 | $dbr = wfGetDB( DB_SLAVE ); |
29 | 30 | $counts = array( 'increment' => array(), 'decrement' => array() ); |
| 31 | + |
30 | 32 | # load feedback record, bail if we don't have one |
31 | 33 | $record = $dbr->selectRow( |
32 | 34 | 'aft_article_feedback', |
— | — | @@ -62,32 +64,48 @@ |
63 | 65 | $error = 'articlefeedbackv5-invalid-feedback-flag'; |
64 | 66 | } |
65 | 67 | |
66 | | - |
67 | 68 | // Newly abusive record |
68 | 69 | if( $flag == 'abuse' && $record->af_abuse_count == 0 ) { |
69 | | - $counts['increment'][] = 'abuse'; |
| 70 | + $counts['increment'][] = 'abusive'; |
70 | 71 | } |
71 | 72 | |
| 73 | + if( $flag == 'oversight' ) { |
| 74 | + $counts['increment'][] = 'needsoversight'; |
| 75 | + } |
| 76 | + if( $flag == 'unoversight' ) { |
| 77 | + $counts['decrement'][] = 'needsoversight'; |
| 78 | + } |
| 79 | + |
| 80 | + |
72 | 81 | // Newly hidden record |
73 | 82 | if( $flag == 'hide' && $record->af_hide_count == 0 ) { |
74 | 83 | $counts['increment'][] = 'invisible'; |
75 | 84 | $counts['decrement'][] = 'visible'; |
76 | 85 | } |
| 86 | + // Unhidden record |
| 87 | + if( $flag == 'unhide') { |
| 88 | + $counts['increment'][] = 'visible'; |
| 89 | + $counts['decrement'][] = 'invisible'; |
| 90 | + } |
77 | 91 | |
78 | 92 | // Newly deleted record |
79 | 93 | if( $flag == 'delete' && $record->af_delete_count == 0 ) { |
80 | 94 | $counts['increment'][] = 'deleted'; |
81 | 95 | $counts['decrement'][] = 'visible'; |
82 | 96 | } |
83 | | - |
| 97 | + // Undeleted record |
| 98 | + if( $flag == 'undelete' ) { |
| 99 | + $counts['increment'][] = 'visible'; |
| 100 | + $counts['decrement'][] = 'deleted'; |
| 101 | + } |
| 102 | + |
84 | 103 | // Newly helpful record |
85 | 104 | if( $flag == 'helpful' && $record->af_helpful_count == 0 ) { |
86 | 105 | $counts['increment'][] = 'helpful'; |
87 | 106 | } |
88 | | - |
89 | 107 | // Newly unhelpful record (IE, unhelpful has overtaken helpful) |
90 | 108 | if( $flag == 'unhelpful' |
91 | | - && ( $record->af_helpful_count - $record->af_unhelpful_count ) == 1 ) { |
| 109 | + && ( ( $record->af_helpful_count - $record->af_unhelpful_count ) == 1 ) ) { |
92 | 110 | $counts['decrement'][] = 'helpful'; |
93 | 111 | } |
94 | 112 | |
— | — | @@ -100,7 +118,8 @@ |
101 | 119 | __METHOD__ |
102 | 120 | ); |
103 | 121 | |
104 | | - $this->updateFilterCounts( $counts, $params['pageid'] ); |
| 122 | + ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $counts['increment'] ); |
| 123 | + ApiArticleFeedbackv5Utils::decrementFilterCounts( $pageId, $counts['decrement'] ); |
105 | 124 | } |
106 | 125 | |
107 | 126 | if ( $error ) { |
— | — | @@ -121,46 +140,6 @@ |
122 | 141 | ); |
123 | 142 | } |
124 | 143 | |
125 | | - public function updateFilterCounts( $counts, $pageId ) { |
126 | | - $dbw = wfGetDB( DB_MASTER ); |
127 | | - $rows = array(); |
128 | | - |
129 | | - foreach( array_merge( $counts['increment'], $counts['decrement'] ) as $filter ) { |
130 | | - $rows[] = array( |
131 | | - 'afc_page_id' => $pageId, |
132 | | - 'afc_filter_name' => $filter, |
133 | | - 'afc_filter_count' => 0 |
134 | | - ); |
135 | | - } |
136 | | - |
137 | | - // Make sure the rows are inserted. |
138 | | - $dbw->insert( |
139 | | - 'aft_article_filter_count', |
140 | | - $rows, |
141 | | - __METHOD__, |
142 | | - array( 'IGNORE' ) |
143 | | - ); |
144 | | - |
145 | | - // Update the filter counts |
146 | | - foreach( $counts['increment'] as $count ) { |
147 | | - $dbw->update( |
148 | | - 'aft_article_filter_count', |
149 | | - array( 'afc_filter_count = afc_filter_count + 1' ), |
150 | | - array( 'afc_filter_name' => $count ), |
151 | | - __METHOD__ |
152 | | - ); |
153 | | - } |
154 | | - |
155 | | - foreach( $counts['decrement'] as $count ) { |
156 | | - $dbw->update( |
157 | | - 'aft_article_filter_count', |
158 | | - array( 'afc_filter_count = afc_filter_count - 1' ), |
159 | | - array( 'afc_filter_name' => $count ), |
160 | | - __METHOD__ |
161 | | - ); |
162 | | - } |
163 | | - } |
164 | | - |
165 | 144 | /** |
166 | 145 | * Gets the allowed parameters |
167 | 146 | * |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -274,13 +274,13 @@ |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | | - # Update the overall number of records for this page. |
279 | | - ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'all' ); |
280 | | - ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'visible' ); |
| 278 | + $filters = array( 'all', 'visible' ); |
281 | 279 | # If the feedbackrecord had a comment, update that filter count. |
282 | 280 | if( $has_comment ) { |
283 | | - ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'comment' ); |
| 281 | + $filters[] = 'comment'; |
284 | 282 | } |
| 283 | + |
| 284 | + ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $filters ); |
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php |
— | — | @@ -254,7 +254,7 @@ |
255 | 255 | $where[] = 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) > 0'; |
256 | 256 | break; |
257 | 257 | case 'unhelpful': |
258 | | - $where[] = 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) <= 0'; |
| 258 | + $where[] = 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) < 0'; |
259 | 259 | break; |
260 | 260 | case 'comment': |
261 | 261 | $where[] = 'aa_response_text IS NOT NULL'; |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php |
— | — | @@ -154,40 +154,62 @@ |
155 | 155 | * Increments the per-page-per-filter count rollups used on the feedback |
156 | 156 | * page. |
157 | 157 | * |
158 | | - * @param $pageId int the ID of the page (page.page_id) |
159 | | - * @param $filterName string name of the filter to increment |
| 158 | + * @param $pageId int the ID of the page (page.page_id) |
| 159 | + * @param $filterNames array values are names of filters to increment |
160 | 160 | */ |
161 | | - public static function incrementFilterCount( $pageId, $filterName ) { |
| 161 | + public static function incrementFilterCounts( $pageId, $filterNames ) { |
| 162 | + ApiArticleFeedbackv5Utils::updateFilterCounts( $pageId, $filterNames, false ); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * decrements the per-page-per-filter count rollups used on the feedback |
| 167 | + * page. |
| 168 | + * |
| 169 | + * @param $pageId int the ID of the page (page.page_id) |
| 170 | + * @param $filterNames array values are names of filters to decrement |
| 171 | + */ |
| 172 | + public static function decrementFilterCounts( $pageId, $filterNames ) { |
| 173 | + ApiArticleFeedbackv5Utils::updateFilterCounts( $pageId, $filterNames, true ); |
| 174 | + } |
| 175 | + |
| 176 | + public function updateFilterCounts( $pageId, $filters, $decrement ) { |
162 | 177 | $dbw = wfGetDB( DB_MASTER ); |
163 | 178 | |
164 | 179 | $dbw->begin(); |
165 | 180 | |
166 | | - # Try to insert the record, but ignore failures. |
167 | | - # Ensures the count row exists. |
168 | | - $dbw->insert( |
169 | | - 'aft_article_filter_count', |
170 | | - array( |
171 | | - 'afc_page_id' => $pageId, |
172 | | - 'afc_filter_name' => $filterName, |
173 | | - 'afc_filter_count' => 0 |
174 | | - ), |
175 | | - __METHOD__, |
176 | | - array( 'IGNORE' ) |
177 | | - ); |
| 181 | + foreach( $filters as $filter ) { |
| 182 | + $rows[] = array( |
| 183 | + 'afc_page_id' => $pageId, |
| 184 | + 'afc_filter_name' => $filter, |
| 185 | + 'afc_filter_count' => 0 |
| 186 | + ); |
| 187 | + } |
178 | 188 | |
179 | | - # Update the count row, incrementing the count. |
180 | | - $dbw->update( |
181 | | - 'aft_article_filter_count', |
182 | | - array( |
183 | | - 'afc_filter_count = afc_filter_count + 1' |
184 | | - ), |
185 | | - array( |
186 | | - 'afc_page_id' => $pageId, |
187 | | - 'afc_filter_name' => $filterName |
188 | | - ), |
189 | | - __METHOD__ |
190 | | - ); |
| 189 | + # Try to insert the record, but ignore failures. |
| 190 | + # Ensures the count row exists. |
| 191 | + $dbw->insert( |
| 192 | + 'aft_article_filter_count', |
| 193 | + $rows, |
| 194 | + __METHOD__, |
| 195 | + array( 'IGNORE' ) |
| 196 | + ); |
191 | 197 | |
192 | | - $dbw->commit(); |
| 198 | + $value = $decrement ? 'afc_filter_count - 1' : 'afc_filter_count + 1'; |
| 199 | + |
| 200 | + foreach( $filters as $filter ) { |
| 201 | + # Update each row with the new count. |
| 202 | + $dbw->update( |
| 203 | + 'aft_article_filter_count', |
| 204 | + array( "afc_filter_count = $value" ), |
| 205 | + array( |
| 206 | + 'afc_page_id' => $pageId, |
| 207 | + 'afc_filter_name' => $filter |
| 208 | + ), |
| 209 | + __METHOD__ |
| 210 | + ); |
| 211 | + |
| 212 | + } |
| 213 | + |
| 214 | + $dbw->commit(); |
193 | 215 | } |
194 | 216 | } |