Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php |
— | — | @@ -100,16 +100,16 @@ |
101 | 101 | |
102 | 102 | // Set locked/unlocked flag accordingly |
103 | 103 | foreach ( $lockedNotices as $notice ) { |
104 | | - $this->updateLock( $notice, '1' ); |
| 104 | + $this->setBooleanCampaignSetting( $notice, 'locked', 1 ); |
105 | 105 | } |
106 | 106 | foreach ( $unlockedNotices as $notice ) { |
107 | | - $this->updateLock( $notice, '0' ); |
| 107 | + $this->setBooleanCampaignSetting( $notice, 'locked', 0 ); |
108 | 108 | } |
109 | 109 | // Handle updates if no post content came through (all checkboxes unchecked) |
110 | 110 | } else { |
111 | 111 | $allNotices = $this->getAllCampaignNames(); |
112 | 112 | foreach ( $allNotices as $notice ) { |
113 | | - $this->updateLock( $notice, '0' ); |
| 113 | + $this->setBooleanCampaignSetting( $notice, 'locked', 0 ); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
— | — | @@ -121,16 +121,16 @@ |
122 | 122 | |
123 | 123 | // Set enabled/disabled flag accordingly |
124 | 124 | foreach ( $enabledNotices as $notice ) { |
125 | | - $this->updateEnabled( $notice, '1' ); |
| 125 | + $this->setBooleanCampaignSetting( $notice, 'enabled', 1 ); |
126 | 126 | } |
127 | 127 | foreach ( $disabledNotices as $notice ) { |
128 | | - $this->updateEnabled( $notice, '0' ); |
| 128 | + $this->setBooleanCampaignSetting( $notice, 'enabled', 0 ); |
129 | 129 | } |
130 | 130 | // Handle updates if no post content came through (all checkboxes unchecked) |
131 | 131 | } else { |
132 | 132 | $allNotices = $this->getAllCampaignNames(); |
133 | 133 | foreach ( $allNotices as $notice ) { |
134 | | - $this->updateEnabled( $notice, '0' ); |
| 134 | + $this->setBooleanCampaignSetting( $notice, 'enabled', 0 ); |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
— | — | @@ -142,23 +142,28 @@ |
143 | 143 | |
144 | 144 | // Set flag accordingly |
145 | 145 | foreach ( $preferredNotices as $notice ) { |
146 | | - $this->updatePreferred( $notice, '1' ); |
| 146 | + $this->setBooleanCampaignSetting( $notice, 'preferred', 1 ); |
147 | 147 | } |
148 | 148 | foreach ( $unsetNotices as $notice ) { |
149 | | - $this->updatePreferred( $notice, '0' ); |
| 149 | + $this->setBooleanCampaignSetting( $notice, 'preferred', 0 ); |
150 | 150 | } |
151 | 151 | // Handle updates if no post content came through (all checkboxes unchecked) |
152 | 152 | } else { |
153 | 153 | $allNotices = $this->getAllCampaignNames(); |
154 | 154 | foreach ( $allNotices as $notice ) { |
155 | | - $this->updatePreferred( $notice, '0' ); |
| 155 | + $this->setBooleanCampaignSetting( $notice, 'preferred', 0 ); |
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | | - // Get all the final campaign settings for logging |
160 | | - $allFinalCampaignSettings = array(); |
| 159 | + // Get all the final campaign settings for potential logging |
161 | 160 | 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 | + } |
163 | 168 | } |
164 | 169 | } |
165 | 170 | |
— | — | @@ -615,34 +620,34 @@ |
616 | 621 | |
617 | 622 | // Handle locking/unlocking campaign |
618 | 623 | if ( $wgRequest->getCheck( 'locked' ) ) { |
619 | | - $this->updateLock( $notice, '1' ); |
| 624 | + $this->setBooleanCampaignSetting( $notice, 'locked', 1 ); |
620 | 625 | } else { |
621 | | - $this->updateLock( $notice, 0 ); |
| 626 | + $this->setBooleanCampaignSetting( $notice, 'locked', 0 ); |
622 | 627 | } |
623 | 628 | |
624 | 629 | // Handle enabling/disabling campaign |
625 | 630 | if ( $wgRequest->getCheck( 'enabled' ) ) { |
626 | | - $this->updateEnabled( $notice, '1' ); |
| 631 | + $this->setBooleanCampaignSetting( $notice, 'enabled', 1 ); |
627 | 632 | } else { |
628 | | - $this->updateEnabled( $notice, 0 ); |
| 633 | + $this->setBooleanCampaignSetting( $notice, 'enabled', 0 ); |
629 | 634 | } |
630 | 635 | |
631 | 636 | // Handle setting campaign to preferred/not preferred |
632 | 637 | if ( $wgRequest->getCheck( 'preferred' ) ) { |
633 | | - $this->updatePreferred( $notice, '1' ); |
| 638 | + $this->setBooleanCampaignSetting( $notice, 'preferred', 1 ); |
634 | 639 | } else { |
635 | | - $this->updatePreferred( $notice, 0 ); |
| 640 | + $this->setBooleanCampaignSetting( $notice, 'preferred', 0 ); |
636 | 641 | } |
637 | 642 | |
638 | 643 | // Handle updating geotargeting |
639 | 644 | if ( $wgRequest->getCheck( 'geotargeted' ) ) { |
640 | | - $this->updateGeotargeted( $notice, 1 ); |
| 645 | + $this->setBooleanCampaignSetting( $notice, 'geo', 1 ); |
641 | 646 | $countries = $wgRequest->getArray( 'geo_countries' ); |
642 | 647 | if ( $countries ) { |
643 | 648 | $this->updateCountries( $notice, $countries ); |
644 | 649 | } |
645 | 650 | } else { |
646 | | - $this->updateGeotargeted( $notice, 0 ); |
| 651 | + $this->setBooleanCampaignSetting( $notice, 'geo', 0 ); |
647 | 652 | } |
648 | 653 | |
649 | 654 | // Handle updating the start and end settings |
— | — | @@ -1349,67 +1354,27 @@ |
1350 | 1355 | array( 'not_name' => $noticeName ) |
1351 | 1356 | ); |
1352 | 1357 | } |
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 | | - } |
1368 | 1358 | |
1369 | 1359 | /** |
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 |
1371 | 1364 | */ |
1372 | | - function updatePreferred( $noticeName, $isPreferred ) { |
| 1365 | + private function setBooleanCampaignSetting( $noticeName, $settingName, $settingValue ) { |
1373 | 1366 | 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; |
1375 | 1369 | } else { |
| 1370 | + $settingName = strtolower( $settingName ); |
1376 | 1371 | $dbw = wfGetDB( DB_MASTER ); |
1377 | 1372 | $res = $dbw->update( 'cn_notices', |
1378 | | - array( 'not_preferred' => $isPreferred ), |
| 1373 | + array( 'not_'.$settingName => $settingValue ), |
1379 | 1374 | array( 'not_name' => $noticeName ) |
1380 | 1375 | ); |
1381 | 1376 | } |
1382 | 1377 | } |
1383 | 1378 | |
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 | | - |
1414 | 1379 | function updateWeight( $noticeName, $templateId, $weight ) { |
1415 | 1380 | $dbw = wfGetDB( DB_MASTER ); |
1416 | 1381 | $noticeId = $this->getNoticeId( $noticeName ); |