From: Aaron Schulz Date: Tue, 14 Jul 2015 19:11:32 +0000 (-0700) Subject: Added DBAccessObjectUtils class to avoid duplication X-Git-Tag: 1.31.0-rc.0~10534^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=704583440ed27e1e0b7f463112233816cdade8a1;p=lhc%2Fweb%2Fwiklou.git Added DBAccessObjectUtils class to avoid duplication * WikiPage is the first caller to use this instead of DIY * This can be used elsewhere to keep callers uniform Change-Id: Ia6371eaa185d70d1431271b2c6c955523cd424e8 --- diff --git a/autoload.php b/autoload.php index 6444e3efa8..2a096f460b 100644 --- a/autoload.php +++ b/autoload.php @@ -279,6 +279,7 @@ $wgAutoloadLocalClasses = array( 'CurlHttpRequest' => __DIR__ . '/includes/HttpFunctions.php', 'DBAccessBase' => __DIR__ . '/includes/dao/DBAccessBase.php', 'DBAccessError' => __DIR__ . '/includes/db/LBFactory.php', + 'DBAccessObjectUtils' => __DIR__ . '/includes/dao/DBAccessObjectUtils.php', 'DBConnRef' => __DIR__ . '/includes/db/DBConnRef.php', 'DBConnectionError' => __DIR__ . '/includes/db/DatabaseError.php', 'DBError' => __DIR__ . '/includes/db/DatabaseError.php', diff --git a/includes/dao/DBAccessObjectUtils.php b/includes/dao/DBAccessObjectUtils.php new file mode 100644 index 0000000000..58f991fc10 --- /dev/null +++ b/includes/dao/DBAccessObjectUtils.php @@ -0,0 +1,59 @@ +pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle, array( 'FOR UPDATE' ) ); - } elseif ( $from === self::READ_LATEST ) { - $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); - } elseif ( $from === self::READ_NORMAL ) { - $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle ); + if ( is_int( $from ) ) { + list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from ); + $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts ); + if ( !$data + && $index == DB_SLAVE && wfGetLB()->getServerCount() > 1 && wfGetLB()->hasOrMadeRecentMasterChanges() ) { $from = self::READ_LATEST; - $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); + list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from ); + $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts ); } } else { // No idea from where the caller got this data, assume slave database.