Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php |
— | — | @@ -599,6 +599,8 @@ |
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
| 603 | + $initialCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice ); |
| 604 | + |
603 | 605 | // Handle locking/unlocking campaign |
604 | 606 | if ( $wgRequest->getCheck( 'locked' ) ) { |
605 | 607 | $this->updateLock( $notice, '1' ); |
— | — | @@ -691,6 +693,10 @@ |
692 | 694 | $this->updateProjectLanguages( $notice, $projectLangs ); |
693 | 695 | } |
694 | 696 | |
| 697 | + $finalCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice ); |
| 698 | + $campaignId = $this->getNoticeId( $notice ); |
| 699 | + $this->logCampaignChange( 'modified', $campaignId, $initialCampaignSettings, $finalCampaignSettings ); |
| 700 | + |
695 | 701 | // If there were no errors, reload the page to prevent duplicate form submission |
696 | 702 | if ( !$this->centralNoticeError ) { |
697 | 703 | $wgOut->redirect( $this->getTitle()->getLocalUrl( |
— | — | @@ -774,26 +780,11 @@ |
775 | 781 | } else { |
776 | 782 | $readonly = array( 'disabled' => 'disabled' ); |
777 | 783 | } |
778 | | - $dbr = wfGetDB( DB_SLAVE ); |
779 | | - |
780 | | - // Get campaign info from database |
781 | | - $row = $dbr->selectRow( 'cn_notices', |
782 | | - array( |
783 | | - 'not_id', |
784 | | - 'not_name', |
785 | | - 'not_start', |
786 | | - 'not_end', |
787 | | - 'not_enabled', |
788 | | - 'not_preferred', |
789 | | - 'not_locked', |
790 | | - 'not_geo' |
791 | | - ), |
792 | | - array( 'not_name' => $notice ), |
793 | | - __METHOD__ |
794 | | - ); |
795 | 784 | |
796 | | - if ( $row ) { |
| 785 | + $campaign = CentralNoticeDB::getCampaignSettings( $notice ); |
797 | 786 | |
| 787 | + if ( $campaign ) { |
| 788 | + |
798 | 789 | // If there was an error, we'll need to restore the state of the form |
799 | 790 | if ( $wgRequest->wasPosted() ) { |
800 | 791 | $startArray = $wgRequest->getArray( 'start' ); |
— | — | @@ -818,14 +809,14 @@ |
819 | 810 | $isGeotargeted = $wgRequest->getCheck( 'geotargeted' ); |
820 | 811 | $countries = $wgRequest->getArray( 'geo_countries', array() ); |
821 | 812 | } else { // Defaults |
822 | | - $startTimestamp = $row->not_start; |
823 | | - $endTimestamp = $row->not_end; |
824 | | - $isEnabled = ( $row->not_enabled == '1' ); |
825 | | - $isPreferred = ( $row->not_preferred == '1' ); |
826 | | - $isLocked = ( $row->not_locked == '1' ); |
| 813 | + $startTimestamp = $campaign['start']; |
| 814 | + $endTimestamp = $campaign['end']; |
| 815 | + $isEnabled = ( $campaign['enabled'] == '1' ); |
| 816 | + $isPreferred = ( $campaign['preferred'] == '1' ); |
| 817 | + $isLocked = ( $campaign['locked'] == '1' ); |
827 | 818 | $noticeProjects = $this->getNoticeProjects( $notice ); |
828 | 819 | $noticeLanguages = $this->getNoticeLanguages( $notice ); |
829 | | - $isGeotargeted = ( $row->not_geo == '1' ); |
| 820 | + $isGeotargeted = ( $campaign['geo'] == '1' ); |
830 | 821 | $countries = $this->getNoticeCountries( $notice ); |
831 | 822 | } |
832 | 823 | |
— | — | @@ -877,7 +868,7 @@ |
878 | 869 | Xml::check( 'geotargeted', $isGeotargeted, |
879 | 870 | wfArrayMerge( |
880 | 871 | $readonly, |
881 | | - array( 'value' => $row->not_name, 'id' => 'geotargeted' ) ) ) ); |
| 872 | + array( 'value' => $notice, 'id' => 'geotargeted' ) ) ) ); |
882 | 873 | $htmlOut .= Xml::closeElement( 'tr' ); |
883 | 874 | if ( $isGeotargeted ) { |
884 | 875 | $htmlOut .= Xml::openElement( 'tr', array( 'id'=>'geoMultiSelector' ) ); |
— | — | @@ -896,7 +887,7 @@ |
897 | 888 | $htmlOut .= Xml::tags( 'td', array(), |
898 | 889 | Xml::check( 'enabled', $isEnabled, |
899 | 890 | wfArrayMerge( $readonly, |
900 | | - array( 'value' => $row->not_name, 'id' => 'enabled' ) ) ) ); |
| 891 | + array( 'value' => $notice, 'id' => 'enabled' ) ) ) ); |
901 | 892 | $htmlOut .= Xml::closeElement( 'tr' ); |
902 | 893 | // Preferred |
903 | 894 | $htmlOut .= Xml::openElement( 'tr' ); |
— | — | @@ -905,7 +896,7 @@ |
906 | 897 | $htmlOut .= Xml::tags( 'td', array(), |
907 | 898 | Xml::check( 'preferred', $isPreferred, |
908 | 899 | wfArrayMerge( $readonly, |
909 | | - array( 'value' => $row->not_name, 'id' => 'preferred' ) ) ) ); |
| 900 | + array( 'value' => $notice, 'id' => 'preferred' ) ) ) ); |
910 | 901 | $htmlOut .= Xml::closeElement( 'tr' ); |
911 | 902 | // Locked |
912 | 903 | $htmlOut .= Xml::openElement( 'tr' ); |
— | — | @@ -914,7 +905,7 @@ |
915 | 906 | $htmlOut .= Xml::tags( 'td', array(), |
916 | 907 | Xml::check( 'locked', $isLocked, |
917 | 908 | wfArrayMerge( $readonly, |
918 | | - array( 'value' => $row->not_name, 'id' => 'locked' ) ) ) ); |
| 909 | + array( 'value' => $notice, 'id' => 'locked' ) ) ) ); |
919 | 910 | $htmlOut .= Xml::closeElement( 'tr' ); |
920 | 911 | if ( $this->editable ) { |
921 | 912 | // Locked |
— | — | @@ -923,7 +914,7 @@ |
924 | 915 | Xml::label( wfMsg( 'centralnotice-remove' ), 'remove' ) ); |
925 | 916 | $htmlOut .= Xml::tags( 'td', array(), |
926 | 917 | Xml::check( 'remove', false, |
927 | | - array( 'value' => $row->not_name, 'id' => 'remove' ) ) ); |
| 918 | + array( 'value' => $notice, 'id' => 'remove' ) ) ); |
928 | 919 | $htmlOut .= Xml::closeElement( 'tr' ); |
929 | 920 | } |
930 | 921 | $htmlOut .= Xml::closeElement( 'table' ); |
— | — | @@ -1171,6 +1162,7 @@ |
1172 | 1163 | $this->showError( 'centralnotice-no-language' ); |
1173 | 1164 | return; |
1174 | 1165 | } else { |
| 1166 | + if ( !$geo_countries ) $geo_countries = array(); |
1175 | 1167 | $dbw = wfGetDB( DB_MASTER ); |
1176 | 1168 | $dbw->begin(); |
1177 | 1169 | $start['hour'] = substr( $start['hour'], 0 , 2 ); |
— | — | @@ -1220,7 +1212,7 @@ |
1221 | 1213 | $res = $dbw->insert( 'cn_notice_languages', $insertArray, |
1222 | 1214 | __METHOD__, array( 'IGNORE' ) ); |
1223 | 1215 | |
1224 | | - if ( $geotargeted && $geo_countries ) { |
| 1216 | + if ( $geotargeted ) { |
1225 | 1217 | // Do multi-row insert for campaign countries |
1226 | 1218 | $insertArray = array(); |
1227 | 1219 | foreach( $geo_countries as $code ) { |
— | — | @@ -1235,16 +1227,16 @@ |
1236 | 1228 | // Log the creation of the campaign |
1237 | 1229 | $beginSettings = array(); |
1238 | 1230 | $endSettings = array( |
1239 | | - 'notlog_end_name' => $noticeName, |
1240 | | - 'notlog_end_projects' => implode( ", ", $projects ), |
1241 | | - 'notlog_end_languages' => implode( ", ", $project_languages ), |
1242 | | - 'notlog_end_countries' => implode( ", ", $geo_countries ), |
1243 | | - 'notlog_end_start' => $dbw->timestamp( $startTs ), |
1244 | | - 'notlog_end_end' => $dbw->timestamp( $endTs ), |
1245 | | - 'notlog_end_enabled' => $enabled, |
1246 | | - 'notlog_end_preferred' => 0, |
1247 | | - 'notlog_end_locked' => 0, |
1248 | | - 'notlog_end_geo' => $geotargeted |
| 1231 | + 'name' => $noticeName, |
| 1232 | + 'projects' => implode( ", ", $projects ), |
| 1233 | + 'languages' => implode( ", ", $project_languages ), |
| 1234 | + 'countries' => implode( ", ", $geo_countries ), |
| 1235 | + 'start' => $dbw->timestamp( $startTs ), |
| 1236 | + 'end' => $dbw->timestamp( $endTs ), |
| 1237 | + 'enabled' => $enabled, |
| 1238 | + 'preferred' => 0, |
| 1239 | + 'locked' => 0, |
| 1240 | + 'geo' => $geotargeted |
1249 | 1241 | ); |
1250 | 1242 | $this->logCampaignChange( 'created', $not_id, $beginSettings, $endSettings ); |
1251 | 1243 | |
— | — | @@ -1821,7 +1813,12 @@ |
1822 | 1814 | 'notlog_not_id' => $campaign |
1823 | 1815 | ); |
1824 | 1816 | |
1825 | | - $log = array_merge($log, $beginSettings, $endSettings); |
| 1817 | + foreach ( $beginSettings as $key => $value ) { |
| 1818 | + $log['notlog_begin_'.$key] = $value; |
| 1819 | + } |
| 1820 | + foreach ( $endSettings as $key => $value ) { |
| 1821 | + $log['notlog_end_'.$key] = $value; |
| 1822 | + } |
1826 | 1823 | |
1827 | 1824 | $res = $dbw->insert( 'cn_notice_log', $log ); |
1828 | 1825 | $log_id = $dbw->insertId(); |
Index: trunk/extensions/CentralNotice/patches/patch-notice_logs.sql |
— | — | @@ -6,26 +6,26 @@ |
7 | 7 | `notlog_user_id` int unsigned NOT NULL, |
8 | 8 | `notlog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified', |
9 | 9 | `notlog_not_id` int unsigned NOT NULL, |
10 | | - `notlog_begin_name` varchar(255), |
11 | | - `notlog_end_name` varchar(255), |
12 | | - `notlog_begin_projects` varchar(255), |
13 | | - `notlog_end_projects` varchar(255), |
| 10 | + `notlog_begin_name` varchar(255) DEFAULT NULL, |
| 11 | + `notlog_end_name` varchar(255) DEFAULT NULL, |
| 12 | + `notlog_begin_projects` varchar(255) DEFAULT NULL, |
| 13 | + `notlog_end_projects` varchar(255) DEFAULT NULL, |
14 | 14 | `notlog_begin_languages` text, |
15 | 15 | `notlog_end_languages` text, |
16 | 16 | `notlog_begin_countries` text, |
17 | 17 | `notlog_end_countries` text, |
18 | | - `notlog_begin_start` char(14), |
19 | | - `notlog_end_start` char(14), |
20 | | - `notlog_begin_end` char(14), |
21 | | - `notlog_end_end` char(14), |
22 | | - `notlog_begin_enabled` tinyint(1), |
23 | | - `notlog_end_enabled` tinyint(1), |
24 | | - `notlog_begin_preferred` tinyint(1), |
25 | | - `notlog_end_preferred` tinyint(1), |
26 | | - `notlog_begin_locked` tinyint(1), |
27 | | - `notlog_end_locked` tinyint(1), |
28 | | - `notlog_begin_geo` tinyint(1), |
29 | | - `notlog_end_geo` tinyint(1), |
| 18 | + `notlog_begin_start` char(14) DEFAULT NULL, |
| 19 | + `notlog_end_start` char(14) DEFAULT NULL, |
| 20 | + `notlog_begin_end` char(14) DEFAULT NULL, |
| 21 | + `notlog_end_end` char(14) DEFAULT NULL, |
| 22 | + `notlog_begin_enabled` tinyint(1) DEFAULT NULL, |
| 23 | + `notlog_end_enabled` tinyint(1) DEFAULT NULL, |
| 24 | + `notlog_begin_preferred` tinyint(1) DEFAULT NULL, |
| 25 | + `notlog_end_preferred` tinyint(1) DEFAULT NULL, |
| 26 | + `notlog_begin_locked` tinyint(1) DEFAULT NULL, |
| 27 | + `notlog_end_locked` tinyint(1) DEFAULT NULL, |
| 28 | + `notlog_begin_geo` tinyint(1) DEFAULT NULL, |
| 29 | + `notlog_end_geo` tinyint(1) DEFAULT NULL, |
30 | 30 | `notlog_begin_assignments` text, |
31 | 31 | `notlog_end_assignments` text |
32 | 32 | ) /*$wgDBTableOptions*/; |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -118,7 +118,48 @@ |
119 | 119 | |
120 | 120 | return $notices; |
121 | 121 | } |
| 122 | + |
| 123 | + /* |
| 124 | + * Return settings for a campaign |
| 125 | + * @param $campaignName The name of the campaign |
| 126 | + * @return an array of settings |
| 127 | + */ |
| 128 | + static function getCampaignSettings( $campaignName ) { |
| 129 | + global $wgCentralDBname; |
| 130 | + |
| 131 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname ); |
| 132 | + |
| 133 | + $campaign = array(); |
122 | 134 | |
| 135 | + // Get campaign info from database |
| 136 | + $row = $dbr->selectRow( 'cn_notices', |
| 137 | + array( |
| 138 | + 'not_name', |
| 139 | + 'not_start', |
| 140 | + 'not_end', |
| 141 | + 'not_enabled', |
| 142 | + 'not_preferred', |
| 143 | + 'not_locked', |
| 144 | + 'not_geo' |
| 145 | + ), |
| 146 | + array( 'not_name' => $campaignName ), |
| 147 | + __METHOD__ |
| 148 | + ); |
| 149 | + if ( $row ) { |
| 150 | + $campaign = array( |
| 151 | + 'name' => $row->not_name, |
| 152 | + 'start' => $row->not_start, |
| 153 | + 'end' => $row->not_end, |
| 154 | + 'enabled' => $row->not_enabled, |
| 155 | + 'preferred' => $row->not_preferred, |
| 156 | + 'locked' => $row->not_locked, |
| 157 | + 'geo' => $row->not_geo |
| 158 | + ); |
| 159 | + } |
| 160 | + // TODO: Add languages, projects, and countries |
| 161 | + return $campaign; |
| 162 | + } |
| 163 | + |
123 | 164 | /* |
124 | 165 | * Given one or more campaign ids, return all banners bound to them |
125 | 166 | * @param $campaigns An array of id numbers |