6require_once __DIR__ .
'/Maintenance.php';
21 parent::__construct();
24 'Name of the user preference to initialize',
31 'Name of the user preference to take the value from',
42 $this->
output(
"Initializing '$target' based on the value of '$source'\n" );
49 $dbr->newSelectQueryBuilder()
50 ->from(
'user_properties' )
51 ->select( [
'up_user',
'up_value' ] )
54 $dbr->expr(
'up_value',
'!=',
null ),
55 $dbr->expr(
'up_value',
'!=',
'0' ),
57 ->caller( __METHOD__ ),
58 [
'up_user',
'up_property' ],
63 foreach ( $iterator as $batch ) {
64 foreach ( $batch as $row ) {
65 $dbw->newInsertQueryBuilder()
66 ->insertInto(
'user_properties' )
68 'up_user' => $row->up_user,
69 'up_property' => $target,
70 'up_value' => $row->up_value,
72 ->onDuplicateKeyUpdate()
73 ->uniqueIndexFields( [
'up_user',
'up_property' ] )
74 ->set( [
'up_value' => $row->up_value ] )
75 ->caller( __METHOD__ )->execute();
77 $processed += $dbw->affectedRows();
81 $this->
output(
"Processed $processed user(s)\n" );
82 $this->
output(
"Finished!\n" );
88require_once RUN_MAINTENANCE_IF_MAIN;
Allows iterating a large number of rows in batches transparently.
Maintenance script that initializes a user preference based on the value of another preference.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.