function updateCountries($notice, $newCountries)
 {
     $dbw = wfGetDB(DB_MASTER);
     // Get the previously assigned languages
     $oldCountries = CentralNotice::getNoticeCountries($notice);
     // Get the notice id
     $row = $dbw->selectRow('cn_notices', 'not_id', array('not_name' => $notice));
     // Add newly assigned countries
     $addCountries = array_diff($newCountries, $oldCountries);
     $insertArray = array();
     foreach ($addCountries as $code) {
         $insertArray[] = array('nc_notice_id' => $row->not_id, 'nc_country' => $code);
     }
     $res = $dbw->insert('cn_notice_countries', $insertArray, __METHOD__, array('IGNORE'));
     // Remove disassociated countries
     $removeCountries = array_diff($oldCountries, $newCountries);
     if ($removeCountries) {
         $dbw->delete('cn_notice_countries', array('nc_notice_id' => $row->not_id, 'nc_country' => $removeCountries));
     }
 }
 /**
  * Return settings for a campaign
  * @param $campaignName string: The name of the campaign
  * @param $detailed boolean: Whether or not to include targeting and banner assignment info
  * @return an array of settings
  */
 static function getCampaignSettings($campaignName, $detailed = true)
 {
     global $wgCentralDBname;
     // Read from the master database to avoid concurrency problems
     $dbr = wfGetDB(DB_MASTER, array(), $wgCentralDBname);
     $campaign = array();
     // Get campaign info from database
     $row = $dbr->selectRow('cn_notices', array('not_id', 'not_start', 'not_end', 'not_enabled', 'not_preferred', 'not_locked', 'not_geo'), array('not_name' => $campaignName), __METHOD__);
     if ($row) {
         $campaign = array('start' => $row->not_start, 'end' => $row->not_end, 'enabled' => $row->not_enabled, 'preferred' => $row->not_preferred, 'locked' => $row->not_locked, 'geo' => $row->not_geo);
     }
     if ($detailed) {
         $projects = CentralNotice::getNoticeProjects($campaignName);
         $languages = CentralNotice::getNoticeLanguages($campaignName);
         $geo_countries = CentralNotice::getNoticeCountries($campaignName);
         $campaign['projects'] = implode(", ", $projects);
         $campaign['languages'] = implode(", ", $languages);
         $campaign['countries'] = implode(", ", $geo_countries);
         $bannersIn = CentralNoticeDB::getCampaignBanners($row->not_id, true);
         $bannersOut = array();
         // All we want are the banner names and weights
         foreach ($bannersIn as $key => $row) {
             $outKey = $bannersIn[$key]['name'];
             $bannersOut[$outKey] = $bannersIn[$key]['weight'];
         }
         // Encode into a JSON string for storage
         $campaign['banners'] = FormatJson::encode($bannersOut);
     }
     return $campaign;
 }
 public function testGetNoticeCountries()
 {
     $this->assertEquals(array('AF', 'US'), CentralNotice::getNoticeCountries('PHPUnitTestCampaign'));
 }