* @defgroup Maintenance Maintenance
*/
+define( 'MW_ENTRY_POINT', 'cli' );
+
// Bail on old versions of PHP, or if composer has not been run yet to install
// dependencies.
require_once __DIR__ . '/../includes/PHPVersionCheck.php';
// Const for getStdin()
const STDIN_ALL = 'all';
- // Array of desired/allowed params
+ /**
+ * Array of desired/allowed params
+ * @var array[]
+ * @phan-var array<string,array{desc:string,require:bool,withArg:string,shortName:string,multiOccurrence:bool}>
+ */
protected $mParams = [];
// Array of mapping short parameters to long ones
*/
protected $mBatchSize = null;
- // Generic options added by addDefaultParams()
+ /**
+ * Generic options added by addDefaultParams()
+ * @var array[]
+ * @phan-var array<string,array{desc:string,require:bool,withArg:string,shortName:string,multiOccurrence:bool}>
+ */
private $mGenericParameters = [];
- // Generic options which might or not be supported by the script
+ /**
+ * Generic options which might or not be supported by the script
+ * @var array[]
+ * @phan-var array<string,array{desc:string,require:bool,withArg:string,shortName:string,multiOccurrence:bool}>
+ */
private $mDependantParameters = [];
/**
"server name detection may fail in command line scripts.", false, true );
$this->addOption( 'profiler', 'Profiler output format (usually "text")', false, true );
// This is named --mwdebug, because --debug would conflict in the phpunit.php CLI script.
- $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, true );
+ $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, false );
# Save generic options to display them separately in help
$this->mGenericParameters = $this->mParams;
+ $wgProfiler
+ [ 'threshold' => $wgProfileLimit ]
);
- $profiler->setTemplated( true );
+ $profiler->setAllowOutput();
Profiler::replaceStubInstance( $profiler );
}
*/
protected function afterFinalSetup() {
if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
+ // @phan-suppress-next-line PhanUndeclaredConstant
call_user_func( MW_CMDLINE_CALLBACK );
}
}
$res = $dbw->select( 'content', 'content_address', [], __METHOD__, [ 'DISTINCT' ] );
$blobStore = MediaWikiServices::getInstance()->getBlobStore();
foreach ( $res as $row ) {
+ // @phan-suppress-next-line PhanUndeclaredMethod
$textId = $blobStore->getTextIdFromAddress( $row->content_address );
if ( $textId ) {
$cur[] = $textId;
}
/**
- * Returns a database to be used by current maintenance script. It can be set by setDB().
- * If not set, wfGetDB() will be used.
- * This function has the same parameters as wfGetDB()
+ * Returns a database to be used by current maintenance script.
+ *
+ * This uses the main LBFactory instance by default unless overriden via setDB().
+ *
+ * This function has the same parameters as LoadBalancer::getConnection().
*
* @param int $db DB index (DB_REPLICA/DB_MASTER)
* @param string|string[] $groups default: empty array
- * @param string|bool $wiki default: current wiki
+ * @param string|bool $dbDomain default: current wiki
* @return IMaintainableDatabase
*/
- protected function getDB( $db, $groups = [], $wiki = false ) {
+ protected function getDB( $db, $groups = [], $dbDomain = false ) {
if ( $this->mDb === null ) {
- return wfGetDB( $db, $groups, $wiki );
+ return MediaWikiServices::getInstance()
+ ->getDBLoadBalancerFactory()
+ ->getMainLB( $dbDomain )
+ ->getMaintenanceConnectionRef( $db, $groups, $dbDomain );
}
+
return $this->mDb;
}
/**
* Sets database object to be returned by getDB().
*
- * @param IDatabase $db
+ * @param IMaintainableDatabase $db
*/
- public function setDB( IDatabase $db ) {
+ public function setDB( IMaintainableDatabase $db ) {
$this->mDb = $db;
}
$title = $titleObj->getPrefixedDBkey();
$this->output( "$title..." );
# Update searchindex
- $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent() );
+ $u = new SearchUpdate( $pageId, $titleObj, $rev->getContent() );
$u->doUpdate();
$this->output( "\n" );
}
protected function updateSkippedMessage() {
$key = $this->getUpdateKey();
- return "Update '{$key}' already logged as completed.";
+ return "Update '{$key}' already logged as completed. Use --force to run it again.";
}
/**