Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -1011,79 +1011,91 @@ |
1012 | 1012 | preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches ); |
1013 | 1013 | $location = strtoupper( $matches[0] ); |
1014 | 1014 | |
| 1015 | + $campaigns = array(); |
1015 | 1016 | $dbr = wfGetDB( DB_SLAVE ); |
1016 | 1017 | $encTimestamp = $dbr->addQuotes( $dbr->timestamp() ); |
| 1018 | + |
| 1019 | + // Pull non-geotargeted campaigns |
| 1020 | + $campaignResults1 = $dbr->select( |
| 1021 | + array( |
| 1022 | + 'cn_notices', |
| 1023 | + 'cn_notice_languages' |
| 1024 | + ), |
| 1025 | + array( |
| 1026 | + 'not_id' |
| 1027 | + ), |
| 1028 | + array ( |
| 1029 | + "not_start <= $encTimestamp", |
| 1030 | + "not_end >= $encTimestamp", |
| 1031 | + 'not_enabled = 1', // enabled |
| 1032 | + 'not_geo = 0', // not geotargeted |
| 1033 | + 'nl_notice_id = cn_notices.not_id', |
| 1034 | + 'nl_language' => $language, |
| 1035 | + 'not_project' => array( '', $project ) |
| 1036 | + ), |
| 1037 | + __METHOD__ |
| 1038 | + ); |
| 1039 | + foreach ( $campaignResults1 as $row ) { |
| 1040 | + $campaigns[] = $row->not_id; |
| 1041 | + } |
1017 | 1042 | if ( $location ) { |
1018 | | - $res = $dbr->select( |
| 1043 | + // Pull geotargeted campaigns |
| 1044 | + $campaignResults2 = $dbr->select( |
1019 | 1045 | array( |
1020 | 1046 | 'cn_notices', |
1021 | 1047 | 'cn_notice_languages', |
1022 | | - 'cn_notice_countries', |
1023 | | - 'cn_assignments', |
1024 | | - 'cn_templates' |
| 1048 | + 'cn_notice_countries' |
1025 | 1049 | ), |
1026 | 1050 | array( |
1027 | | - 'tmp_name', |
1028 | | - 'SUM(tmp_weight) AS total_weight', |
1029 | | - 'tmp_display_anon', |
1030 | | - 'tmp_display_account' |
| 1051 | + 'not_id' |
1031 | 1052 | ), |
1032 | | - array ( |
1033 | | - "not_start <= $encTimestamp", |
1034 | | - "not_end >= $encTimestamp", |
1035 | | - 'not_enabled = 1', |
1036 | | - 'nc_notice_id = cn_notices.not_id', |
1037 | | - "(not_geo = 0) OR ((not_geo = 1) AND (nc_country = '$location'))", // not geotargeted or (geotargeted and matches location) |
1038 | | - 'nl_notice_id = cn_notices.not_id', |
1039 | | - 'nl_language' => $language, |
1040 | | - 'not_project' => array( '', $project ), |
1041 | | - 'cn_notices.not_id=cn_assignments.not_id', |
1042 | | - 'cn_assignments.tmp_id=cn_templates.tmp_id' |
1043 | | - ), |
1044 | | - __METHOD__, |
1045 | 1053 | array( |
1046 | | - 'GROUP BY' => 'tmp_name' |
1047 | | - ), |
1048 | | - array( |
1049 | | - 'cn_notice_countries' => array( |
1050 | | - 'LEFT JOIN', |
1051 | | - "nc_country = '$location'" |
1052 | | - ) |
1053 | | - ) |
1054 | | - ); |
1055 | | - } else { |
1056 | | - $res = $dbr->select( |
1057 | | - array( |
1058 | | - 'cn_notices', |
1059 | | - 'cn_notice_languages', |
1060 | | - 'cn_assignments', |
1061 | | - 'cn_templates' |
1062 | | - ), |
1063 | | - array( |
1064 | | - 'tmp_name', |
1065 | | - 'SUM(tmp_weight) AS total_weight', |
1066 | | - 'tmp_display_anon', |
1067 | | - 'tmp_display_account' |
1068 | | - ), |
1069 | | - array ( |
1070 | 1054 | "not_start <= $encTimestamp", |
1071 | 1055 | "not_end >= $encTimestamp", |
1072 | 1056 | 'not_enabled = 1', // enabled |
1073 | | - 'not_geo = 0', // not geotargeted |
| 1057 | + 'not_geo = 1', // geotargeted |
| 1058 | + 'nc_notice_id = cn_notices.not_id', |
| 1059 | + 'nc_country' => $location, |
1074 | 1060 | 'nl_notice_id = cn_notices.not_id', |
1075 | 1061 | 'nl_language' => $language, |
1076 | | - 'not_project' => array( '', $project ), |
1077 | | - 'cn_notices.not_id=cn_assignments.not_id', |
1078 | | - 'cn_assignments.tmp_id=cn_templates.tmp_id' |
| 1062 | + 'not_project' => array( '', $project ) |
1079 | 1063 | ), |
1080 | | - __METHOD__, |
1081 | | - array( |
1082 | | - 'GROUP BY' => 'tmp_name' |
1083 | | - ) |
| 1064 | + __METHOD__ |
1084 | 1065 | ); |
| 1066 | + foreach ( $campaignResults2 as $row ) { |
| 1067 | + $campaigns[] = $row->not_id; |
| 1068 | + } |
1085 | 1069 | } |
| 1070 | + |
| 1071 | + // Convert array of campaigns into a comma-delimited list for SQL |
| 1072 | + $campaignList = implode(',', $campaigns); |
| 1073 | + |
| 1074 | + // Pull all banners assigned to the campaigns |
| 1075 | + $bannerResults = $dbr->select( |
| 1076 | + array( |
| 1077 | + 'cn_notices', |
| 1078 | + 'cn_assignments', |
| 1079 | + 'cn_templates' |
| 1080 | + ), |
| 1081 | + array( |
| 1082 | + 'tmp_name', |
| 1083 | + 'SUM(tmp_weight) AS total_weight', |
| 1084 | + 'tmp_display_anon', |
| 1085 | + 'tmp_display_account' |
| 1086 | + ), |
| 1087 | + array ( |
| 1088 | + "cn_notices.not_id IN ($campaignList)", |
| 1089 | + 'cn_notices.not_id=cn_assignments.not_id', |
| 1090 | + 'cn_assignments.tmp_id=cn_templates.tmp_id' |
| 1091 | + ), |
| 1092 | + __METHOD__, |
| 1093 | + array( |
| 1094 | + 'GROUP BY' => 'tmp_name' |
| 1095 | + ) |
| 1096 | + ); |
| 1097 | + |
1086 | 1098 | $templates = array(); |
1087 | | - foreach ( $res as $row ) { |
| 1099 | + foreach ( $bannerResults as $row ) { |
1088 | 1100 | $template = array(); |
1089 | 1101 | $template['name'] = $row->tmp_name; |
1090 | 1102 | $template['weight'] = intval( $row->total_weight ); |