* This will work on any MediaWiki installation.
*/
class LCStoreDB implements LCStore {
- /** @var string */
- private $currentLang;
- /** @var bool */
- private $writesDone = false;
+ /** @var string Language code */
+ private $code;
+ /** @var array Server configuration map */
+ private $server;
+
+ /** @var array Rows buffered for insertion */
+ private $batch = [];
+
/** @var IDatabase|null */
private $dbw;
- /** @var array */
- private $batch = [];
- /** @var bool */
+ /** @var bool Whether a batch of writes were recently written */
+ private $writesDone = false;
+ /** @var bool Whether the DB is read-only or otherwise unavailable for writes */
private $readOnly = false;
- /** @var array Server configuration map */
- private $server;
public function __construct( $params ) {
$this->server = $params['server'] ?? [];
$dbw = $this->getWriteConnection();
$this->readOnly = $dbw->isReadOnly();
- $this->currentLang = $code;
+ $this->code = $code;
$this->batch = [];
}
public function finishWrite() {
if ( $this->readOnly ) {
return;
- } elseif ( is_null( $this->currentLang ) ) {
+ } elseif ( is_null( $this->code ) ) {
throw new MWException( __CLASS__ . ': must call startWrite() before finishWrite()' );
}
$dbw = $this->getWriteConnection();
$dbw->startAtomic( __METHOD__ );
try {
- $dbw->delete( 'l10n_cache', [ 'lc_lang' => $this->currentLang ], __METHOD__ );
+ $dbw->delete( 'l10n_cache', [ 'lc_lang' => $this->code ], __METHOD__ );
foreach ( array_chunk( $this->batch, 500 ) as $rows ) {
$dbw->insert( 'l10n_cache', $rows, __METHOD__ );
}
$trxProfiler->setSilenced( $oldSilenced );
}
- $this->currentLang = null;
+ $this->code = null;
$this->batch = [];
}
public function set( $key, $value ) {
if ( $this->readOnly ) {
return;
- } elseif ( is_null( $this->currentLang ) ) {
+ } elseif ( is_null( $this->code ) ) {
throw new MWException( __CLASS__ . ': must call startWrite() before set()' );
}
$dbw = $this->getWriteConnection();
$this->batch[] = [
- 'lc_lang' => $this->currentLang,
+ 'lc_lang' => $this->code,
'lc_key' => $key,
'lc_value' => $dbw->encodeBlob( serialize( $value ) )
];