r73101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73100‎ | r73101 | r73102 >
Date:23:29, 15 September 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
consolidating similar code for pulling banners
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerListLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php
@@ -64,28 +64,21 @@
6565
6666 if ( $this->language == 'en' && $this->project != null ) {
6767 // See if we have any preferred notices for all of en
68 - $notices = $this->centralNoticeDB->getNotices( '', 'en', null, 1, 1, $this->location );
 68+ $notices = $this->centralNoticeDB->getNotices( null, 'en', null, 1, 1, $this->location );
6969
7070 if ( $notices ) {
71 - // Pull out values
72 - foreach ( $notices as $notice => $val ) {
73 - // Either match against ALL project or a specific project
74 - if ( $val['project'] === '' || $val['project'] == $this->project ) {
75 - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notice );
76 - break;
77 - }
78 - }
 71+ // Pull banners
 72+ $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices );
7973 }
8074 }
8175
8276 if ( !$templates && $this->project == 'wikipedia' ) {
8377 // See if we have any preferred notices for this language wikipedia
8478 $notices = $this->centralNoticeDB->getNotices( 'wikipedia', $this->language, null, 1, 1, $this->location );
 79+
8580 if ( $notices ) {
86 - foreach ( $notices as $notice => $val ) {
87 - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notice );
88 - break;
89 - }
 81+ // Pull banners
 82+ $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices );
9083 }
9184 }
9285
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -1067,39 +1067,9 @@
10681068 }
10691069 }
10701070
1071 - // Pull all banners assigned to the campaigns
1072 - $bannerResults = $dbr->select(
1073 - array(
1074 - 'cn_notices',
1075 - 'cn_assignments',
1076 - 'cn_templates'
1077 - ),
1078 - array(
1079 - 'tmp_name',
1080 - 'SUM(tmp_weight) AS total_weight',
1081 - 'tmp_display_anon',
1082 - 'tmp_display_account'
1083 - ),
1084 - array(
1085 - 'cn_notices.not_id' => $campaigns,
1086 - 'cn_notices.not_id=cn_assignments.not_id',
1087 - 'cn_assignments.tmp_id=cn_templates.tmp_id'
1088 - ),
1089 - __METHOD__,
1090 - array(
1091 - 'GROUP BY' => 'tmp_name'
1092 - )
1093 - );
1094 -
10951071 $templates = array();
1096 - foreach ( $bannerResults as $row ) {
1097 - $template = array();
1098 - $template['name'] = $row->tmp_name;
1099 - $template['weight'] = intval( $row->total_weight );
1100 - $template['display_anon'] = intval( $row->tmp_display_anon );
1101 - $template['display_account'] = intval( $row->tmp_display_account );
1102 - $templates[] = $template;
1103 - }
 1072+ // Pull all banners assigned to the campaigns
 1073+ $templates = $this->centralNoticeDB->selectTemplatesAssigned( $campaigns );
