r91695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91694‎ | r91695 | r91696 >
Date:22:10, 7 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
Consolidate boolean campaign setting methods. Log the campaign setting changes from the Manage Campaigns interface.
Modified paths:
  • /trunk/extensions/CentralNotice/special/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
@@ -100,16 +100,16 @@
101101
102102 // Set locked/unlocked flag accordingly
103103 foreach ( $lockedNotices as $notice ) {
104 - $this->updateLock( $notice, '1' );
 104+ $this->setBooleanCampaignSetting( $notice, 'locked', 1 );
105105 }
106106 foreach ( $unlockedNotices as $notice ) {
107 - $this->updateLock( $notice, '0' );
 107+ $this->setBooleanCampaignSetting( $notice, 'locked', 0 );
108108 }
109109 // Handle updates if no post content came through (all checkboxes unchecked)
110110 } else {
111111 $allNotices = $this->getAllCampaignNames();
112112 foreach ( $allNotices as $notice ) {
113 - $this->updateLock( $notice, '0' );
 113+ $this->setBooleanCampaignSetting( $notice, 'locked', 0 );
114114 }
115115 }
116116
@@ -121,16 +121,16 @@
122122
123123 // Set enabled/disabled flag accordingly
124124 foreach ( $enabledNotices as $notice ) {
125 - $this->updateEnabled( $notice, '1' );
 125+ $this->setBooleanCampaignSetting( $notice, 'enabled', 1 );
126126 }
127127 foreach ( $disabledNotices as $notice ) {
128 - $this->updateEnabled( $notice, '0' );
 128+ $this->setBooleanCampaignSetting( $notice, 'enabled', 0 );
129129 }
130130 // Handle updates if no post content came through (all checkboxes unchecked)
131131 } else {
132132 $allNotices = $this->getAllCampaignNames();
133133 foreach ( $allNotices as $notice ) {
134 - $this->updateEnabled( $notice, '0' );
 134+ $this->setBooleanCampaignSetting( $notice, 'enabled', 0 );
135135 }
136136 }
137137
@@ -142,23 +142,28 @@
143143
144144 // Set flag accordingly
145145 foreach ( $preferredNotices as $notice ) {
146 - $this->updatePreferred( $notice, '1' );
 146+ $this->setBooleanCampaignSetting( $notice, 'preferred', 1 );
147147 }
148148 foreach ( $unsetNotices as $notice ) {
149 - $this->updatePreferred( $notice, '0' );
 149+ $this->setBooleanCampaignSetting( $notice, 'preferred', 0 );
150150 }
151151 // Handle updates if no post content came through (all checkboxes unchecked)
152152 } else {
153153 $allNotices = $this->getAllCampaignNames();
154154 foreach ( $allNotices as $notice ) {
155 - $this->updatePreferred( $notice, '0' );
 155+ $this->setBooleanCampaignSetting( $notice, 'preferred', 0 );
156156 }
157157 }
158158
159 - // Get all the final campaign settings for logging
160 - $allFinalCampaignSettings = array();
 159+ // Get all the final campaign settings for potential logging
