function updateProjectLanguages($notice, $newLanguages)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     // Get the previously assigned languages
     $oldLanguages = CentralNotice::getNoticeLanguages($notice);
     // Get the notice id
     $row = $dbw->selectRow('cn_notices', 'not_id', array('not_name' => $notice));
     // Add newly assigned languages
     $addLanguages = array_diff($newLanguages, $oldLanguages);
     $insertArray = array();
     foreach ($addLanguages as $code) {
         $insertArray[] = array('nl_notice_id' => $row->not_id, 'nl_language' => $code);
     }
     $res = $dbw->insert('cn_notice_languages', $insertArray, __METHOD__, array('IGNORE'));
     // Remove disassociated languages
     $removeLanguages = array_diff($oldLanguages, $newLanguages);
     if ($removeLanguages) {
         $res = $dbw->delete('cn_notice_languages', array('nl_notice_id' => $row->not_id, 'nl_language' => $removeLanguages));
     }
     $dbw->commit();
 }
 /**
  * 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 testGetNoticeLanguages()
 {
     $this->assertEquals(array('de', 'en'), CentralNotice::getNoticeLanguages('PHPUnitTestCampaign'));
 }