X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=5332d7e07ff87a68f3753afa070596fee52732a1;hb=12d3c539240e38ae7d316f8ca002c7f563563fc0;hp=b698ceffbc68ff8fab9de821c2df8e8420661a18;hpb=dc1632d58ee3b016697667bfc003338141bc3ce7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index b698ceffbc..5332d7e07f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -385,6 +385,13 @@ abstract class ApiBase extends ContextSource { /** * Indicates whether this module requires write mode + * + * This should return true for modules that may require synchronous database writes. + * Modules that do not need such writes should also not rely on master database access, + * since only read queries are needed and each master DB is a single point of failure. + * Additionally, requests that only need replica DBs can be efficiently routed to any + * datacenter via the Promise-Non-Write-API-Action header. + * * @return bool */ public function isWriteMode() { @@ -626,7 +633,7 @@ abstract class ApiBase extends ContextSource { /** * Gets a default replica DB connection object - * @return Database + * @return IDatabase */ protected function getDB() { if ( !isset( $this->mSlaveDB ) ) { @@ -1856,6 +1863,23 @@ abstract class ApiBase extends ContextSource { throw new MWException( 'Successful status passed to ApiBase::dieStatus' ); } + // ApiUsageException needs a fatal status, but this method has + // historically accepted any non-good status. Convert it if necessary. + $status->setOK( false ); + if ( !$status->getErrorsByType( 'error' ) ) { + $newStatus = Status::newGood(); + foreach ( $status->getErrorsByType( 'warning' ) as $err ) { + call_user_func_array( + [ $newStatus, 'fatal' ], + array_merge( [ $err['message'] ], $err['params'] ) + ); + } + if ( !$newStatus->getErrorsByType( 'error' ) ) { + $newStatus->fatal( 'unknownerror-nocode' ); + } + $status = $newStatus; + } + throw new ApiUsageException( $this, $status ); }