* will always return the same object, unless the underlying connection or load
* balancer is manually destroyed.
*
+ * Note 2: use $this->getDB() in maintenance scripts that may be invoked by
+ * updater to ensure that a proper database is being updated.
+ *
* @return DatabaseBase
*/
function &wfGetDB( $db, $groups = array(), $wiki = false ) {
// Generic options which might or not be supported by the script
private $mDependantParameters = array();
+ // Used by getDD() / setDB()
+ private $mDb = null;
+
/**
* List of all the core maintenance scripts. This is added
* to scripts added by extensions in $wgMaintenanceScripts
$child = new $maintClass();
$child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
+ if ( !is_null( $this->mDb ) ) {
+ $child->setDB( $this->mDb );
+ }
return $child;
}
*/
public function purgeRedundantText( $delete = true ) {
# Data should come off the master, wrapped in a transaction
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->begin();
$tbl_arc = $dbw->tableName( 'archive' );
return self::$mCoreScripts;
}
+ /**
+ * 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()
+ *
+ * @return DatabaseBase
+ */
+ protected function &getDB( $db, $groups = array(), $wiki = false ) {
+ if ( is_null( $this->mDb ) ) {
+ return wfGetDB( $db, $groups, $wiki );
+ } else {
+ return $this->mDb;
+ }
+ }
+
+ /**
+ * Sets database object to be returned by getDB().
+ *
+ * @param $db DatabaseBase: Database object to be used
+ */
+ public function setDB( &$db ) {
+ $this->mDb = $db;
+ }
+
/**
* Lock the search index
* @param &$db Database object
}
public function execute() {
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
$start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
if ( !$start ) {
$this->output( "Nothing to do.\n" );
public function execute() {
global $wgCategoryCollation, $wgMiserMode;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$force = $this->getOption( 'force' );
$options = array( 'LIMIT' => self::BATCH_SIZE );