From: Aaron Schulz Date: Wed, 14 Sep 2016 02:38:19 +0000 (-0700) Subject: Replace some MWExceptions with natives ones in /db X-Git-Tag: 1.31.0-rc.0~5589^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=4be70af8c68c7d506c49cc1844ccc21db4177aa4;p=lhc%2Fweb%2Fwiklou.git Replace some MWExceptions with natives ones in /db Change-Id: I94532d09216926d401e94c61acd60fdc6241a2a0 --- diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index cab9438780..97d59d8a96 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -76,7 +76,7 @@ class CloneDatabase { if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) { // Shared tables don't work properly when cloning due to // how prefixes are handled (bug 65654) - throw new MWException( "Cannot clone shared table $tbl." ); + throw new RuntimeException( "Cannot clone shared table $tbl." ); } # Clean up from previous aborted run. So that table escaping # works correctly across DB engines, we need to change the pre- @@ -93,7 +93,7 @@ class CloneDatabase { ) { if ( $oldTableName === $newTableName ) { // Last ditch check to avoid data loss - throw new MWException( "Not dropping new table, as '$newTableName'" + throw new LogicException( "Not dropping new table, as '$newTableName'" . " is name of both the old and the new table." ); } $this->db->dropTable( $tbl, __METHOD__ ); diff --git a/includes/db/Database.php b/includes/db/Database.php index b044e23c18..109dbfea6f 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -340,8 +340,8 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { if ( in_array( $p['driver'], $possibleDrivers ) ) { $driver = $p['driver']; } else { - throw new MWException( __METHOD__ . - " cannot construct Database with type '$dbType' and driver '{$p['driver']}'" ); + throw new InvalidArgumentException( __METHOD__ . + " type '$dbType' does not support driver '{$p['driver']}'" ); } } else { foreach ( $possibleDrivers as $posDriver ) { @@ -740,7 +740,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * not restored on unserialize. */ public function __sleep() { - throw new MWException( 'Database serialization may cause problems, since ' . + throw new RuntimeException( 'Database serialization may cause problems, since ' . 'the connection is not restored on wakeup.' ); } @@ -807,7 +807,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { $closed = $this->closeConnection(); $this->mConn = false; } elseif ( $this->mTrxIdleCallbacks || $this->mTrxEndCallbacks ) { // sanity - throw new MWException( "Transaction callbacks still pending." ); + throw new RuntimeException( "Transaction callbacks still pending." ); } else { $closed = true; } @@ -1736,7 +1736,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { unset( $value[$nullKey] ); } if ( count( $value ) == 0 && !$includeNull ) { - throw new MWException( __METHOD__ . ": empty input for field $field" ); + throw new InvalidArgumentException( __METHOD__ . ": empty input for field $field" ); } elseif ( count( $value ) == 0 ) { // only check if $field is null $list .= "$field IS NULL"; @@ -3132,12 +3132,12 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { public function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { - throw new MWException( + throw new RuntimeException( 'DatabaseBase::duplicateTableStructure is not implemented in descendant class' ); } function listTables( $prefix = null, $fname = __METHOD__ ) { - throw new MWException( 'DatabaseBase::listTables is not implemented in descendant class' ); + throw new RuntimeException( 'DatabaseBase::listTables is not implemented in descendant class' ); } /** @@ -3161,7 +3161,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * @since 1.22 */ public function listViews( $prefix = null, $fname = __METHOD__ ) { - throw new MWException( 'DatabaseBase::listViews is not implemented in descendant class' ); + throw new RuntimeException( 'DatabaseBase::listViews is not implemented in descendant class' ); } /** @@ -3173,7 +3173,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * @since 1.22 */ public function isView( $name ) { - throw new MWException( 'DatabaseBase::isView is not implemented in descendant class' ); + throw new RuntimeException( 'DatabaseBase::isView is not implemented in descendant class' ); } public function timestamp( $ts = 0 ) { @@ -3368,7 +3368,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { MediaWiki\restoreWarnings(); if ( false === $fp ) { - throw new MWException( "Could not open \"{$filename}\".\n" ); + throw new RuntimeException( "Could not open \"{$filename}\".\n" ); } if ( !$fname ) { diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index f8770d2200..269a24873a 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -1080,17 +1080,17 @@ class DatabaseMssql extends Database { */ private function escapeIdentifier( $identifier ) { if ( strlen( $identifier ) == 0 ) { - throw new MWException( "An identifier must not be empty" ); + throw new InvalidArgumentException( "An identifier must not be empty" ); } if ( strlen( $identifier ) > 128 ) { - throw new MWException( "The identifier '$identifier' is too long (max. 128)" ); + throw new InvalidArgumentException( "The identifier '$identifier' is too long (max. 128)" ); } if ( ( strpos( $identifier, '[' ) !== false ) || ( strpos( $identifier, ']' ) !== false ) ) { // It may be allowed if you quoted with double quotation marks, but // that would break if QUOTED_IDENTIFIER is OFF - throw new MWException( "Square brackets are not allowed in '$identifier'" ); + throw new InvalidArgumentException( "Square brackets are not allowed in '$identifier'" ); } return "[$identifier]"; diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index ebeb3a6ce8..f40105815f 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -369,7 +369,7 @@ class DatabaseOracle extends Database { protected function doQuery( $sql ) { wfDebug( "SQL: [$sql]\n" ); if ( !StringUtils::isUtf8( $sql ) ) { - throw new MWException( "SQL encoding is invalid\n$sql" ); + throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" ); } // handle some oracle specifics diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index e6401b3979..ef08ab0705 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -962,7 +962,7 @@ class DatabaseSqlite extends Database { $this->addQuotes( $oldName ) . " AND type='table'", $fname ); $obj = $this->fetchObject( $res ); if ( !$obj ) { - throw new MWException( "Couldn't retrieve structure for table $oldName" ); + throw new RuntimeException( "Couldn't retrieve structure for table $oldName" ); } $sql = $obj->sql; $sql = preg_replace( diff --git a/includes/db/loadbalancer/LBFactoryMulti.php b/includes/db/loadbalancer/LBFactoryMulti.php index d486e1322f..dd7737bb1c 100644 --- a/includes/db/loadbalancer/LBFactoryMulti.php +++ b/includes/db/loadbalancer/LBFactoryMulti.php @@ -178,7 +178,7 @@ class LBFactoryMulti extends LBFactory { foreach ( $required as $key ) { if ( !isset( $conf[$key] ) ) { - throw new MWException( __CLASS__ . ": $key is required in configuration" ); + throw new InvalidArgumentException( __CLASS__ . ": $key is required in configuration" ); } $this->$key = $conf[$key]; } @@ -269,7 +269,7 @@ class LBFactoryMulti extends LBFactory { */ protected function newExternalLB( $cluster, $wiki = false ) { if ( !isset( $this->externalLoads[$cluster] ) ) { - throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); + throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); } $template = $this->serverTemplate; if ( isset( $this->externalTemplateOverrides ) ) { diff --git a/includes/db/loadbalancer/LBFactorySimple.php b/includes/db/loadbalancer/LBFactorySimple.php index 69c4abb5eb..d8590b7003 100644 --- a/includes/db/loadbalancer/LBFactorySimple.php +++ b/includes/db/loadbalancer/LBFactorySimple.php @@ -110,7 +110,7 @@ class LBFactorySimple extends LBFactory { protected function newExternalLB( $cluster, $wiki = false ) { global $wgExternalServers; if ( !isset( $wgExternalServers[$cluster] ) ) { - throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); + throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); } return $this->newLoadBalancer( $wgExternalServers[$cluster] ); diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 5e7743a1a8..687317cb5d 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -261,7 +261,7 @@ class LoadBalancer implements ILoadBalancer { } if ( !count( $nonErrorLoads ) ) { - throw new MWException( "Empty server array given to LoadBalancer" ); + throw new InvalidArgumentException( "Empty server array given to LoadBalancer" ); } # Scale the configured load ratios according to the dynamic load if supported @@ -489,7 +489,7 @@ class LoadBalancer implements ILoadBalancer { public function getConnection( $i, $groups = [], $wiki = false ) { if ( $i === null || $i === false ) { - throw new MWException( 'Attempt to call ' . __METHOD__ . + throw new InvalidArgumentException( 'Attempt to call ' . __METHOD__ . ' with invalid server index' ); } @@ -578,7 +578,7 @@ class LoadBalancer implements ILoadBalancer { $wiki = $dbName; } if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) { - throw new MWException( __METHOD__ . ": connection not found, has " . + throw new InvalidArgumentException( __METHOD__ . ": connection not found, has " . "the connection been freed already?" ); } $conn->setLBInfo( 'foreignPoolRefCount', --$refCount ); @@ -768,7 +768,7 @@ class LoadBalancer implements ILoadBalancer { } if ( !is_array( $server ) ) { - throw new MWException( 'You must update your load-balancing configuration. ' . + throw new InvalidArgumentException( 'You must update your load-balancing configuration. ' . 'See DefaultSettings.php entry for $wgDBservers.' ); }