/**
* Used by getDB() / setDB()
- * @var DatabaseBase
+ * @var IDatabase
*/
private $mDb = null;
private $config;
/**
- * Used to read the options in the order
- * they were passed. Useful for option
- * chaining. (Ex. dumpBackup.php)
+ * Used to read the options in the order they were passed.
+ * Useful for option chaining (Ex. dumpBackup.php). It will
+ * be an empty array if the options are passed in through
+ * loadParamsAndArgs( $self, $opts, $args ).
*
* This is an array of arrays where
- * 0 => the option and 1 => parameter value
+ * 0 => the option and 1 => parameter value.
*
* @var array
*/
}
/**
- * Process command line arguments
- * $mOptions becomes an array with keys set to the option names
- * $mArgs becomes a zero-based array containing the non-option arguments
+ * Load params and arguments from a given array
+ * of command-line arguments
*
- * @param string $self The name of the script, if any
- * @param array $opts An array of options, in form of key=>value
- * @param array $args An array of command line arguments
+ * @since 1.27
+ * @param array $argv
*/
- public function loadParamsAndArgs( $self = null, $opts = null, $args = null ) {
- # If we were given opts or args, set those and return early
- if ( $self ) {
- $this->mSelf = $self;
- $this->mInputLoaded = true;
- }
- if ( $opts ) {
- $this->mOptions = $opts;
- $this->mInputLoaded = true;
- }
- if ( $args ) {
- $this->mArgs = $args;
- $this->mInputLoaded = true;
- }
-
- # If we've already loaded input (either by user values or from $argv)
- # skip on loading it again. The array_shift() will corrupt values if
- # it's run again and again
- if ( $this->mInputLoaded ) {
- $this->loadSpecialVars();
-
- return;
- }
-
- global $argv;
- $this->mSelf = array_shift( $argv );
-
+ public function loadWithArgv( $argv ) {
$options = array();
$args = array();
$this->orderedOptions = array();
}
}
+ /**
+ * Process command line arguments
+ * $mOptions becomes an array with keys set to the option names
+ * $mArgs becomes a zero-based array containing the non-option arguments
+ *
+ * @param string $self The name of the script, if any
+ * @param array $opts An array of options, in form of key=>value
+ * @param array $args An array of command line arguments
+ */
+ public function loadParamsAndArgs( $self = null, $opts = null, $args = null ) {
+ # If we were given opts or args, set those and return early
+ if ( $self ) {
+ $this->mSelf = $self;
+ $this->mInputLoaded = true;
+ }
+ if ( $opts ) {
+ $this->mOptions = $opts;
+ $this->mInputLoaded = true;
+ }
+ if ( $args ) {
+ $this->mArgs = $args;
+ $this->mInputLoaded = true;
+ }
+
+ # If we've already loaded input (either by user values or from $argv)
+ # skip on loading it again. The array_shift() will corrupt values if
+ # it's run again and again
+ if ( $this->mInputLoaded ) {
+ $this->loadSpecialVars();
+
+ return;
+ }
+
+ global $argv;
+ $this->mSelf = $argv[0];
+ $this->loadWithArgv( array_slice( $argv, 1 ) );
+ }
+
/**
* Run some validation checks on the params, etc
*/
public function purgeRedundantText( $delete = true ) {
# Data should come off the master, wrapped in a transaction
$dbw = $this->getDB( DB_MASTER );
- $dbw->begin( __METHOD__ );
+ $this->beginTransaction( $dbw, __METHOD__ );
# Get "active" text records from the revisions table
$this->output( 'Searching for active text records in revisions table...' );
}
# Done
- $dbw->commit( __METHOD__ );
+ $this->commitTransaction( $dbw, __METHOD__ );
}
/**
* If not set, wfGetDB() will be used.
* This function has the same parameters as wfGetDB()
*
- * @return DatabaseBase
+ * @param integer $db DB index (DB_SLAVE/DB_MASTER)
+ * @param array $groups; default: empty array
+ * @param string|bool $wiki; default: current wiki
+ * @return IDatabase
*/
protected function getDB( $db, $groups = array(), $wiki = false ) {
if ( is_null( $this->mDb ) ) {
/**
* Sets database object to be returned by getDB().
*
- * @param DatabaseBase $db Database object to be used
+ * @param IDatabase $db Database object to be used
*/
- public function setDB( $db ) {
+ public function setDB( IDatabase $db ) {
$this->mDb = $db;
}
+ /**
+ * Begin a transcation on a DB
+ *
+ * This method makes it clear that begin() is called from a maintenance script,
+ * which has outermost scope. This is safe, unlike $dbw->begin() called in other places.
+ *
+ * @param IDatabase $dbw
+ * @param string $fname Caller name
+ * @since 1.27
+ */
+ protected function beginTransaction( IDatabase $dbw, $fname ) {
+ $dbw->begin( $fname );
+ }
+
+ /**
+ * Commit a transcation on a DB
+ *
+ * This method makes it clear that commit() is called from a maintenance script,
+ * which has outermost scope. This is safe, unlike $dbw->commit() called in other places.
+ *
+ * @param IDatabase $dbw
+ * @param string $fname Caller name
+ * @since 1.27
+ */
+ protected function commitTransaction( IDatabase $dbw, $fname ) {
+ $dbw->commit( $fname );
+ }
+
+ /**
+ * Rollback a transcation on a DB
+ *
+ * This method makes it clear that rollback() is called from a maintenance script,
+ * which has outermost scope. This is safe, unlike $dbw->rollback() called in other places.
+ *
+ * @param IDatabase $dbw
+ * @param string $fname Caller name
+ * @since 1.27
+ */
+ protected function rollbackTransaction( IDatabase $dbw, $fname ) {
+ $dbw->rollback( $fname );
+ }
+
/**
* Lock the search index
* @param DatabaseBase &$db