Lwelling has uploaded a new change for review.
https://gerrit.wikimedia.org/r/60786
Change subject: Maintainence script to copy the preference of existing users
who have opted out of talk page email notifications to the analogous setting in
the Echo version of talk notifications
......................................................................
Maintainence script to copy the preference of existing users who have opted out
of talk page email notifications to the analogous setting in the Echo version of
talk notifications
Change-Id: I5cdaf261d042f3586d2d02fed672ee35df5a9b90
---
A maintenance/copyExistingEmailPreference.php
1 file changed, 65 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/86/60786/1
diff --git a/maintenance/copyExistingEmailPreference.php
b/maintenance/copyExistingEmailPreference.php
new file mode 100644
index 0000000..536f2b1
--- /dev/null
+++ b/maintenance/copyExistingEmailPreference.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Copy existing users preference on whether to get email talk page
notifications
+ * to the new notification system
+ *
+ * @ingroup Maintenance
+ */
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+ : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+
+/**
+ * Copy user's notification pref from the old talk page email notification
setting to the new one
+ *
+ * @ingroup Maintenance
+ */
+class CopyExistingEmailPreference extends Maintenance {
+
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Script for install time copying of users
who have opted out of talk page emails";
+ $this->addOption( 'batch', 'Batch size for SQL partitioning',
false, true );
+ }
+
+ public function execute() {
+ $dbw = $this->getDB( DB_MASTER );
+
+ if( $this->hasOption( 'batch' ) ) {
+ $batch = $this->getOption( 'batch' );
+ } else {
+ $batch = 3;
+ }
+
+ // count the number of user who have opted out under the old
system.
+ // DatabaseBase::query does not return rows affected
+ $users = $dbw->selectField( 'user_properties', 'COUNT(*)',
array( "up_property='enotifusertalkpages'" ), __METHOD__ );
+
+ $total = 0;
+
+ // risks missing people if extra users opt out between script
starting and finishing
+ for( $i = 0; $i<$users; $i+=$batch ) {
+ $sql = "INSERT IGNORE INTO user_properties
+SELECT up_user, 'echo-subscriptions-email-edit-user-talk', up_value
+FROM user_properties
+WHERE up_property = 'enotifusertalkpages'
+ORDER BY up_user LIMIT $batch OFFSET $total";
+
+ $res = $dbw->query(
+ $sql,
+ __METHOD__, // caller
+ true // ignore errors
+ );
+
+ $total += $batch;
+
+ if( $total < $users ) {
+ $this->output( "Total Updated: $total\n" );
+ }
+ }
+ $this->output( "Done. Final total: $users\n" );
+ }
+}
+
+$maintClass = 'CopyExistingEmailPreference'; // Tells it to run the class
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/60786
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5cdaf261d042f3586d2d02fed672ee35df5a9b90
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Lwelling <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits