r109962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109961‎ | r109962 | r109963 >
Date:22:23, 24 January 2012
Author:gregchiasson
Status:ok
Tags:aft 
Comment:
AFT5 feedback page - updating filter counts should work properly now.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/alter.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
@@ -61,19 +61,19 @@
6262 ALTER TABLE aft_article_feedback ADD COLUMN af_helpful_count integer unsigned NOT NULL DEFAULT 0;
6363 ALTER TABLE aft_article_feedback ADD COLUMN af_delete_count integer unsigned NOT NULL DEFAULT 0;
6464
 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)
6570 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;
6873 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;
6974 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;
7075 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;
7176 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 -
7577 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;
7780 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 @@
2424 */
2525 public function execute() {
2626 $params = $this->extractRequestParams();
 27+ $pageId = $params['pageid'];
2728 $error = null;
2829 $dbr = wfGetDB( DB_SLAVE );
2930 $counts = array( 'increment' => array(), 'decrement' => array() );
 31+
3032 # load feedback record, bail if we don't have one
3133 $record = $dbr->selectRow(
3234 'aft_article_feedback',
@@ -62,32 +64,48 @@
6365 $error = 'articlefeedbackv5-invalid-feedback-flag';
6466 }
6567
66 -
6768 // Newly abusive record
6869 if( $flag == 'abuse' && $record->af_abuse_count == 0 ) {
69 - $counts['increment'][] = 'abuse';
 70+ $counts['increment'][] = 'abusive';
7071 }
7172
 73+ if( $flag == 'oversight' ) {
 74+ $counts['increment'][] = 'needsoversight';
 75+ }
 76+ if( $flag == 'unoversight' ) {
 77+ $counts['decrement'][] = 'needsoversight';
 78+ }
 79+
 80+
7281 // Newly hidden record
7382 if( $flag == 'hide' && $record->af_hide_count == 0 ) {
7483 $counts['increment'][] = 'invisible';
7584 $counts['decrement'][] = 'visible';
7685 }
 86+ // Unhidden record
 87+ if( $flag == 'unhide') {
 88+ $counts['increment'][] = 'visible';
 89+ $counts['decrement'][] = 'invisible';
 90+ }
7791
7892 // Newly deleted record
7993 if( $flag == 'delete' && $record->af_delete_count == 0 ) {
8094 $counts['increment'][] = 'deleted';
8195 $counts['decrement'][] = 'visible';
8296 }
83 -
 97+ // Undeleted record
 98+ if( $flag == 'undelete' ) {
 99+ $counts['increment'][] = 'visible';
 100+ $counts['decrement'][] = 'deleted';
 101+ }
 102+
84103 // Newly helpful record
85104 if( $flag == 'helpful' && $record->af_helpful_count == 0 ) {
86105 $counts['increment'][] = 'helpful';
87106 }
88 -
89107 // Newly unhelpful record (IE, unhelpful has overtaken helpful)
90108 if( $flag == 'unhelpful'
91 - && ( $record->af_helpful_count - $record->af_unhelpful_count ) == 1 ) {
 109+ && ( ( $record->af_helpful_count - $record->af_unhelpful_count ) == 1 ) ) {
92110 $counts['decrement'][] = 'helpful';
93111 }
94112
@@ -100,7 +118,8 @@
101119 __METHOD__
102120 );
103121
104 - $this->updateFilterCounts( $counts, $params['pageid'] );
 122+ ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $counts['increment'] );
 123+ ApiArticleFeedbackv5Utils::decrementFilterCounts( $pageId, $counts['decrement'] );
105124 }
106125
107126 if ( $error ) {
@@ -121,46 +140,6 @@
122141 );
123142 }
124143
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 -
165144 /**
166145 * Gets the allowed parameters
167146 *
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -274,13 +274,13 @@
275275 }
276276 }
277277
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' );
281279 # If the feedbackrecord had a comment, update that filter count.
282280 if( $has_comment ) {
283 - ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'comment' );
 281+ $filters[] = 'comment';
284282 }
 283+
 284+ ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $filters );
285285 }
286286
287287 /**
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -254,7 +254,7 @@
255255 $where[] = 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) > 0';
256256 break;
257257 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';
259259 break;
260260 case 'comment':
261261 $where[] = 'aa_response_text IS NOT NULL';
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -154,40 +154,62 @@
155155 * Increments the per-page-per-filter count rollups used on the feedback
156156 * page.
157157 *
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
160160 */
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 ) {
162177 $dbw = wfGetDB( DB_MASTER );
163178
164179 $dbw->begin();
165180
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+ }
178188
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+ );
191197
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();
193215 }
194216 }

Status & tagging log