X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabasePostgres.php;h=5049f9b09f8fc7610c6b8456c8c20e8aa10f0a86;hb=a2f5d05ae842d26847d924ed5f57776108101363;hp=af9716d451731c776a6778b223785cc2343c8e9d;hpb=d657b1706621e2272ad40f4fe566854f82980c03;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index af9716d451..5049f9b09f 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -20,12 +20,14 @@ * @file * @ingroup Database */ +namespace Wikimedia\Rdbms; + use Wikimedia\Timestamp\ConvertibleTimestamp; use Wikimedia\WaitConditionLoop; -use Wikimedia\Rdbms\Blob; -use Wikimedia\Rdbms\PostgresBlob; -use Wikimedia\Rdbms\PostgresField; -use Wikimedia\Rdbms\ResultWrapper; +use MediaWiki; +use DBUnexpectedError; +use DBConnectionError; +use Exception; /** * @ingroup Database @@ -859,10 +861,10 @@ __INDEXATTR__; * * @since 1.19 * @param string $text Postgreql array returned in a text form like {a,b} - * @param string $output + * @param string[] $output * @param int|bool $limit * @param int $offset - * @return string + * @return string[] */ private function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) { if ( false === $limit ) { @@ -1305,6 +1307,33 @@ SQL; return parent::streamStatementEnd( $sql, $newLine ); } + public function doLockTables( array $read, array $write, $method ) { + $tablesWrite = []; + foreach ( $write as $table ) { + $tablesWrite[] = $this->tableName( $table ); + } + $tablesRead = []; + foreach ( $read as $table ) { + $tablesRead[] = $this->tableName( $table ); + } + + // Acquire locks for the duration of the current transaction... + if ( $tablesWrite ) { + $this->query( + 'LOCK TABLE ONLY ' . implode( ',', $tablesWrite ) . ' IN EXCLUSIVE MODE', + $method + ); + } + if ( $tablesRead ) { + $this->query( + 'LOCK TABLE ONLY ' . implode( ',', $tablesRead ) . ' IN SHARE MODE', + $method + ); + } + + return true; + } + public function lockIsFree( $lockName, $method ) { // http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS $key = $this->addQuotes( $this->bigintFromLockName( $lockName ) ); @@ -1356,6 +1385,8 @@ SQL; * @return string Integer */ private function bigintFromLockName( $lockName ) { - return Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 ); + return \Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 ); } } + +class_alias( DatabasePostgres::class, 'DatabasePostgres' );