MediaWiki  1.30.0
initUserPreference.php
Go to the documentation of this file.
1 <?php
9 require_once __DIR__ . '/Maintenance.php';
10 
18  public function __construct() {
19  parent::__construct();
20  $this->addOption(
21  'target',
22  'Name of the user preference to initialize',
23  true,
24  true,
25  't'
26  );
27  $this->addOption(
28  'source',
29  'Name of the user preference to take the value from',
30  true,
31  true,
32  's'
33  );
34  $this->setBatchSize( 300 );
35  }
36 
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" );
41 
42  $dbr = $this->getDB( DB_REPLICA );
43  $dbw = $this->getDB( DB_MASTER );
44 
45  $iterator = new BatchRowIterator(
46  $dbr,
47  'user_properties',
48  [ 'up_user', 'up_property' ],
49  $this->mBatchSize
50  );
51  $iterator->setFetchColumns( [ 'up_user', 'up_value' ] );
52  $iterator->addConditions( [
53  'up_property' => $source,
54  'up_value IS NOT NULL',
55  'up_value != 0',
56  ] );
57 
58  $processed = 0;
59  foreach ( $iterator as $batch ) {
60  foreach ( $batch as $row ) {
61  $values = [
62  'up_user' => $row->up_user,
63  'up_property' => $target,
64  'up_value' => $row->up_value,
65  ];
66  $dbw->upsert(
67  'user_properties',
68  $values,
69  [ 'up_user', 'up_property' ],
70  $values,
71  __METHOD__
72  );
73 
74  $processed += $dbw->affectedRows();
75  }
76  }
77 
78  $this->output( "Processed $processed user(s)\n" );
79  $this->output( "Finished!\n" );
80  }
81 }
82 
83 $maintClass = 'InitUserPreference'; // Tells it to run the class
84 require_once RUN_MAINTENANCE_IF_MAIN;
InitUserPreference\execute
execute()
Do the actual work.
Definition: initUserPreference.php:37
$maintClass
$maintClass
Definition: initUserPreference.php:83
BatchRowIterator
Definition: BatchRowIterator.php:29
InitUserPreference\__construct
__construct()
Default constructor.
Definition: initUserPreference.php:18
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
$source
$source
Definition: mwdoc-filter.php:46
$batch
$batch
Definition: linkcache.txt:23
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
InitUserPreference
Initialize a user preference based on the value of another preference.
Definition: initUserPreference.php:17
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:314