use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\LBFactory;
+use Wikimedia\Rdbms\IMaintainableDatabase;
/**
* Abstract maintenance class for quickly writing and churning out
/**
* Used by getDB() / setDB()
- * @var Database
+ * @var IMaintainableDatabase
*/
private $mDb = null;
* @param string $description The description of the param to show on --help
* @param bool $required Is the param required?
* @param bool $withArg Is an argument required with this option?
- * @param string $shortName Character to use as short name
+ * @param string|bool $shortName Character to use as short name
* @param bool $multiOccurrence Can this option be passed multiple times?
*/
protected function addOption( $name, $description, $required = false,
* @param integer $db DB index (DB_REPLICA/DB_MASTER)
* @param array $groups; default: empty array
* @param string|bool $wiki; default: current wiki
- * @return Database
+ * @return IMaintainableDatabase
*/
protected function getDB( $db, $groups = [], $wiki = false ) {
if ( is_null( $this->mDb ) ) {
/**
* Sets database object to be returned by getDB().
*
- * @param IDatabase $db Database object to be used
+ * @param IDatabase $db
*/
public function setDB( IDatabase $db ) {
$this->mDb = $db;
/**
* Lock the search index
- * @param Database &$db
+ * @param IMaintainableDatabase &$db
*/
private function lockSearchindex( $db ) {
$write = [ 'searchindex' ];
/**
* Unlock the tables
- * @param Database &$db
+ * @param IMaintainableDatabase &$db
*/
private function unlockSearchindex( $db ) {
$db->unlockTables( __CLASS__ . '::' . __METHOD__ );
/**
* Unlock and lock again
* Since the lock is low-priority, queued reads will be able to complete
- * @param Database &$db
+ * @param IMaintainableDatabase &$db
*/
private function relockSearchindex( $db ) {
$this->unlockSearchindex( $db );
* Perform a search index update with locking
* @param int $maxLockTime The maximum time to keep the search index locked.
* @param string $callback The function that will update the function.
- * @param Database $dbw
+ * @param IMaintainableDatabase $dbw
* @param array $results
*/
public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) {
/**
* Update the searchindex table for a given pageid
- * @param Database $dbw A database write handle
+ * @param IDatabase $dbw A database write handle
* @param int $pageId The page ID to update.
* @return null|string
*/
require __DIR__ . '/../commandLine.inc';
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script that upgrade for log_id/log_deleted fields in a
* replication-safe way.
class UpdateLogging {
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
public $dbw;
public $batchSize = 1000;
require_once __DIR__ . '/Benchmarker.php';
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE.
*
}
/**
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return void
*/
private function insertData( $dbw ) {
}
/**
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return void
*/
private function delete( $dbw ) {
}
/**
- * @param Database $dbw
+ * @param IMaintainableDatabase $dbw
* @return void
*/
private function truncate( $dbw ) {
require_once __DIR__ . '/Maintenance.php';
use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IDatabase;
/**
* Maintenance script to convert user options to the new `user_properties` table.
/**
* @param ResultWrapper $res
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return null|int
*/
function convertOptionBatch( $res, $dbw ) {
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Maintenance script that deletes revisions which refer to a nonexisting page.
*
* Do this inside a transaction
*
* @param array $id Array of revision id values
- * @param Database $dbw Database class (needs to be a master)
+ * @param IDatabase $dbw Master DB handle
*/
private function deleteRevs( $id, &$dbw ) {
if ( !is_array( $id ) ) {
);
$dbw->delete( 'revision', [ 'rev_id' => $revID ] );
if ( $pageLatest == $revID ) {
- // Database integrity
$newLatest = $dbw->selectField(
'revision',
'rev_id',
/**
* Callback function for each revision, child classes should override
* processRevision instead.
- * @param Database $rev
+ * @param WikiRevision $rev
*/
public function handleRevision( $rev ) {
$title = $rev->getTitle();
require_once __DIR__ . '/backup.inc';
require_once __DIR__ . '/../includes/export/WikiExporter.php';
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\IMaintainableDatabase;
/**
* @ingroup Maintenance
protected $checkpointFiles = [];
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
protected $db;
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Maintenance script used to fetch page text in a subprocess.
*
/**
* May throw a database error if, say, the server dies during query.
- * @param Database $db
+ * @param IDatabase $db
* @param int $id The old_id
* @return string
*/
* @ingroup Maintenance
*/
+require_once __DIR__ . '/Maintenance.php';
+
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\ResultWrapper;
-
-require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IMaintainableDatabase;
/**
* Maintenance script that checks for articles to fix after
class NamespaceConflictChecker extends Maintenance {
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
protected $db;
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script that looks for 'orphan' revisions hooked to pages which
* don't exist and 'childless' pages with no revisions.
/**
* Lock the appropriate tables for the script
- * @param Database $db
+ * @param IMaintainableDatabase $db
* @param string[] $extraTable The name of any extra tables to lock (eg: text)
*/
private function lockTables( $db, $extraTable = [] ) {
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Usage:
* populateContentModel.php --ns=1 --table=page
*/
class PopulateContentModel extends Maintenance {
protected $wikiId;
-
+ /** @var WANObjectCache */
protected $wanCache;
public function __construct() {
$this->wanCache->delete( $revisionKey );
}
- private function updatePageRows( Database $dbw, $pageIds, $model ) {
+ private function updatePageRows( IDatabase $dbw, $pageIds, $model ) {
$count = count( $pageIds );
$this->output( "Setting $count rows to $model..." );
$dbw->update(
$this->output( "done.\n" );
}
- protected function populatePage( Database $dbw, $ns ) {
+ protected function populatePage( IDatabase $dbw, $ns ) {
$toSave = [];
$lastId = 0;
$nsCondition = $ns === 'all' ? [] : [ 'page_namespace' => $ns ];
}
}
- private function updateRevisionOrArchiveRows( Database $dbw, $ids, $model, $table ) {
+ private function updateRevisionOrArchiveRows( IDatabase $dbw, $ids, $model, $table ) {
$prefix = $table === 'archive' ? 'ar' : 'rev';
$model_column = "{$prefix}_content_model";
$format_column = "{$prefix}_content_format";
$this->output( "done.\n" );
}
- protected function populateRevisionOrArchive( Database $dbw, $table, $ns ) {
+ protected function populateRevisionOrArchive( IDatabase $dbw, $table, $ns ) {
$prefix = $table === 'archive' ? 'ar' : 'rev';
$model_column = "{$prefix}_content_model";
$format_column = "{$prefix}_content_format";
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Maintenance script to populate the rc_source field.
*
return __CLASS__;
}
- protected function buildUpdateCondition( Database $dbw ) {
+ protected function buildUpdateCondition( IDatabase $dbw ) {
$rcNew = $dbw->addQuotes( RC_NEW );
$rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
$rcEdit = $dbw->addQuotes( RC_EDIT );
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script to update image metadata records.
*
class ImageBuilder extends Maintenance {
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
protected $dbw;
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script that rebuilds search index table from scratch.
*
const RTI_CHUNK_SIZE = 500;
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
private $db;
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script to refresh image metadata fields.
*
class RefreshImageMetadata extends Maintenance {
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
protected $dbw;
}
/**
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return array
*/
function getConditions( $dbw ) {
* By specifying a null $start or $end, it is also possible to create
* half-bounded or unbounded intervals using this function.
*
- * @param IDatabase $db Database connection
+ * @param IDatabase $db
* @param string $var Field name
* @param mixed $start First value to include or null
* @param mixed $end Last value to include or null
$index = DB_MASTER;
}
- /** @var Database $db DB handle for the appropriate cluster/wiki */
+ /** @var IDatabase $db DB handle for the appropriate cluster/wiki */
$db = $lb->getConnection( $index, [], $wiki );
if ( $replicaDB != '' && $db->getLBInfo( 'master' ) !== null ) {
$this->error( "The server selected ({$db->getServer()}) is not a replica DB.", 1 );
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script to run database schema updates.
*
$this->output( "Going to run database updates for " . wfWikiID() . "\n" );
if ( $db->getType() === 'sqlite' ) {
- /** @var Database|DatabaseSqlite $db */
+ /** @var IMaintainableDatabase|DatabaseSqlite $db */
$this->output( "Using SQLite file: '{$db->getDbFilePath()}'\n" );
}
$this->output( "Depending on the size of your database this may take a while!\n" );
require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Maintenance script that will find all rows in the categorylinks table
* whose collation is out-of-date.
* Return an SQL expression selecting rows which sort above the given row,
* assuming an ordering of cl_collation, cl_to, cl_type, cl_from
* @param stdClass $row
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return string
*/
function getBatchCondition( $row, $dbw ) {