11041074 return $templates;
11051075 }
11061076
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -37,9 +37,6 @@
3838 }
3939
4040 // Use whatever conditional arguments got passed in
41 - if ( $project ) {
42 - $conds[] = "not_project =" . $dbr->addQuotes( $project );
43 - }
4441 if ( $language ) {
4542 $conds[] = "nl_notice_id = cn_notices.not_id";
4643 $conds[] = "nl_language =" . $dbr->addQuotes( $language );
@@ -50,6 +47,7 @@
5148 if ( $preferred ) {
5249 $conds[] = "not_preferred = 1";
5350 }
 51+ $conds[] = 'not_project' => array( '', $project );
5452 $conds[] = "not_geo = 0";
5553 $conds[] = "not_start <= " . $encTimestamp;
5654 $conds[] = "not_end >= " . $encTimestamp;
@@ -58,35 +56,25 @@
5957 $res = $dbr->select(
6058 $tables,
6159 array(
62 - 'not_name',
63 - 'not_project',
64 - 'not_locked',
65 - 'not_enabled',
66 - 'not_preferred'
 60+ 'not_id'
6761 ),
6862 $conds,
6963 __METHOD__
7064 );
7165
72 - // Loop through result set and return attributes
 66+ // Loop through result set and return ids
7367 foreach ( $res as $row ) {
74 - $notice = $row->not_name;
75 - $notices[$notice]['project'] = $row->not_project;
76 - $notices[$notice]['preferred'] = $row->not_preferred;
77 - $notices[$notice]['locked'] = $row->not_locked;
78 - $notices[$notice]['enabled'] = $row->not_enabled;
 68+ $notices[] = $row->not_id;
7969 }
8070
8171 // If a location is passed, also pull geotargeted campaigns that match the location
8272 if ( $location ) {
8373 $tables = array();
8474 $tables[] = "cn_notices";
 75+ $tables[] = "cn_notice_countries";
8576 if ( $language ) {
8677 $tables[] = "cn_notice_languages";
8778 }
88 - if ( $location ) {
89 - $tables[] = "cn_notice_countries";
90 - }
9179
9280 // Use whatever conditional arguments got passed in
9381 $conds = array();
@@ -97,17 +85,17 @@
9886 $conds[] = "nl_notice_id = cn_notices.not_id";
9987 $conds[] = "nl_language =" . $dbr->addQuotes( $language );
10088 }
101 - if ( $location ) {
102 - $conds[] = "not_geo = 1";
103 - $conds[] = "nc_notice_id = cn_notices.not_id";
104 - $conds[] = "nc_country =" . $dbr->addQuotes( $location );
105 - }
 89+
10690 if ( $enabled ) {
10791 $conds[] = "not_enabled = 1";
10892 }
10993 if ( $preferred ) {
11094 $conds[] = "not_preferred = 1";
11195 }
 96+ $conds[] = 'not_project' => array( '', $project );
 97+ $conds[] = "not_geo = 1";
 98+ $conds[] = "nc_notice_id = cn_notices.not_id";
 99+ $conds[] = "nc_country =" . $dbr->addQuotes( $location );
112100 $conds[] = "not_start <= " . $encTimestamp;
113101 $conds[] = "not_end >= " . $encTimestamp;
114102
@@ -115,23 +103,15 @@
116104 $res = $dbr->select(
117105 $tables,
118106 array(
119 - 'not_name',
120 - 'not_project',
121 - 'not_locked',
122 - 'not_enabled',
123 - 'not_preferred'
 107+ 'not_id'
124108 ),
125109 $conds,
126110 __METHOD__
127111 );
128112
129 - // Loop through result set and return attributes
 113+ // Loop through result set and return ids
130114 foreach ( $res as $row ) {
131 - $notice = $row->not_name;
132 - $notices[$notice]['project'] = $row->not_project;
133 - $notices[$notice]['preferred'] = $row->not_preferred;
134 - $notices[$notice]['locked'] = $row->not_locked;
135 - $notices[$notice]['enabled'] = $row->not_enabled;
 115+ $notices[] = $row->not_id;
136116 }
137117 }
138118
@@ -139,9 +119,9 @@
140120 }
141121
142122 /*
143 - * Given a notice return all banners bound to it
 123+ * Given one or more campaign ids, return all banners bound to them
144124 */
145 - public function selectTemplatesAssigned( $notice ) {
 125+ public function selectTemplatesAssigned( $campaigns ) {
146126 $dbr = wfGetDB( DB_SLAVE );
147127
148128 // Pull templates based on join with assignments
@@ -158,7 +138,7 @@
159139 'tmp_display_account'
160140 ),
161141 array(
162 - 'cn_notices.not_name' => $notice,
 142+ 'cn_notices.not_id' => $campaigns,
163143 'cn_notices.not_id = cn_assignments.not_id',
164144 'cn_assignments.tmp_id = cn_templates.tmp_id'
165145 ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r73103db functions should be static, fixing query conds bug in r73101kaldari00:32, 16 September 2010

Comments

#Comment by Catrope (talk | contribs)   18:22, 27 September 2010

Glaring error $conds[] = 'not_project' => array( , $project ); fixed in r73103, which was marked as fixme; marking this one resolved regardless cause the fix does work.

Status & tagging log