MediaWiki  1.34.0
cleanupArchiveUserText.php
Go to the documentation of this file.
1 <?php
2 
3 $IP = getenv( 'MW_INSTALL_PATH' );
4 if ( $IP === false ) {
5  $IP = __DIR__ . '/../../..';
6 }
7 
8 require_once "$IP/maintenance/Maintenance.php";
9 
14  public function __construct() {
15  parent::__construct();
16  $this->addDescription( 'Update the archive table where users were ' .
17  'previously renamed, but their archive contributions were not' );
18 
19  $this->requireExtension( 'Renameuser' );
20  }
21 
22  public function execute() {
24  $this->output( "archive.ar_user_text is no longer used.\n" );
25  return;
26  }
27 
28  $dbw = wfGetDB( DB_MASTER );
29  do {
30  $res = $dbw->select(
31  [ 'archive', 'user' ],
32  [ 'DISTINCT ar_user_text', 'user_name', 'ar_user' ],
33  [
34  'ar_user_text <> user_name',
35  'ar_user = user_id',
36  ],
37  __METHOD__,
38  [ 'LIMIT' => 50 ]
39  );
40  $results = 0;
41  foreach ( $res as $row ) {
42  $results++;
43  $this->output( "User:{$row->ar_user_text} => User:{$row->user_name} " );
44  $dbw->update(
45  'archive',
46  [ 'ar_user_text' => $row->user_name ],
47  [
48  'ar_user_text' => $row->ar_user_text,
49  'ar_user' => $row->ar_user,
50  ],
51  __METHOD__,
52  [ 'LIMIT' => 50 ]
53  );
54  $affected = $dbw->affectedRows();
55  $this->output( "$affected rows\n" );
57  }
58  } while ( $results === 50 );
59  }
60 
61  public function getDbType() {
62  return Maintenance::DB_ADMIN;
63  }
64 }
65 
66 $maintClass = CleanupArchiveUserText::class;
67 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
$IP
$IP
Definition: cleanupArchiveUserText.php:3
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
CleanupArchiveUserText\__construct
__construct()
Default constructor.
Definition: cleanupArchiveUserText.php:14
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$res
$res
Definition: testCompression.php:52
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:2718
RenameuserSQL\actorMigrationWriteOld
static actorMigrationWriteOld()
Indicate whether we should still write old user fields.
Definition: RenameuserSQL.php:405
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
CleanupArchiveUserText\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: cleanupArchiveUserText.php:61
Maintenance\requireExtension
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
Definition: Maintenance.php:638
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\DB_ADMIN
const DB_ADMIN
Definition: Maintenance.php:89
CleanupArchiveUserText
Definition: cleanupArchiveUserText.php:13
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
$maintClass
$maintClass
Definition: cleanupArchiveUserText.php:66
CleanupArchiveUserText\execute
execute()
Do the actual work.
Definition: cleanupArchiveUserText.php:22