Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7406350
migratePass0.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
migratePass0.php
View Options
<?php
// --> disable account creations, password changes
// pass 0:
// * generate 'globalnames' and 'localnames' entries for each user on each wiki
// --> enable
namespace
MediaWiki\Extension\CentralAuth\Maintenance
;
$IP
=
getenv
(
'MW_INSTALL_PATH'
);
if
(
$IP
===
false
)
{
$IP
=
__DIR__
.
'/../../..'
;
}
require_once
"$IP/maintenance/Maintenance.php"
;
use
MediaWiki\Extension\CentralAuth\User\CentralAuthUser
;
use
MediaWiki\Maintenance\Maintenance
;
/**
* Copy user data for this wiki into the globalnames and localnames table
*/
class
MigratePass0
extends
Maintenance
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
requireExtension
(
'CentralAuth'
);
}
public
function
execute
()
{
global
$wgDBname
;
$this
->
output
(
"CentralAuth migration pass 0:
\n
"
);
$this
->
output
(
"$wgDBname preparing migration data...
\n
"
);
$this
->
doPassZero
();
$this
->
output
(
"done.
\n
"
);
}
private
function
doPassZero
()
{
global
$wgDBname
;
$dbr
=
$this
->
getDB
(
DB_REPLICA
);
$chunkSize
=
1000
;
$start
=
microtime
(
true
);
$migrated
=
0
;
$users
=
[];
// List all user accounts on this wiki in the migration table
// on the central authentication server.
$lastUser
=
$dbr
->
newSelectQueryBuilder
()
->
select
(
'MAX(user_id)'
)
->
from
(
'user'
)
->
caller
(
__METHOD__
)
->
fetchField
();
for
(
$min
=
0
;
$min
<=
$lastUser
;
$min
+=
$chunkSize
)
{
$max
=
$min
+
$chunkSize
-
1
;
$result
=
$dbr
->
newSelectQueryBuilder
()
->
select
(
[
'user_id'
,
'user_name'
]
)
->
from
(
'user'
)
->
where
(
[
$dbr
->
expr
(
'user_id'
,
'>='
,
$min
),
$dbr
->
expr
(
'user_id'
,
'<='
,
$max
),
]
)
->
caller
(
__METHOD__
)
->
fetchResultSet
();
foreach
(
$result
as
$row
)
{
$users
[
intval
(
$row
->
user_id
)]
=
$row
->
user_name
;
++
$migrated
;
}
CentralAuthUser
::
storeMigrationData
(
$wgDBname
,
$users
);
// clear the array for the next pass
$users
=
[];
$delta
=
microtime
(
true
)
-
$start
;
$rate
=
$delta
?
$migrated
/
$delta
:
0.0
;
$this
->
output
(
sprintf
(
"%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).
\n
"
,
$wgDBname
,
$migrated
,
min
(
$max
,
$lastUser
)
/
$lastUser
*
100.0
,
$delta
,
$rate
)
);
if
(
(
$min
+
$chunkSize
)
%
(
$chunkSize
*
10
)
==
0
)
{
$this
->
output
(
"Waiting for replicas to catch up ... "
);
$this
->
waitForReplication
();
$this
->
output
(
"done
\n
"
);
}
}
}
}
$maintClass
=
MigratePass0
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 20:21 (1 d, 9 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
38/29/960a5501263201ebf26e3048e86a
Default Alt Text
migratePass0.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment