MediaWiki
master
populateUserIsTemp.php
Go to the documentation of this file.
1
<?php
24
use
MediaWiki\User\TempUser\TempUserConfig
;
25
use
Wikimedia\Rdbms\IDatabase
;
26
use
Wikimedia\Rdbms\IExpression
;
27
use
Wikimedia\Rdbms\IReadableDatabase
;
28
29
require_once __DIR__ .
'/Maintenance.php'
;
30
37
class
PopulateUserIsTemp
extends
LoggedUpdateMaintenance
{
38
39
private
TempUserConfig
$tempUserConfig;
40
private
IDatabase
$dbw;
41
private
IReadableDatabase
$dbr;
42
43
public
function
__construct
() {
44
parent::__construct();
45
$this->
addDescription
(
'Populates the user_is_temp field of the user table.'
);
46
$this->
setBatchSize
( 200 );
47
}
48
50
protected
function
getUpdateKey
() {
51
return
__CLASS__;
52
}
53
55
protected
function
doDBUpdates
() {
56
$this->
initServices
();
57
58
if
( !$this->tempUserConfig->isEnabled() ) {
59
// If temporary user auto-creation is disabled, then just return early as there will be no rows to update.
60
return
true
;
61
}
62
63
// Generate a SelectQueryBuilder that selects all temporary users (based on the configured match patterns)
64
// which do have user_is_temp set to 0 (the default) in the the user table.
65
$queryBuilder = $this->dbr->newSelectQueryBuilder()
66
->select(
'user_id'
)
67
->from(
'user'
)
68
->where( [
69
'user_is_temp'
=> 0,
70
$this->tempUserConfig->getMatchCondition( $this->dbr,
'user_name'
, IExpression::LIKE ),
71
] )
72
->limit( $this->
getBatchSize
() ?? 200 )
73
->caller( __METHOD__ );
74
75
do
{
76
// Get a batch of user IDs for temporary accounts that do not have user_is_temp set to 1.
77
$batch = $queryBuilder->fetchFieldValues();
78
if
( count( $batch ) ) {
79
// If there are user IDs in the batch, then update the user_is_temp column to '1' for these rows.
80
$this->dbw->newUpdateQueryBuilder()
81
->update(
'user'
)
82
->set( [
'user_is_temp'
=> 1 ] )
83
->where( [
'user_id'
=> $batch ] )
84
->caller( __METHOD__ )
85
->execute();
86
}
87
}
while
( count( $batch ) >= ( $this->
getBatchSize
() ?? 200 ) );
88
89
return
true
;
90
}
91
100
protected
function
initServices
(): void {
101
$this->tempUserConfig = $this->
getServiceContainer
()->getTempUserConfig();
102
$this->dbw = $this->
getDB
(
DB_PRIMARY
);
103
$this->dbr = $this->
getDB
(
DB_REPLICA
);
104
}
105
}
106
107
$maintClass
= PopulateUserIsTemp::class;
108
require_once RUN_MAINTENANCE_IF_MAIN;
getDB
getDB()
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition
LoggedUpdateMaintenance.php:26
Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:641
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition
Maintenance.php:400
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:329
Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:407
PopulateUserIsTemp
Maintenance script that Fills the user_is_temp column of the user table for users created before MW 1...
Definition
populateUserIsTemp.php:37
PopulateUserIsTemp\__construct
__construct()
Default constructor.
Definition
populateUserIsTemp.php:43
PopulateUserIsTemp\initServices
initServices()
Initialise the services and database connections used by this script.
Definition
populateUserIsTemp.php:100
PopulateUserIsTemp\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.string
Definition
populateUserIsTemp.php:50
PopulateUserIsTemp\doDBUpdates
doDBUpdates()
Do the actual work.All child classes will need to implement this. Return true to log the update as do...
Definition
populateUserIsTemp.php:55
MediaWiki\User\TempUser\TempUserConfig
Interface for temporary user creation config and name matching.
Definition
TempUserConfig.php:18
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition
IDatabase.php:36
Wikimedia\Rdbms\IExpression
Definition
IExpression.php:10
Wikimedia\Rdbms\IReadableDatabase
A database connection without write operations.
Definition
IReadableDatabase.php:33
$maintClass
$maintClass
Definition
populateUserIsTemp.php:107
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
DB_PRIMARY
const DB_PRIMARY
Definition
defines.php:28
maintenance
populateUserIsTemp.php
Generated on Sat Apr 27 2024 10:26:34 for MediaWiki by
1.10.0