Paladox has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314861

Change subject: Fix postgres support
......................................................................

Fix postgres support

Follows up Ic247a7b42a686f170f7abe6ec584459f3db4ed69 which broke the
support

Bug: T147599
Change-Id: If9b1a0586eed5248a96b2e19e08f542ca979c4cb
---
M includes/libs/rdbms/database/Database.php
1 file changed, 43 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/61/314861/1

diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 9f1f228..4894577 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -2168,12 +2168,20 @@
                        $ok = $this->insert( $table, $rows, $fname, [ 'IGNORE' 
] ) && $ok;
                } catch ( Exception $e ) {
                        if ( $useTrx ) {
-                               $this->rollback( $fname, 
self::FLUSHING_INTERNAL );
+                               if ( $this->getDB()->getType() == 'postgres' ) {
+                                       $this->rollback( $fname );
+                               } else {
+                                       $this->rollback( $fname, 
self::FLUSHING_INTERNAL );
+                               }
                        }
                        throw $e;
                }
                if ( $useTrx ) {
-                       $this->commit( $fname, self::FLUSHING_INTERNAL );
+                       if ( $this->getDB()->getType() == 'postgres' ) {
+                               $this->commit( $fname, 
self::TRANSACTION_INTERNAL );
+                       } else {
+                               $this->commit( $fname, self::FLUSHING_INTERNAL 
);
+                       }
                }
 
                return $ok;
@@ -2469,12 +2477,24 @@
                        $this->mTrxPreCommitCallbacks[] = [ $callback, $fname ];
                } else {
                        // If no transaction is active, then make one for this 
callback
-                       $this->startAtomic( __METHOD__ );
+                       if ( $this->getDB()->getType() == 'postgres' ) {
+                               $this->begin( __METHOD__, 
self::TRANSACTION_INTERNAL );
+                       } else {
+                               $this->startAtomic( __METHOD__ );
+                       }
                        try {
                                call_user_func( $callback );
-                               $this->endAtomic( __METHOD__ );
+                               if ( $this->getDB()->getType() == 'postgres' ) {
+                                       $this->commit( __METHOD__ );
+                               } else {
+                                       $this->endAtomic( __METHOD__ );
+                               }
                        } catch ( Exception $e ) {
-                               $this->rollback( __METHOD__, 
self::FLUSHING_INTERNAL );
+                               if ( $this->getDB()->getType() == 'postgres' ) {
+                                       $this->rollback( __METHOD__ );
+                               } else {
+                                       $this->rollback( __METHOD__, 
self::FLUSHING_INTERNAL );
+                               }
                                throw $e;
                        }
                }
@@ -2540,7 +2560,11 @@
                                        // Some callbacks may use 
startAtomic/endAtomic, so make sure
                                        // their transactions are ended so 
other callbacks don't fail
                                        if ( $this->trxLevel() ) {
-                                               $this->rollback( __METHOD__, 
self::FLUSHING_INTERNAL );
+                                               if ( $this->getDB()->getType() 
== 'postgres' ) {
+                                                       $this->rollback( 
__METHOD__ );
+                                               } else {
+                                                       $this->rollback( 
__METHOD__, self::FLUSHING_INTERNAL );
+                                               }
                                        }
                                }
                        }
@@ -2614,6 +2638,9 @@
        final public function startAtomic( $fname = __METHOD__ ) {
                if ( !$this->mTrxLevel ) {
                        $this->begin( $fname, self::TRANSACTION_INTERNAL );
+                       if ( $this->getDB()->getType() == 'postgres' ) {
+                               $this->mTrxAutomatic = true;
+                       }
                        // If DBO_TRX is set, a series of startAtomic/endAtomic 
pairs will result
                        // in all changes being in one transaction to keep 
requests transactional.
                        if ( !$this->getFlag( self::DBO_TRX ) ) {
@@ -2644,7 +2671,11 @@
                try {
                        $res = call_user_func_array( $callback, [ $this, $fname 
] );
                } catch ( Exception $e ) {
-                       $this->rollback( $fname, self::FLUSHING_INTERNAL );
+                       if ( $this->getDB()->getType() == 'postgres' ) {
+                               $this->rollback( $fname );
+                       } else {
+                               $this->rollback( $fname, 
self::FLUSHING_INTERNAL );
+                       }
                        throw $e;
                }
                $this->endAtomic( $fname );
@@ -2682,7 +2713,11 @@
                $this->mTrxTimestamp = microtime( true );
                $this->mTrxFname = $fname;
                $this->mTrxDoneWrites = false;
-               $this->mTrxAutomatic = ( $mode === self::TRANSACTION_INTERNAL );
+               if ( $this->getDB()->getType() == 'postgres' ) {
+                       $this->mTrxAutomatic = false;
+               } else {
+                       $this->mTrxAutomatic = ( $mode === 
self::TRANSACTION_INTERNAL );
+               }
                $this->mTrxAutomaticAtomic = false;
                $this->mTrxAtomicLevels = [];
                $this->mTrxShortId = sprintf( '%06x', mt_rand( 0, 0xffffff ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/314861
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If9b1a0586eed5248a96b2e19e08f542ca979c4cb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to