Merge "Add styling for the styleguide"
[lhc/web/wiklou.git] / includes / exception / MWExceptionHandler.php
index 64e8999..71917e1 100644 (file)
@@ -32,6 +32,7 @@ class MWExceptionHandler {
 
        /**
         * Report an exception to the user
+        * @param Exception $e
         */
        protected static function report( Exception $e ) {
                global $wgShowExceptionDetails;
@@ -101,6 +102,25 @@ class MWExceptionHandler {
                }
        }
 
+       /**
+        * If there are any open database transactions, roll them back and log
+        * the stack trace of the exception that should have been caught so the
+        * transaction could be aborted properly.
+        * @since 1.23
+        * @param Exception $e
+        */
+       public static function rollbackMasterChangesAndLog( Exception $e ) {
+               $factory = wfGetLBFactory();
+               if ( $factory->hasMasterChanges() ) {
+                       wfDebugLog( 'Bug56269',
+                               'Exception thrown with an uncommited database transaction: ' .
+                                       MWExceptionHandler::getLogMessage( $e ) . "\n" .
+                                       $e->getTraceAsString()
+                       );
+                       $factory->rollbackMasterChanges();
+               }
+       }
+
        /**
         * Exception handler which simulates the appropriate catch() handling:
         *
@@ -111,10 +131,13 @@ class MWExceptionHandler {
         *   } catch ( Exception $e ) {
         *       echo $e->__toString();
         *   }
+        * @param Exception $e
         */
        public static function handle( $e ) {
                global $wgFullyInitialised;
 
+               self::rollbackMasterChangesAndLog( $e );
+
                self::report( $e );
 
                // Final cleanup
@@ -292,7 +315,7 @@ class MWExceptionHandler {
         * @param Exception $e
         * @param bool $pretty Add non-significant whitespace to improve readability (default: false).
         * @param int $escaping Bitfield consisting of FormatJson::.*_OK class constants.
-        * @return string|bool: JSON string if successful; false upon failure
+        * @return string|bool JSON string if successful; false upon failure
         */
        public static function jsonSerializeException( Exception $e, $pretty = false, $escaping = 0 ) {
                global $wgLogExceptionBacktrace;