X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabase.php;h=2eb5c5483daec835e48adcc45288228d8f323adc;hb=bdf062a8e9f351d3b94f99f2cbe9f7176f0b8801;hp=7f0718c9526eb2bce15673e163d23a724acfa4dd;hpb=d84c3dde5af90c5c3497d18e427a5c2a38ac6ca8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 7f0718c952..2eb5c5483d 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -394,7 +394,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $p['variables'] = isset( $p['variables'] ) ? $p['variables'] : []; $p['tablePrefix'] = isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : ''; $p['schema'] = isset( $p['schema'] ) ? $p['schema'] : ''; - $p['cliMode'] = isset( $p['cliMode'] ) ? $p['cliMode'] : ( PHP_SAPI === 'cli' ); + $p['cliMode'] = isset( $p['cliMode'] ) + ? $p['cliMode'] + : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ); $p['agent'] = isset( $p['agent'] ) ? $p['agent'] : ''; if ( !isset( $p['connLogger'] ) ) { $p['connLogger'] = new \Psr\Log\NullLogger(); @@ -908,6 +910,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $isWrite ) { + if ( $this->getLBInfo( 'replica' ) === true ) { + throw new DBError( + $this, + 'Write operations are not allowed on replica database connections.' + ); + } # In theory, non-persistent writes are allowed in read-only mode, but due to things # like https://bugs.mysql.com/bug.php?id=33669 that might not work anyway... $reason = $this->getReadOnlyReason(); @@ -3384,6 +3392,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $fname = __METHOD__, callable $inputCallback = null ) { + $delimiterReset = new ScopedCallback( + function ( $delimiter ) { + $this->delimiter = $delimiter; + }, + [ $this->delimiter ] + ); $cmd = ''; while ( !feof( $fp ) ) { @@ -3412,7 +3426,15 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( $done || feof( $fp ) ) { $cmd = $this->replaceVars( $cmd ); - if ( !$inputCallback || call_user_func( $inputCallback, $cmd ) ) { + if ( $inputCallback ) { + $callbackResult = call_user_func( $inputCallback, $cmd ); + + if ( is_string( $callbackResult ) || !$callbackResult ) { + $cmd = $callbackResult; + } + } + + if ( $cmd ) { $res = $this->query( $cmd, $fname ); if ( $resultCallback ) { @@ -3429,6 +3451,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } } + ScopedCallback::consume( $delimiterReset ); return true; }