Page MenuHomePhabricator
Paste P2521

listUnattached.php
ActivePublic

Authored by Legoktm on Jan 22 2016, 9:29 PM.
Tags
None
Referenced Files
F3270156: listUnattached.php
Feb 24 2016, 5:27 AM
Subscribers
<?php
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
require_once( "$IP/maintenance/Maintenance.php" );
/**
* Lists all unattached accounts in a format friendly for migrateAccount.php
*/
class ListUnattached extends Maintenance {
private $lName = '';
private $lWiki = '';
public function __construct() {
parent::__construct();
$this->addOption( 'wiki', 'Output wiki name', false, false );
$this->setBatchSize( 1000 );
}
/**
* Fetches unattached accounts and attempts to continue.
*
* @return ResultWrapper
*/
private function doQuery() {
$dbr = CentralAuthUtils::getCentralSlaveDB();
$rows = $dbr->select(
array( 'localnames', 'localuser' ),
array( 'ln_name AS name', 'ln_wiki AS wiki' ),
array(
$dbr->makeList(
array(
'ln_name > ' . $dbr->addQuotes( $this->lName ),
'ln_name = ' . $dbr->addQuotes( $this->lName ) . ' AND ln_wiki > ' .
$dbr->addQuotes( $this->lWiki )
),
LIST_OR
),
'lu_attached_method IS NULL'
),
__METHOD__,
array(
'LIMIT' => $this->mBatchSize,
'ORDER BY' => array( 'ln_name', 'ln_wiki' ),
),
array( 'localuser' => array( 'LEFT JOIN', 'ln_name=lu_name AND ln_wiki=lu_wiki' ) )
);
return $rows;
}
public function execute() {
$outputWiki = $this->hasOption( 'wiki' ) && false;
do {
$rows = $this->doQuery();
foreach ( $rows as $row ) {
$this->lName = $row->name;
$this->lWiki = $row->wiki;
if ( $outputWiki ) {
$this->output( "$row->name\t$row->wiki\n" );
} else {
$this->output( "$row->name\n" );
}
}
} while ( $rows->numRows() !== 0 );
}
}
$maintClass = 'ListUnattached';
require_once RUN_MAINTENANCE_IF_MAIN;

Event Timeline

Legoktm changed the title of this paste from untitled to listUnattached.php.Jan 22 2016, 9:29 PM
Legoktm edited the content of this paste. (Show Details)
Liuxinyu970226 updated the paste's language from autodetect to php.Dec 31 2016, 1:04 AM
Liuxinyu970226 subscribed.