3 * Initialize a user preference based on the value
4 * of another preference.
9 require_once __DIR__
. '/Maintenance.php';
12 * Maintenance script that initializes a user preference
13 * based on the value of another preference.
15 * @ingroup Maintenance
17 class InitUserPreference
extends Maintenance
{
18 public function __construct() {
19 parent
::__construct();
22 'Name of the user preference to initialize',
29 'Name of the user preference to take the value from',
34 $this->setBatchSize( 300 );
37 public function execute() {
38 $target = $this->getOption( 'target' );
39 $source = $this->getOption( 'source' );
40 $this->output( "Initializing '$target' based on the value of '$source'\n" );
42 $dbr = $this->getDB( DB_REPLICA
);
43 $dbw = $this->getDB( DB_MASTER
);
45 $iterator = new BatchRowIterator(
48 [ 'up_user', 'up_property' ],
51 $iterator->setFetchColumns( [ 'up_user', 'up_value' ] );
52 $iterator->addConditions( [
53 'up_property' => $source,
54 'up_value IS NOT NULL',
59 foreach ( $iterator as $batch ) {
60 foreach ( $batch as $row ) {
62 'up_user' => $row->up_user
,
63 'up_property' => $target,
64 'up_value' => $row->up_value
,
69 [ 'up_user', 'up_property' ],
74 $processed +
= $dbw->affectedRows();
78 $this->output( "Processed $processed user(s)\n" );
79 $this->output( "Finished!\n" );
83 $maintClass = 'InitUserPreference'; // Tells it to run the class
84 require_once RUN_MAINTENANCE_IF_MAIN
;