jenkins-bot has submitted this change and it was merged.

Change subject: Script to delete private data
......................................................................


Script to delete private data

Maintenance script to delete IP, XFF, and UA from votes, for any
election that has been closed for 90 days or more.

Bug: 43529
Change-Id: Ifc7bc30e9a364c7d6b5dc7d431899c71abf555d9
---
A cli/purgePrivateVoteData.php
1 file changed, 118 insertions(+), 0 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/cli/purgePrivateVoteData.php b/cli/purgePrivateVoteData.php
new file mode 100644
index 0000000..24c6665
--- /dev/null
+++ b/cli/purgePrivateVoteData.php
@@ -0,0 +1,118 @@
+<?php
+/**
+ * Purge private data (IP, XFF, UA) from SecurePoll Votes
+ *
+ * Usage: php purgePrivateVoteData.php
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Chris Steipp
+ * @ingroup Maintenance
+ */
+
+
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+       $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+       $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class PurgePrivateVoteData extends Maintenance {
+
+       private $mPurgeDays;
+
+       function __construct() {
+               global $wgSecurePollKeepPrivateInfoDays;
+               parent::__construct();
+               $this->mDescription = 'Script purge private data (IP, XFF, UA) 
from SecurePoll Votes';
+               $this->setBatchSize( 200 );
+               $this->mPurgeDays = $wgSecurePollKeepPrivateInfoDays;
+       }
+
+       public function execute() {
+
+               $electionsToPurge = array();
+               $deleteSets = array();
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $elResult = $dbr->select( 'securepoll_elections',
+                       array( 'el_entity', 'el_title', 'el_end_date' ),
+                       "el_end_date < " . $dbr->addQuotes( $dbr->timestamp( 
time() - ( $this->mPurgeDays * 24 * 60 * 60 ) ) ),
+                       __METHOD__
+               );
+
+               foreach ( $elResult as $row  ) {
+                       $electionsToPurge[] = $row->el_entity;
+                       $this->output( "Election '{$row->el_title}' with end 
date '{$row->el_end_date}' will have data purged\n" );
+               }
+
+               if ( count( $electionsToPurge ) > 0 ) {
+
+                       $conds = array( 'vote_election' => $electionsToPurge );
+                       // In case a partial purge ran previously
+                       $conds[] = "( vote_ip != '' OR vote_xff != '' OR 
vote_ua != '' )";
+                       $minVoteId = 0;
+                       do {
+                               $vRes = $dbr->select( 'securepoll_votes',
+                                       array( 'vote_id' ),
+                                       array_merge( $conds, array( 'vote_id >= 
' . $dbr->addQuotes( $minVoteId ) ) ),
+                                       __METHOD__,
+                                       array( 'ORDER BY' => 'vote_id ASC', 
'LIMIT' => $this->mBatchSize )
+                               );
+
+                               if ( $vRes->numRows() === 0 ) {
+                                       break;
+                               }
+
+                               $setMin = null;
+                               $setMax = null;
+                               foreach ( $vRes as $row  ) {
+                                       if ( $setMin === null ) {
+                                               $setMin = $row->vote_id;
+                                       }
+                                       $setMax = $row->vote_id + 1;
+                               }
+                               $deleteSets[] = array( $setMin, $setMax );
+                               $minVoteId = $setMax;
+                       } while( $vRes->numRows() == $this->mBatchSize );
+
+                       $dbw = wfGetDB( DB_MASTER );
+
+                       foreach ( $deleteSets as $deleteSet ) {
+                               list ( $minId, $maxId ) = $deleteSet;
+                               $dbw->update(
+                                       'securepoll_votes',
+                                       array( 'vote_ip' => '', 'vote_xff' => 
'', 'vote_ua' => '' ),
+                                       array_merge( $conds,
+                                               array( 'vote_id >= ' . 
$dbr->addQuotes( $minId ),
+                                                       'vote_id < ' . 
$dbr->addQuotes( $maxId ) )
+                                       ),
+                                       __METHOD__,
+                                       array( 'LIMIT' => $this->mBatchSize )
+                               );
+                               $this->output( "Purged data from " . 
$dbw->affectedRows() . " votes\n" );
+
+                               wfWaitForSlaves();
+                       }
+               }
+               $this->output( "Done.\n" );
+       }
+}
+
+$maintClass = "PurgePrivateVoteData";
+require_once( RUN_MAINTENANCE_IF_MAIN );

-- 
To view, visit https://gerrit.wikimedia.org/r/45696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc7bc30e9a364c7d6b5dc7d431899c71abf555d9
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/SecurePoll
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Greg Grossmeier <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to