function updateProjects($notice, $newProjects)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     // Get the previously assigned projects
     $oldProjects = CentralNotice::getNoticeProjects($notice);
     // Get the notice id
     $row = $dbw->selectRow('cn_notices', 'not_id', array('not_name' => $notice));
     // Add newly assigned projects
     $addProjects = array_diff($newProjects, $oldProjects);
     $insertArray = array();
     foreach ($addProjects as $project) {
         $insertArray[] = array('np_notice_id' => $row->not_id, 'np_project' => $project);
     }
     $res = $dbw->insert('cn_notice_projects', $insertArray, __METHOD__, array('IGNORE'));
     // Remove disassociated projects
     $removeProjects = array_diff($oldProjects, $newProjects);
     if ($removeProjects) {
         $res = $dbw->delete('cn_notice_projects', array('np_notice_id' => $row->not_id, 'np_project' => $removeProjects));
     }
     $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 testGetNoticeProjects()
 {
     $this->assertEquals(array('wikibooks', 'wikipedia'), CentralNotice::getNoticeProjects('PHPUnitTestCampaign'));
 }