API: Don't rollback changes if the exception was a UsageException
authorKunal Mehta <legoktm@gmail.com>
Tue, 22 Apr 2014 16:56:40 +0000 (09:56 -0700)
committerKunal Mehta <legoktm@gmail.com>
Tue, 22 Apr 2014 16:56:40 +0000 (09:56 -0700)
In I1b7396ceb, we were trying to log failures to Special:Log, but
since $this->dieUsage throws an exception, the log entry insertion
was being rolled back.

This is similar to I36cd645d which was for index.php calls.

Change-Id: I136ba66d2f939fcdd0c9326e04d686a30449bf4c
Follows-Up: I8f1da51187b281fe4afc0d5a0c49f5caf3612e92

includes/api/ApiMain.php

index ab7c0a6..078e57a 100644 (file)
@@ -387,7 +387,10 @@ class ApiMain extends ApiBase {
         */
        protected function handleException( Exception $e ) {
                // Bug 63145: Rollback any open database transactions
-               MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+               if ( !( $e instanceof UsageException ) ) {
+                       // UsageExceptions are intentional, so don't rollback if that's the case
+                       MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+               }
 
                // Allow extra cleanup and logging
                wfRunHooks( 'ApiMain::onException', array( $this, $e ) );