r91517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91516‎ | r91517 | r91518 >
Date:01:41, 6 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
Support for logging campaign modifications. Right now only works via listNoticeDetail method (Edit Campaign interface). Need to add support for logging campaign changes from Manage Campaigns interface as well.
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/patches/patch-notice_logs.sql (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
@@ -599,6 +599,8 @@
600600 }
601601 }
602602
 603+ $initialCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice );
 604+
603605 // Handle locking/unlocking campaign
604606 if ( $wgRequest->getCheck( 'locked' ) ) {
605607 $this->updateLock( $notice, '1' );
@@ -691,6 +693,10 @@
692694 $this->updateProjectLanguages( $notice, $projectLangs );
693695 }
694696
 697+ $finalCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice );
 698+ $campaignId = $this->getNoticeId( $notice );
 699+ $this->logCampaignChange( 'modified', $campaignId, $initialCampaignSettings, $finalCampaignSettings );
 700+
695701 // If there were no errors, reload the page to prevent duplicate form submission
696702 if ( !$this->centralNoticeError ) {
697703 $wgOut->redirect( $this->getTitle()->getLocalUrl(
@@ -774,26 +780,11 @@
775781 } else {
776782 $readonly = array( 'disabled' => 'disabled' );
777783 }
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 - );
795784
796 - if ( $row ) {
 785+ $campaign = CentralNoticeDB::getCampaignSettings( $notice );
797786
 787+ if ( $campaign ) {
 788+
798789 // If there was an error, we'll need to restore the state of the form
799790 if ( $wgRequest->wasPosted() ) {
800791 $startArray = $wgRequest->getArray( 'start' );
@@ -818,14 +809,14 @@
819810 $isGeotargeted = $wgRequest->getCheck( 'geotargeted' );
820811 $countries = $wgRequest->getArray( 'geo_countries', array() );
821812 } 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' );
827818 $noticeProjects = $this->getNoticeProjects( $notice );
828819 $noticeLanguages = $this->getNoticeLanguages( $notice );
829 - $isGeotargeted = ( $row->not_geo == '1' );
 820+ $isGeotargeted = ( $campaign['geo'] == '1' );
830821 $countries = $this->getNoticeCountries( $notice );
831822 }
832823
@@ -877,7 +868,7 @@
878869 Xml::check( 'geotargeted', $isGeotargeted,
879870 wfArrayMerge(
880871 $readonly,
881 - array( 'value' => $row->not_name, 'id' => 'geotargeted' ) ) ) );
 872+ array( 'value' => $notice, 'id' => 'geotargeted' ) ) ) );
882873 $htmlOut .= Xml::closeElement( 'tr' );
883874 if ( $isGeotargeted ) {
884875 $htmlOut .= Xml::openElement( 'tr', array( 'id'=>'geoMultiSelector' ) );
@@ -896,7 +887,7 @@
897888 $htmlOut .= Xml::tags( 'td', array(),
898889 Xml::check( 'enabled', $isEnabled,
899890 wfArrayMerge( $readonly,
900 - array( 'value' => $row->not_name, 'id' => 'enabled' ) ) ) );
 891+ array( 'value' => $notice, 'id' => 'enabled' ) ) ) );
901892 $htmlOut .= Xml::closeElement( 'tr' );
902893 // Preferred
903894 $htmlOut .= Xml::openElement( 'tr' );
@@ -905,7 +896,7 @@
906897 $htmlOut .= Xml::tags( 'td', array(),
907898 Xml::check( 'preferred', $isPreferred,
908899 wfArrayMerge( $readonly,
909 - array( 'value' => $row->not_name, 'id' => 'preferred' ) ) ) );
 900+ array( 'value' => $notice, 'id' => 'preferred' ) ) ) );
910901 $htmlOut .= Xml::closeElement( 'tr' );
911902 // Locked
912903 $htmlOut .= Xml::openElement( 'tr' );
@@ -914,7 +905,7 @@
915906 $htmlOut .= Xml::tags( 'td', array(),
916907 Xml::check( 'locked', $isLocked,
917908 wfArrayMerge( $readonly,
918 - array( 'value' => $row->not_name, 'id' => 'locked' ) ) ) );
 909+ array( 'value' => $notice, 'id' => 'locked' ) ) ) );
919910 $htmlOut .= Xml::closeElement( 'tr' );
920911 if ( $this->editable ) {
921912 // Locked
@@ -923,7 +914,7 @@
924915 Xml::label( wfMsg( 'centralnotice-remove' ), 'remove' ) );
925916 $htmlOut .= Xml::tags( 'td', array(),
926917 Xml::check( 'remove', false,
927 - array( 'value' => $row->not_name, 'id' => 'remove' ) ) );
 918+ array( 'value' => $notice, 'id' => 'remove' ) ) );
928919 $htmlOut .= Xml::closeElement( 'tr' );
929920 }
930921 $htmlOut .= Xml::closeElement( 'table' );
@@ -1171,6 +1162,7 @@
11721163 $this->showError( 'centralnotice-no-language' );
11731164 return;
11741165 } else {
 1166+ if ( !$geo_countries ) $geo_countries = array();
11751167 $dbw = wfGetDB( DB_MASTER );
11761168 $dbw->begin();
11771169 $start['hour'] = substr( $start['hour'], 0 , 2 );
@@ -1220,7 +1212,7 @@
12211213 $res = $dbw->insert( 'cn_notice_languages', $insertArray,
12221214 __METHOD__, array( 'IGNORE' ) );
12231215
1224 - if ( $geotargeted && $geo_countries ) {
 1216+ if ( $geotargeted ) {
12251217 // Do multi-row insert for campaign countries
12261218 $insertArray = array();
12271219 foreach( $geo_countries as $code ) {
@@ -1235,16 +1227,16 @@
12361228 // Log the creation of the campaign
12371229 $beginSettings = array();
12381230 $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
12491241 );
12501242 $this->logCampaignChange( 'created', $not_id, $beginSettings, $endSettings );
12511243
@@ -1821,7 +1813,12 @@
18221814 'notlog_not_id' => $campaign
18231815 );
18241816
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+ }
18261823
18271824 $res = $dbw->insert( 'cn_notice_log', $log );
18281825 $log_id = $dbw->insertId();
Index: trunk/extensions/CentralNotice/patches/patch-notice_logs.sql
@@ -6,26 +6,26 @@
77 `notlog_user_id` int unsigned NOT NULL,
88 `notlog_action` enum('created','modified','removed') NOT NULL DEFAULT 'modified',
99 `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,
1414 `notlog_begin_languages` text,
1515 `notlog_end_languages` text,
1616 `notlog_begin_countries` text,
1717 `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,
3030 `notlog_begin_assignments` text,
3131 `notlog_end_assignments` text
3232 ) /*$wgDBTableOptions*/;
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -118,7 +118,48 @@
119119
120120 return $notices;
121121 }
 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();
122134
 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+
123164 /*
124165 * Given one or more campaign ids, return all banners bound to them
125166 * @param $campaigns An array of id numbers

Status & tagging log