From: jenkins-bot Date: Fri, 3 Mar 2017 18:37:03 +0000 (+0000) Subject: Merge "Maintenance: init a user preference based on another preference" X-Git-Tag: 1.31.0-rc.0~3909 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=900843f7ee9131ebdbe839fafffb70b8e293a8b9;hp=732c91eb5fb224db6140dc47dda90af05726f4a0;p=lhc%2Fweb%2Fwiklou.git Merge "Maintenance: init a user preference based on another preference" --- diff --git a/autoload.php b/autoload.php index 62500e46a4..793b973e85 100644 --- a/autoload.php +++ b/autoload.php @@ -628,6 +628,7 @@ $wgAutoloadLocalClasses = [ 'InfoAction' => __DIR__ . '/includes/actions/InfoAction.php', 'InitEditCount' => __DIR__ . '/maintenance/initEditCount.php', 'InitSiteStats' => __DIR__ . '/maintenance/initSiteStats.php', + 'InitUserPreference' => __DIR__ . '/maintenance/initUserPreference.php', 'InstallDocFormatter' => __DIR__ . '/includes/installer/InstallDocFormatter.php', 'Installer' => __DIR__ . '/includes/installer/Installer.php', 'InstallerOverrides' => __DIR__ . '/includes/installer/InstallerOverrides.php', diff --git a/maintenance/initUserPreference.php b/maintenance/initUserPreference.php new file mode 100644 index 0000000000..f4da570fbb --- /dev/null +++ b/maintenance/initUserPreference.php @@ -0,0 +1,84 @@ +addOption( + 'target', + 'Name of the user preference to initialize', + true, + true, + 't' + ); + $this->addOption( + 'source', + 'Name of the user preference to take the value from', + true, + true, + 's' + ); + $this->setBatchSize( 300 ); + } + + public function execute() { + $target = $this->getOption( 'target' ); + $source = $this->getOption( 'source' ); + $this->output( "Initializing '$target' based on the value of '$source'\n" ); + + $dbr = $this->getDB( DB_REPLICA ); + $dbw = $this->getDB( DB_MASTER ); + + $iterator = new BatchRowIterator( + $dbr, + 'user_properties', + [ 'up_user', 'up_property' ], + $this->mBatchSize + ); + $iterator->setFetchColumns( [ 'up_user', 'up_value' ] ); + $iterator->addConditions( [ + 'up_property' => $source, + 'up_value IS NOT NULL', + 'up_value != 0', + ] ); + + $processed = 0; + foreach ( $iterator as $batch ) { + foreach ( $batch as $row ) { + $values = [ + 'up_user' => $row->up_user, + 'up_property' => $target, + 'up_value' => $row->up_value, + ]; + $dbw->upsert( + 'user_properties', + $values, + [ 'up_user', 'up_property' ], + $values, + __METHOD__ + ); + + $processed += $dbw->affectedRows(); + } + } + + $this->output( "Processed $processed user(s)\n" ); + $this->output( "Finished!\n" ); + } +} + +$maintClass = 'InitUserPreference'; // Tells it to run the class +require_once RUN_MAINTENANCE_IF_MAIN;