161160 foreach ( $allCampaignNames as $campaignName ) {
162 - $allFinalCampaignSettings[$campaignName] = CentralNoticeDB::getCampaignSettings( $campaignName, false );
 161+ $finalCampaignSettings = CentralNoticeDB::getCampaignSettings( $campaignName, false );
 162+ $diffs = array_diff_assoc( $allInitialCampaignSettings[$campaignName], $finalCampaignSettings );
 163+ // If there are changes, log them
 164+ if ( $diffs ) {
 165+ $campaignId = $this->getNoticeId( $notice );
 166+ $this->logCampaignChange( 'modified', $campaignId, $allInitialCampaignSettings[$campaignName], $finalCampaignSettings );
 167+ }
163168 }
164169 }
165170
@@ -615,34 +620,34 @@
616621
617622 // Handle locking/unlocking campaign
618623 if ( $wgRequest->getCheck( 'locked' ) ) {
619 - $this->updateLock( $notice, '1' );
 624+ $this->setBooleanCampaignSetting( $notice, 'locked', 1 );
620625 } else {
621 - $this->updateLock( $notice, 0 );
 626+ $this->setBooleanCampaignSetting( $notice, 'locked', 0 );
622627 }
623628
624629 // Handle enabling/disabling campaign
625630 if ( $wgRequest->getCheck( 'enabled' ) ) {
626 - $this->updateEnabled( $notice, '1' );
 631+ $this->setBooleanCampaignSetting( $notice, 'enabled', 1 );
627632 } else {
628 - $this->updateEnabled( $notice, 0 );
 633+ $this->setBooleanCampaignSetting( $notice, 'enabled', 0 );
629634 }
630635
631636 // Handle setting campaign to preferred/not preferred
632637 if ( $wgRequest->getCheck( 'preferred' ) ) {
633 - $this->updatePreferred( $notice, '1' );
 638+ $this->setBooleanCampaignSetting( $notice, 'preferred', 1 );
634639 } else {
635 - $this->updatePreferred( $notice, 0 );
 640+ $this->setBooleanCampaignSetting( $notice, 'preferred', 0 );
636641 }
637642
638643 // Handle updating geotargeting
639644 if ( $wgRequest->getCheck( 'geotargeted' ) ) {
640 - $this->updateGeotargeted( $notice, 1 );
 645+ $this->setBooleanCampaignSetting( $notice, 'geo', 1 );
641646 $countries = $wgRequest->getArray( 'geo_countries' );
642647 if ( $countries ) {
643648 $this->updateCountries( $notice, $countries );
644649 }
645650 } else {
646 - $this->updateGeotargeted( $notice, 0 );
 651+ $this->setBooleanCampaignSetting( $notice, 'geo', 0 );
647652 }
648653
649654 // Handle updating the start and end settings
@@ -1349,67 +1354,27 @@
13501355 array( 'not_name' => $noticeName )
13511356 );
13521357 }
1353 -
1354 - /**
1355 - * Update the enabled/disabled state of a campaign
1356 - */
1357 - private function updateEnabled( $noticeName, $isEnabled ) {
1358 - if ( !$this->noticeExists( $noticeName ) ) {
1359 - $this->showError( 'centralnotice-doesnt-exist' );
1360 - } else {
1361 - $dbw = wfGetDB( DB_MASTER );
1362 - $res = $dbw->update( 'cn_notices',
1363 - array( 'not_enabled' => $isEnabled ),
1364 - array( 'not_name' => $noticeName )
1365 - );
1366 - }
1367 - }
13681358
13691359 /**
1370 - * Update the preferred/not preferred state of a campaign
 1360+ * Update a boolean setting on a campaign
 1361+ * @param $noticeName string: Name of the campaign
 1362+ * @param $settingName string: Name of a boolean setting (enabled, preferred, locked, or geo)
 1363+ * @param $settingValue boolean: Value to use for the setting
13711364 */
1372 - function updatePreferred( $noticeName, $isPreferred ) {
 1365+ private function setBooleanCampaignSetting( $noticeName, $settingName, $settingValue ) {
13731366 if ( !$this->noticeExists( $noticeName ) ) {
1374 - $this->showError( 'centralnotice-doesnt-exist' );
 1367+ // Exit quietly since campaign may have been deleted at the same time.
 1368+ return;
13751369 } else {
 1370+ $settingName = strtolower( $settingName );
13761371 $dbw = wfGetDB( DB_MASTER );
13771372 $res = $dbw->update( 'cn_notices',
1378 - array( 'not_preferred' => $isPreferred ),
 1373+ array( 'not_'.$settingName => $settingValue ),
13791374 array( 'not_name' => $noticeName )
13801375 );
13811376 }
13821377 }
13831378
1384 - /**
1385 - * Update the geotargeted/not geotargeted state of a campaign
1386 - */
1387 - function updateGeotargeted( $noticeName, $isGeotargeted ) {
1388 - if ( !$this->noticeExists( $noticeName ) ) {
1389 - $this->showError( 'centralnotice-doesnt-exist' );
1390 - } else {
1391 - $dbw = wfGetDB( DB_MASTER );
1392 - $res = $dbw->update( 'cn_notices',
1393 - array( 'not_geo' => $isGeotargeted ),
1394 - array( 'not_name' => $noticeName )
1395 - );
1396 - }
1397 - }
1398 -
1399 - /**
1400 - * Update the locked/unlocked state of a campaign
1401 - */
1402 - function updateLock( $noticeName, $isLocked ) {
1403 - if ( !$this->noticeExists( $noticeName ) ) {
1404 - $this->showError( 'centralnotice-doesnt-exist' );
1405 - } else {
1406 - $dbw = wfGetDB( DB_MASTER );
1407 - $res = $dbw->update( 'cn_notices',
1408 - array( 'not_locked' => $isLocked ),
1409 - array( 'not_name' => $noticeName )
1410 - );
1411 - }
1412 - }
1413 -
14141379 function updateWeight( $noticeName, $templateId, $weight ) {
14151380 $dbw = wfGetDB( DB_MASTER );
14161381 $noticeId = $this->getNoticeId( $noticeName );

Follow-up revisions

RevisionCommit summaryAuthorDate
r91936follow-up to r91695, fixing wrong campaign ID bugkaldari04:26, 12 July 2011

Status & tagging log