Exemplo n.º 1
0
 /**
  * Sets up appropriate entries in the uc_campaigns table for each Campaign
  * Acts everytime a page in the NS_CAMPAIGN namespace is saved
  */
 public static function onPageContentSaveComplete($article, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId)
 {
     if (!$article->getTitle()->inNamespace(NS_CAMPAIGN)) {
         return true;
     }
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $campaignData = $content->getJsonData();
     $insertData = array('campaign_enabled' => $campaignData['enabled'] ? 1 : 0);
     $success = $dbw->upsert('uw_campaigns', array_merge(array('campaign_name' => $article->getTitle()->getDBkey()), $insertData), array('campaign_name'), $insertData);
     $campaign = new UploadWizardCampaign($article->getTitle(), $content->getJsonData());
     // Track the templates being used in the wikitext in this campaign, and add the campaign page
     // as a dependency on those templates, via the templatelinks table. This triggers an update
     // for the Campaign page when LinksUpdate runs due to an edit to any of the templates in
     // the dependency chain - and hence we can invalidate caches when any page that the
     // Campaign depends on changes!
     $templates = $campaign->getTemplates();
     $insertions = array();
     foreach ($templates as $template) {
         $insertions[] = array('tl_from' => $article->getId(), 'tl_namespace' => $template[0], 'tl_title' => $template[1]);
     }
     $success = $success && $dbw->delete('templatelinks', array('tl_from' => $article->getId()));
     $success = $success && $dbw->insert('templatelinks', $insertions, __METHOD__, array('IGNORE'));
     $dbw->commit();
     $campaign->invalidateCache();
     return $success;
 }