http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73044
Revision: 73044
Author: kaldari
Date: 2010-09-15 01:50:11 +0000 (Wed, 15 Sep 2010)
Log Message:
-----------
fixing sql query from r72954, also more readable
Modified Paths:
--------------
trunk/extensions/CentralNotice/SpecialCentralNotice.php
Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-15
01:50:04 UTC (rev 73043)
+++ trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-15
01:50:11 UTC (rev 73044)
@@ -1011,79 +1011,91 @@
preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches );
$location = strtoupper( $matches[0] );
+ $campaigns = array();
$dbr = wfGetDB( DB_SLAVE );
$encTimestamp = $dbr->addQuotes( $dbr->timestamp() );
+
+ // Pull non-geotargeted campaigns
+ $campaignResults1 = $dbr->select(
+ array(
+ 'cn_notices',
+ 'cn_notice_languages'
+ ),
+ array(
+ 'not_id'
+ ),
+ array (
+ "not_start <= $encTimestamp",
+ "not_end >= $encTimestamp",
+ 'not_enabled = 1', // enabled
+ 'not_geo = 0', // not geotargeted
+ 'nl_notice_id = cn_notices.not_id',
+ 'nl_language' => $language,
+ 'not_project' => array( '', $project )
+ ),
+ __METHOD__
+ );
+ foreach ( $campaignResults1 as $row ) {
+ $campaigns[] = $row->not_id;
+ }
if ( $location ) {
- $res = $dbr->select(
+ // Pull geotargeted campaigns
+ $campaignResults2 = $dbr->select(
array(
'cn_notices',
'cn_notice_languages',
- 'cn_notice_countries',
- 'cn_assignments',
- 'cn_templates'
+ 'cn_notice_countries'
),
array(
- 'tmp_name',
- 'SUM(tmp_weight) AS total_weight',
- 'tmp_display_anon',
- 'tmp_display_account'
+ 'not_id'
),
- array (
- "not_start <= $encTimestamp",
- "not_end >= $encTimestamp",
- 'not_enabled = 1',
- 'nc_notice_id = cn_notices.not_id',
- "(not_geo = 0) OR ((not_geo = 1) AND
(nc_country = '$location'))", // not geotargeted or (geotargeted and matches
location)
- 'nl_notice_id = cn_notices.not_id',
- 'nl_language' => $language,
- 'not_project' => array( '', $project ),
-
'cn_notices.not_id=cn_assignments.not_id',
-
'cn_assignments.tmp_id=cn_templates.tmp_id'
- ),
- __METHOD__,
array(
- 'GROUP BY' => 'tmp_name'
- ),
- array(
- 'cn_notice_countries' => array(
- 'LEFT JOIN',
- "nc_country = '$location'"
- )
- )
- );
- } else {
- $res = $dbr->select(
- array(
- 'cn_notices',
- 'cn_notice_languages',
- 'cn_assignments',
- 'cn_templates'
- ),
- array(
- 'tmp_name',
- 'SUM(tmp_weight) AS total_weight',
- 'tmp_display_anon',
- 'tmp_display_account'
- ),
- array (
"not_start <= $encTimestamp",
"not_end >= $encTimestamp",
'not_enabled = 1', // enabled
- 'not_geo = 0', // not geotargeted
+ 'not_geo = 1', // geotargeted
+ 'nc_notice_id = cn_notices.not_id',
+ 'nc_country' => $location,
'nl_notice_id = cn_notices.not_id',
'nl_language' => $language,
- 'not_project' => array( '', $project ),
-
'cn_notices.not_id=cn_assignments.not_id',
-
'cn_assignments.tmp_id=cn_templates.tmp_id'
+ 'not_project' => array( '', $project )
),
- __METHOD__,
- array(
- 'GROUP BY' => 'tmp_name'
- )
+ __METHOD__
);
+ foreach ( $campaignResults2 as $row ) {
+ $campaigns[] = $row->not_id;
+ }
}
+
+ // Convert array of campaigns into a comma-delimited list for
SQL
+ $campaignList = implode(',', $campaigns);
+
+ // Pull all banners assigned to the campaigns
+ $bannerResults = $dbr->select(
+ array(
+ 'cn_notices',
+ 'cn_assignments',
+ 'cn_templates'
+ ),
+ array(
+ 'tmp_name',
+ 'SUM(tmp_weight) AS total_weight',
+ 'tmp_display_anon',
+ 'tmp_display_account'
+ ),
+ array (
+ "cn_notices.not_id IN ($campaignList)",
+ 'cn_notices.not_id=cn_assignments.not_id',
+ 'cn_assignments.tmp_id=cn_templates.tmp_id'
+ ),
+ __METHOD__,
+ array(
+ 'GROUP BY' => 'tmp_name'
+ )
+ );
+
$templates = array();
- foreach ( $res as $row ) {
+ foreach ( $bannerResults as $row ) {
$template = array();
$template['name'] = $row->tmp_name;
$template['weight'] = intval( $row->total_weight );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
