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

Change subject: A maintenance script for pre-emptively updating email notice 
option
......................................................................


A maintenance script for pre-emptively updating email notice option

This script is designed to be run prior to the Echo deployment.

Change-Id: I66f532f21183109c6c3c997fa0e666cb19bfc832
---
A maintenance/setEmailOptionTemp.php
1 file changed, 82 insertions(+), 0 deletions(-)

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



diff --git a/maintenance/setEmailOptionTemp.php 
b/maintenance/setEmailOptionTemp.php
new file mode 100755
index 0000000..89600f9
--- /dev/null
+++ b/maintenance/setEmailOptionTemp.php
@@ -0,0 +1,82 @@
+<?php
+/**
+ * Opt existing users out of some echo notifications
+ *
+ * @ingroup Maintenance
+ */
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+       ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+       : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+
+/**
+ * Set existing user's notification prefs to be different than defaults in 
some cases.
+ *
+ * @ingroup Maintenance
+ */
+class SetEmailOptionTemp extends Maintenance {
+
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Script for pre-emptively updating user 
options of users who have opted out of talk page emails";
+               $this->addOption( 'days', 'Only update users that have been 
active within this number of days (maximum 100)', true, true, 'd' );
+               $this->setBatchSize( 100 );
+       }
+
+       public function execute() {
+               $begin = time();
+               $dbr = $this->getDB( DB_SLAVE );
+
+               $total = 0;
+               $updated = 0;
+               $lastUserID = 0;
+
+               // Generate the proper timestamp to use as a threshold
+               $now = time();
+               if ( $this->getOption( 'days' ) > 100 ) {
+                       $days = 100;
+               } else {
+                       $days = $this->getOption( 'days' );
+               }
+               $seconds = $days * 86400;
+               $threshold = $now - $seconds;
+
+               while ( true ) {
+                       $res = $dbr->select(
+                               'user', // table
+                               array( 'user_id' ), // fields
+                               array(
+                                       'user_id > ' . $dbr->addQuotes( 
$lastUserID ),
+                                       'user_touched > ' . $dbr->addQuotes( 
$dbr->timestamp( $threshold ) ),
+                               ), // conditions
+                               __METHOD__, // caller
+                               array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' 
=> 'user_id' ) // options
+                       );
+                       if ( !$res->numRows() ) {
+                               break;
+                       }
+                       $total += $res->numRows();
+                       foreach ( $res as $row ) {
+                               $lastUserID = $row->user_id;
+                               $user = User::newFromId( $row->user_id );
+                               // If the user has disabled 'Email me when my 
user talk page is changed'
+                               // also disable the talk page email 
notification in Echo.
+                               if ( !$user->getOption( 'enotifusertalkpages' )
+                                       && is_null( $user->getOption( 
'echo-subscriptions-email-edit-user-talk' ) )
+                               ) {
+                                       $user->setOption( 
'echo-subscriptions-email-edit-user-talk', 0 );
+                                       $user->saveSettings();
+                                       $updated++;
+                               }
+                       }
+                       $this->output( "Processed: $total; Updated: $updated; 
Last ID processed: $lastUserID\n" );
+                       wfWaitForSlaves();
+               }
+
+               $end = time();
+               $duration = $end - $begin;
+               $this->output( "Done. Elapsed seconds: $duration\n" );
+       }
+}
+
+$maintClass = 'SetEmailOptionTemp'; // Tells it to run the class
+require_once( RUN_MAINTENANCE_IF_MAIN );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I66f532f21183109c6c3c997fa0e666cb19bfc832
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson (WMF) <[email protected]>
Gerrit-Reviewer: Lwelling <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to