"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/cache/localisation/LCStoreDB.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

LCStoreDB.php  (mediawiki-1.31.1):LCStoreDB.php  (mediawiki-1.32.0)
skipping to change at line 21 skipping to change at line 21
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html * http://www.gnu.org/copyleft/gpl.html
* *
* @file * @file
*/ */
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\DBQueryError; use Wikimedia\Rdbms\DBQueryError;
/** /**
* LCStore implementation which uses the standard DB functions to store data. * LCStore implementation which uses the standard DB functions to store data.
* This will work on any MediaWiki installation. * This will work on any MediaWiki installation.
*/ */
class LCStoreDB implements LCStore { class LCStoreDB implements LCStore {
/** @var string */ /** @var string */
private $currentLang; private $currentLang;
/** @var bool */ /** @var bool */
private $writesDone = false; private $writesDone = false;
/** @var IDatabase */ /** @var IDatabase|null */
private $dbw; private $dbw;
/** @var array */ /** @var array */
private $batch = []; private $batch = [];
/** @var bool */ /** @var bool */
private $readOnly = false; private $readOnly = false;
/** @var array Server configuration map */
private $server;
public function __construct( $params ) {
$this->server = $params['server'] ?? [];
}
public function get( $code, $key ) { public function get( $code, $key ) {
if ( $this->writesDone && $this->dbw ) { if ( $this->server || $this->writesDone ) {
$db = $this->dbw; // see the changes in finishWrite() // If a server configuration map is specified, always use
d that connection
// for reads and writes. Otherwise, if writes occurred in
finishWrite(), make
// sure those changes are always visible.
$db = $this->getWriteConnection();
} else { } else {
$db = wfGetDB( DB_REPLICA ); $db = wfGetDB( DB_REPLICA );
} }
$value = $db->selectField( $value = $db->selectField(
'l10n_cache', 'l10n_cache',
'lc_value', 'lc_value',
[ 'lc_lang' => $code, 'lc_key' => $key ], [ 'lc_lang' => $code, 'lc_key' => $key ],
__METHOD__ __METHOD__
); );
skipping to change at line 65 skipping to change at line 74
return ( $value !== false ) ? unserialize( $db->decodeBlob( $valu e ) ) : null; return ( $value !== false ) ? unserialize( $db->decodeBlob( $valu e ) ) : null;
} }
public function startWrite( $code ) { public function startWrite( $code ) {
if ( $this->readOnly ) { if ( $this->readOnly ) {
return; return;
} elseif ( !$code ) { } elseif ( !$code ) {
throw new MWException( __METHOD__ . ": Invalid language \ "$code\"" ); throw new MWException( __METHOD__ . ": Invalid language \ "$code\"" );
} }
$this->dbw = wfGetDB( DB_MASTER ); $dbw = $this->getWriteConnection();
$this->readOnly = $this->dbw->isReadOnly(); $this->readOnly = $dbw->isReadOnly();
$this->currentLang = $code; $this->currentLang = $code;
$this->batch = []; $this->batch = [];
} }
public function finishWrite() { public function finishWrite() {
if ( $this->readOnly ) { if ( $this->readOnly ) {
return; return;
} elseif ( is_null( $this->currentLang ) ) { } elseif ( is_null( $this->currentLang ) ) {
throw new MWException( __CLASS__ . ': must call startWrit e() before finishWrite()' ); throw new MWException( __CLASS__ . ': must call startWrit e() before finishWrite()' );
} }
$this->dbw->startAtomic( __METHOD__ ); $trxProfiler = Profiler::instance()->getTransactionProfiler();
$oldSilenced = $trxProfiler->setSilenced( true );
try { try {
$this->dbw->delete( $dbw = $this->getWriteConnection();
'l10n_cache', $dbw->startAtomic( __METHOD__ );
[ 'lc_lang' => $this->currentLang ], try {
__METHOD__ $dbw->delete( 'l10n_cache', [ 'lc_lang' => $this-
); >currentLang ], __METHOD__ );
foreach ( array_chunk( $this->batch, 500 ) as $rows ) { foreach ( array_chunk( $this->batch, 500 ) as $ro
$this->dbw->insert( 'l10n_cache', $rows, __METHOD ws ) {
__ ); $dbw->insert( 'l10n_cache', $rows, __METH
} OD__ );
$this->writesDone = true; }
} catch ( DBQueryError $e ) { $this->writesDone = true;
if ( $this->dbw->wasReadOnlyError() ) { } catch ( DBQueryError $e ) {
$this->readOnly = true; // just avoid site down t if ( $dbw->wasReadOnlyError() ) {
ime $this->readOnly = true; // just avoid sit
} else { e down time
throw $e; } else {
throw $e;
}
} }
$dbw->endAtomic( __METHOD__ );
} finally {
$trxProfiler->setSilenced( $oldSilenced );
} }
$this->dbw->endAtomic( __METHOD__ );
$this->currentLang = null; $this->currentLang = null;
$this->batch = []; $this->batch = [];
} }
public function set( $key, $value ) { public function set( $key, $value ) {
if ( $this->readOnly ) { if ( $this->readOnly ) {
return; return;
} elseif ( is_null( $this->currentLang ) ) { } elseif ( is_null( $this->currentLang ) ) {
throw new MWException( __CLASS__ . ': must call startWrit e() before set()' ); throw new MWException( __CLASS__ . ': must call startWrit e() before set()' );
} }
$dbw = $this->getWriteConnection();
$this->batch[] = [ $this->batch[] = [
'lc_lang' => $this->currentLang, 'lc_lang' => $this->currentLang,
'lc_key' => $key, 'lc_key' => $key,
'lc_value' => $this->dbw->encodeBlob( serialize( $value ) ) 'lc_value' => $dbw->encodeBlob( serialize( $value ) )
]; ];
} }
/**
* @return IDatabase
*/
private function getWriteConnection() {
if ( !$this->dbw ) {
if ( $this->server ) {
$this->dbw = Database::factory( $this->server['ty
pe'], $this->server );
if ( !$this->dbw ) {
throw new MWException( __CLASS__ . ': fai
led to obtain a DB connection' );
}
} else {
$this->dbw = wfGetDB( DB_MASTER );
}
}
return $this->dbw;
}
} }
 End of changes. 13 change blocks. 
25 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)